$(document).ready(function() {

	//banner animate
	var timer = setInterval( next_bkg, 6000);
	var current_banner=1;
	var next_banner=2;
	function next_bkg(){
		$('.temp').html('next: '+next_banner+' and c:'+current_banner);
		$('div#these_banners div#banner_'+current_banner).fadeOut(3000);
		$('div#these_banners div#banner_'+next_banner).fadeIn(3000);
		current_banner=next_banner;
		next_banner++;
		if (next_banner>parseInt($('#num_banners').text())){
			next_banner=1;
		}
		
	}
	
	//activate checkbox
	$('input').customInput();
	
	//social icons animate
	$('div.social_media a').hover(function(){
		$(this).animate({ 'margin-top': "-=2"},100);
	}, function(){
		$(this).animate({ 'margin-top': "+=2"},100);
	}); 
	
	//menu dropdowns
	//if we have hover
	function open_sub(){
		
		//find if a sub menu
		if ($(this).find('span.sub_menu').length>0){
			$(this).find('span.sub_menu').slideDown('fast');
		}
			
	}
	function close_sub(){

		//find if a sub menu
		if ($(this).find('span.sub_menu').length>0){
			$(this).find('span.sub_menu').stop(true, true).slideUp('fast');
		}
			
	}
	var config = {    
		 over: open_sub, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: close_sub // function = onMouseOut callback (REQUIRED)    
	};
	$('#menu li').hoverIntent(config);
	
	
	//if we have a photo gallery
	if ($('div#gallery img').length>0){
		
		//show first
		$('div#gallery img.'+$('div#thumbs img:first').attr('alt')).fadeIn('fast').addClass('current_album_image');
		$('div#gallery div#gallery_image_desc').text($('div#thumbs img:first').attr('title')).fadeIn('fast');
		
		//and when visitor clicks
		$('div#thumbs img').click(function(){
			
			//show clicked
			$('div#gallery img.current_album_image').hide().removeClass('current_album_image');
			$('div#gallery img.'+$(this).attr('alt')).fadeIn('fast').addClass('current_album_image');
			$('div#gallery div#gallery_image_desc').text($(this).attr('title')).fadeIn('fast');
			
		});
		
	}
	
	//if we have a photo gallery
	if ($('div#banana_cards img').length>0){
		
		//and when visitor clicks
		$('div#banana_cards img').click(function(){
												 
			//show clicked
			$('div#card_holder div.current_card').fadeOut('fast').removeClass('current_card');
			$('div#card_holder img.big_'+$(this).attr('class')).parent().fadeIn('fast').addClass('current_card');
			
		});
		
	}
	
});



/*-------------------------------------------------------------------- 
 * jQuery plugin: customInput()
 * by Maggie Wachs and Scott Jehl, http://www.filamentgroup.com
 * Copyright (c) 2009 Filament Group
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 * Article: http://www.filamentgroup.com/lab/accessible_custom_designed_checkbox_radio_button_inputs_styled_css_jquery/  
 * Usage example below (see comment "Run the script...").
--------------------------------------------------------------------*/

jQuery.fn.customInput = function(){
	$(this).each(function(i){	
		if($(this).is('[type=checkbox]')){
			var input = $(this);
			
			// get the associated label using the input's id
			var label = $('label[for='+input.attr('id')+']');
			
			//get type, for classname suffix 
			var inputType = (input.is('[type=checkbox]')) ? 'checkbox' : 'radio';
			
			// wrap the input + label in a div 
			$('<div class="custom-'+ inputType +'"></div>').insertBefore(input).append(input, label);
			
			// find all inputs in this set using the shared name attribute
			var allInputs = $('input[name='+input.attr('name')+']');
			
			// necessary for browsers that don't support the :hover pseudo class on labels
			label.hover(
				function(){ 
					$(this).addClass('hover'); 
					if(inputType == 'checkbox' && input.is(':checked')){ 
						$(this).addClass('checkedHover'); 
					} 
				},
				function(){ $(this).removeClass('hover checkedHover'); }
			);
			
			//bind custom event, trigger it, bind click,focus,blur events					
			input.bind('updateState', function(){	
				if (input.is(':checked')) {
					if (input.is(':radio')) {				
						allInputs.each(function(){
							$('label[for='+$(this).attr('id')+']').removeClass('checked');
						});		
					};
					label.addClass('checked');
				}
				else { label.removeClass('checked checkedHover checkedFocus'); }
										
			})
			.trigger('updateState')
			.click(function(){ 
				$(this).trigger('updateState'); 
			})
			.focus(function(){ 
				label.addClass('focus'); 
				if(inputType == 'checkbox' && input.is(':checked')){ 
					$(this).addClass('checkedFocus'); 
				} 
			})
			.blur(function(){ label.removeClass('focus checkedFocus'); });
		}
	});
};
