$(document).ready(function() {

	//banner animate
	var timer = setInterval( next_bkg, 6000);
	var current_banner=1;
	var next_banner=2;
	function next_bkg(){
		$('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);
	}); 

	//for inputs with a default value
	$('.input_with_default').focus(function(){							  
		$(this).addClass('has_focus');
		if ($(this).val()==$('#default_'+$(this).attr('name')).html()){
			$(this).val('');
		}
	});
	$('.input_with_default').focusout(function(){
		$(this).removeClass('has_focus');
		if ($(this).val().length<1){
			$(this).val($('#default_'+$(this).attr('name')).html());
		}
	});
	
	//if we have home slides
	if ($('div#home_slides').length>0){
		var timer2 = setInterval( next_slide, 7000);
		var current_slide=1;
		var next_slide=2;
		function next_slide(){
			$('div#home_slides div#slide_'+current_slide).fadeOut(1000);
			$('div#home_slides div#slide_'+next_slide).fadeIn(1000);
			current_slide=next_slide;
			next_slide++;
			if (next_slide>parseInt($('#num_slides').text())){
				next_slide=1;
			}
			
		}
	}
	
});



/*-------------------------------------------------------------------- 
 * 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'); });
		}
	});
};
