$(document).ready(function() {
	
	// fancy box popup
	$(".fb").fancybox({
		'titleShow'     	: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'padding'			:	0
	});
	
	$(".fb_iframe_vendors").fancybox({
		'width'				: 490,
		'height'			: 360,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'titleShow'			: false,
		'padding'			:	0
	});
	
	$(".fb_iframe").fancybox({
		'width'				: 945,
		'height'			: 414,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'titleShow'			: false,
		'padding'			:	0
	});
	
	$(".fb_iframe_gallery").fancybox({
		'width'				: 754,
		'height'			: 567,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'titleShow'			: false,
		'padding'			:	0
	});

	$("#slider").easySlider({
		prevId:         'left_arrow',
		nextId:         'right_arrow',
		controlsShow:   true,
		controlsFade:   false,
		insertAfter:    true,
		auto:           true,
		pause:          9000,
		continuous:     true,
		hoverPause:		true,
		prevNext:       true,
		numeric:        true,
		numericId:      'controls'		
	});
	
	// Home page content slider
    $(function(){
		var sList = $("#home #slider ul#slide_deck li");
        $('#home #slider ul#slide_deck > li').css({'width':($(window).width())+'px'});
		$('#home #slider ul#slide_deck').css({'width':sList.length*($(window).width())+'px'});
		$("#home #slider #slide_deck li:first").css({ 'margin-left' : -($(window).width())+'px'});

        $(window).resize(function(){
        $('#home #slider ul#slide_deck > li').css({'width':($(window).width())+'px'});
		$('#home #slider ul#slide_deck').css({'width':sList.length*($(window).width())+'px'});
		$("#home #slider #slide_deck li:first").css({ 'margin-left' : -($(window).width())+'px'});
        });
    });
	

	// contact committees toggle
	// Ways you can help - sponsors hide (Collapse) the toggle containers on load
	$(".toggler ul").hide(); 
	// Switch the "Open" and "Close" state per click
	$(".toggler a").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});
	// Slide up and down on click
	$(".toggler a").click(function(){
		$(this).next("ul").slideToggle(600);
	});


	// Ways you can help - volunteers positions hide (Collapse) the toggle containers on load
	$(".volunteers_positions dd").hide(); 
	// Switch the "Open" and "Close" state per click
	$(".v_toggler a").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});
	// Slide up and down on click
	$(".v_toggler a").click(function(){
		$(this).parent().next("dd").slideToggle(600);
	});


	// Activities popup - vendors & performers directions toggle
	$(".toggle_content").hide();
	// Switch the "Open" and "Close" state per click
	$(".activities_toggler").toggle(function(){
		$(this).addClass("active");
		$(".activities").fadeOut(300);
		}, function () {
		$(this).removeClass("active");
		$(".activities").fadeIn(1300);
	});
	
	var $div = $(".toggle_content");
	var height = $div.height();
	$div.hide().css({ height : 0 });
	
	$(".activities_toggler").click(function () {
	  if ( $div.is(':visible') ) {
		$div.animate({ height: 0 }, { duration: 600, complete: function () {
			$div.hide();
		  } 
		});
	  } else {
		$div.show().animate({ height : height }, { duration: 600 });
	  }
		
	  return false;
	});
	
	// schedule table styling
	// $(".schedule_content tr:even").addClass("gray");
	$(".schedule_content tr td:last-child, .schedule_content tr th:last-child").css({border:"none"});
	// Schedule page call the tablesorter plugin
    $(".tablesorter").tablesorter({ 
    // sort on the 1st, 2nd, 3rd and 4th columns, order ascending
        sortList: [[0,0],[1,0],[2,0],[3,0]],
		widgets: ["zebra"]
    }); 
	
	// Schedule popup - resize images
	$('.flickr img').each(function() {
        var maxWidth = 620; // Max width for the image
        var maxHeight = 410;    // Max height for the image
        var ratio = 0;  // Used for aspect ratio
        var width = $(this).width();    // Current image width
        var height = $(this).height();  // Current image height
 
        // Check if the current width is larger than the max
        if(width > maxWidth){
            ratio = maxWidth / width;   // get ratio for scaling image
            $(this).css("width", maxWidth); // Set new width
            $(this).css("height", height * ratio);  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        }
 
        // Check if current height is larger than max
        if(height > maxHeight){
            ratio = maxHeight / height; // get ratio for scaling image
            $(this).css("height", maxHeight);   // Set new height
            $(this).css("width", width * ratio);    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image
        }
    });
	
});


