/* Script - collected.js
 *
 * The Chicago Ballet jQuery scripts collected
 *
 */
 
/***************************************************************************************************
		HOMEPAGE CALENDAR FUNCTIONALITY
***************************************************************************************************/
$(function() { 		 
	var offsetX = 5; // These variables offset the tooltip from pointer while hovering
	var offsetY = -10;
	
	var da = new Date();	// Create a Date Object set to the last modifed date
	var dy = da.getFullYear();	// Get full year (as opposed to last two digits only)
	var dm = da.getMonth() + 1;	// Get month and correct it (getMonth() returns 0 to 11)
	var dd = da.getDate();	// Get date within month
	if ( dy < 1970 ) // We still have to fix the millennium bug
		dy = dy + 100;	
	var ys = new String(dy)	// Convert year, month and date to strings
	var ms = new String(dm); 
	var ds = new String(dd); 
	if ( ms.length == 1 ) // Add leading zeros to month and date if required 
		ms = "0" + ms; 
	if ( ds.length == 1 )
		ds = "0" + ds;
	var ys = ys + "-" + ms + "-" + ds;	// Combine year, month and date in ISO format

// FIND AND STYLE CURRENT CALENDAR DAY
	
	$('td#' + ys).addClass('today');
	$('td#' + ys + '>a').css({'color': '#FFFFFF'});
	$('td#' + ys + '>span').css({'color': '#FFFFFF'});	

		$('td.event').hover(function(e) { 
		
    	$(this).children('div#tooltip').stop(true,true).show();		// mouse on
    	
    	var hover_date = $(this).attr("id"); 
    	
    	$('div#list_target').append('<img src="http://chicagoballetcenter.org/images/ajax-loader.gif" alt="Currently Loading" id="loading" />');
		
		$.post(
		"http://chicagoballetcenter.org/events/event_search.php?_=" + Math.random(), 
		{search_date: hover_date},
		function(data) {
			$('#loading').remove();	
			$('div#list_target').stop(true,true).fadeIn(100).html(data);
		}
		
		)
		
	}, function() {
	
	$('div#tooltip').stop(true,true).delay(150).hide(); // mouse off
    $('div#tooltip div#list_target').stop(true,true).delay(200).hide();
    $('div#tooltip div#list_target ul li').stop(true,true).delay(200).remove();
	
	}); // END HOVER STATE
	
	/* Character counting styling on Admin pages */
	$('#hl_message').NobleCount('#count',{
		on_negative: 'go_red',
		on_positive: 'go_green',
		max_chars: 710
	});
});	

/***************************************************************************************************
		HOMEPAGE NEWSFLASH FUNCTIONALITY (bxCarousel)
***************************************************************************************************/
$(function() {
	var n = $('ul#newsflash li').size();			
	if (n > 1) {
		$('ul#newsflash').bxCarousel({
			display_num: 1,       // number of elements to be visible
			move: 1,              // number of elements to the shift the slides
			speed: 300,           // number in milliseconds it takes to finish slide animation
			margin:10,             // right margin to be applied to each <li> element (in pixels, although do not include "px")
			auto: true,          // automatically play slides without a user click
			auto_interval: 7000,  // the amount of time in milliseconds between each auto animation
			auto_dir: 'next',     // direction of auto slideshow (options: 'next', 'prev')
			auto_hover: true,    // determines if the slideshow will stop when user hovers over slideshow
			next_text: 'next',    // text to be used for the 'next' control
			next_image: '',       // image to be used for the 'next' control
			prev_text: 'prev',    // text to be used for the 'prev' control
			prev_image: '',       // image to be used for the 'prev' control
			controls: false        // determines if controls will be displayed
		});

	} else {
		return false;
	}	
	
});

/***************************************************************************************************
		ADMIN EVENT FORM FUNCTIONALITY
***************************************************************************************************/
$(function() {
	$("#locale input[name='find_location']").ready(function() {
		if($("#locale input[name='find_location']:checked").val() == 'other') {
			$("span#alt_location").fadeIn('slow');
		} else {
			$("span#alt_location").fadeOut('fast');
		}
	});
	
	$("#locale input[name='find_location']").click(function() {
		if($("#locale input[name='find_location']:checked").val() == 'other') {
			$("span#alt_location").fadeIn('slow');
		} else {
			$("span#alt_location").fadeOut('fast');
		}
	});
	
	$("#cost_field input[name='cost']").ready(function() {
		if($("#cost_field input[name='cost']:checked").val() == 'other') {
			$("span#alt_cost").fadeIn('slow');
		} else {
			$("span#alt_cost").fadeOut('fast');
		}
	});

	$("#cost_field input[name='cost']").click(function() {
		if($("#cost_field input[name='cost']:checked").val() == 'other') {
			$("span#alt_cost").fadeIn('slow');
		} else {
			$("span#alt_cost").fadeOut('fast');
		}
	});
});	
	
/***************************************************************************************************
		AUTOFOCUS ON FORM INPUT FIELD
***************************************************************************************************/
$(function() {	
	$('input.first_focus').focus();
	
	// $.scrollTo('a#anchor_link');
	
});	

/***************************************************************************************************
		DONATE BUTTON FUNCTIONALITY
***************************************************************************************************/		
$(function() {	
	$('#donate_button_wrap a img#donate_button').hover(
		function() { // Change the input image's source when we "roll on"
			$(this).attr({ src : 'http://chicagoballetcenter.org/images/P_donate_button_down.png'});
		},
		function() { // Change the input image's source back to the default on "roll off"
			$(this).attr({ src : 'http://chicagoballetcenter.org/images/P_donate_button_up.png'});             
		}
	);	
});

/***************************************************************************************************
		ACCORDION FUNCTIONALITY
***************************************************************************************************/
$(function() {
	// Accordion 1
	$("#accordion1").accordion({ header: "h3" });
	
	// hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);
	
	// Accordion 2
	$("#accordion2").accordion({ header: "h3" });
	
	// hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);
});	

/***************************************************************************************************
		CHARACTER COUNT STYLE ON ADMIN PAGES
***************************************************************************************************/		
$(function() {	
	$('#hl_message').NobleCount('#count',{
		on_negative: 'go_red',
		on_positive: 'go_green',
		max_chars: 710
	});
	
	$('#newsflash').NobleCount('#count',{
		on_negative: 'go_red',
		on_positive: 'go_green',
		max_chars: 400
	});
	
});	

/***************************************************************************************************
		VISIBILITY CONTROLS FOR FORM REGISTRATION
***************************************************************************************************/		
$(function() {	
	$('#class_choice').ready(function() {
		if($("select[name='class_choice'] option:selected").val() == 'pb1') {
			$("span#dayofchoice").fadeIn("slow");
		} else if($("select[name='class_choice'] option:selected").val() == 'pb2') {
			$("span#dayofchoice").fadeIn("slow");
		} else if($("select[name='class_choice'] option:selected").val() == 'b1') {
			$("span#dayofchoice").fadeIn("slow");
		} else if($("select[name='class_choice'] option:selected").val() == 'b2') {
			$("span#dayofchoice").fadeIn("slow");			
		} else if($("select[name='class_choice'] option:selected").val() == 'tt') {
			$("span#dayofchoice").fadeIn("slow");			
		} else if($("select[name='class_choice'] option:selected").val() == 'basic_y') {
			$("span#dayofchoice").fadeIn("slow");			
		} else if($("select[name='class_choice'] option:selected").val() == 'bt') {
			$("span#dayofchoice").fadeIn("slow");			
		} else {
			$("span#dayofchoice").fadeOut("fast");
		}
	});
	
	$('#class_choice').change(function() {

		var class_choice = $("select[name='class_choice'] option:selected").val();

		if($("select[name='class_choice'] option:selected").val() == 'pb1') {
		
			$("span#dayofchoice").show();		
		
			$.post(
			"http://chicagoballetcenter.org/school/childrens/reg_class_meet.php", 
			{choice: class_choice},
			function(data) {
				$("select#dayofchoice").html(data);
			}
			)
			
		} else if($("select[name='class_choice'] option:selected").val() == 'pb2') {
			$("span#dayofchoice").show();
			$.post(
			"http://chicagoballetcenter.org/school/childrens/reg_class_meet.php", 
			{choice: class_choice},
			function(data) {
				$("select#dayofchoice").html(data);
			}
			)			
		} else if($("select[name='class_choice'] option:selected").val() == 'b1') {
			$("span#dayofchoice").show();
			$.post(
			"http://chicagoballetcenter.org/school/childrens/reg_class_meet.php", 
			{choice: class_choice},
			function(data) {
				$("select#dayofchoice").html(data);
			}
			)			
		} else if($("select[name='class_choice'] option:selected").val() == 'b2') {
			$("span#dayofchoice").show();			
			$.post(
			"http://chicagoballetcenter.org/school/childrens/reg_class_meet.php", 
			{choice: class_choice},
			function(data) {
				$("select#dayofchoice").html(data);
			}
			)			
		} else if($("select[name='class_choice'] option:selected").val() == 'tt') {
			$("span#dayofchoice").show();			
			$.post(
			"http://chicagoballetcenter.org/school/childrens/reg_class_meet.php", 
			{choice: class_choice},
			function(data) {
				$("select#dayofchoice").html(data);
			}
			)			
		} else if($("select[name='class_choice'] option:selected").val() == 'basic_y') {
			$("span#dayofchoice").show();			
			$.post(
			"http://chicagoballetcenter.org/school/childrens/reg_class_meet.php", 
			{choice: class_choice},
			function(data) {
				$("select#dayofchoice").html(data);
			}
			)			
		} else if($("select[name='class_choice'] option:selected").val() == 'bt') {
			$("span#dayofchoice").show();			
			$.post(
			"http://chicagoballetcenter.org/school/childrens/reg_class_meet.php", 
			{choice: class_choice},
			function(data) {
				$("select#dayofchoice").html(data);
			}
			)			
		} else {
			$("span#dayofchoice").hide();
		}
	});
	
});


/***************************************************************************************************
		ADMIN PAGE CONTROLS
***************************************************************************************************/		


$(function() {
	$("#all_day").change(function() {
		if ($("#all_day").is(":checked")) {
			$("#timebox").hide();
			$("#datepicker2").show();
			$("#dp_to").show();
		} else {
			$("#timebox").show();
			$("#datepicker2").hide();
			$("#dp_to").hide();
		}
	});
	
	$("#all_day").ready(function() {
		if ($("#all_day").is(":checked")) {
			$("#timebox").hide();
			$("#datepicker2").show();
			$("#dp_to").show();
		} else {
			$("#timebox").show();
			$("#datepicker2").hide();
			$("#dp_to").hide();
		}
	});
});


$(function() {
	$("#datepicker1").datepicker();
	$("#datepicker2").datepicker();
});





// Select all inputs and textareas that have a "placeholder" attribute.
$(function() {
	$( 'input[placeholder], textarea[placeholder]' ).placeHoldize();
});


$(function() {
	$('tr:odd').addClass('row1');
	$('td.sub_head').addClass('sub_head');

	$("select#action").change(function() {				/* Syncronize select options */
		$("select#action").val($(this).val());
	});
	
	$("select#filter1").change(function() {
		$("select#filter1").val($(this).val());
	});
	
	$("select#filter2").change(function() {
		$("select#filter2").val($(this).val());
	});	
	
	$("select#filter3").change(function() {
		$("select#filter3").val($(this).val());
	});		
	
	$("input#master_delete1").click(function() { 		/* Check/Uncheck all */
		var checked_status = this.checked;

		$("input:checkbox").each(function() {
			this.checked = checked_status;
		});
	
	});	
	
	$("input#master_delete2").click(function() { 
		var checked_status = this.checked;

		$("input:checkbox").each(function() {
			this.checked = checked_status;
		});
	
	});
	
	/* TRUE value added to hidden field and submitted if select#action has been choosen */
	$('input#apply').click(function() {					
		var action = $('select#action').val();
		if (action == 'add' || action == 'delete') {
			$('input#submitaction').attr({value: 'TRUE'});
			$(this).submit();
		}
	});

});



$(function() {	
	var slider = $('#slider1').bxSlider({
		auto: true,
		infiniteLoop: true,
		autoStart: true,
		autoHover: true,
		pause: 7000,
		controls: false
	});
		
	$('#go_back').click(function() {
		slider.goToPreviousSlide();
		slider.startShow();
		return false;
	});
	
	$('#go_next').click(function() {
		slider.goToNextSlide();
		slider.startShow();		
		return false;
	});             
});


//$(function() {		
//	$.scrollTo('a#anchor_link');
//});	


