Shadowbox.init({
   players: ["iframe", "html"]
});


//*Home page overlay for 2010 Information *
function display2010Notice() {

	setTimeout(function(){
		$.get('/wp-content/themes/celebrationoflight/2010Notice.inc',function(data){
			Shadowbox.open({
				content:data,
				player:'html',
				height:500,
				width:600,
				options:{
					overlayOpacity:0.3
				}
			});	
		});
	}, 1500);


}

var events = [
	{ title: "USA PERFORMING IN", date: new Date(2010, 6, 21, 22) },
	{ title: "SPAIN PERFORMING IN", date: new Date(2010, 6, 24, 22) },
	{ title: "MEXICO PERFORMING IN", date: new Date(2010, 6, 28, 22) },
	{ title: "CHINA PERFORMING IN", date: new Date(2010, 6, 31, 22) }
];

function nextEvent() {
	var now = new Date();
	for (i = 0; i < events.length; i++) {
		if (events[i].date > now) {
			return events[i];
		}
	}
	return { title: "NEXT PERFORMANCE", date: new Date(now.getFullYear()+1, 6, 21, 22) };
}

$(document).ready(function(){

//Page reload for competition pages




	
	$(".countryContainer").easySlider({
		auto: true,
		speed: 500,
		pause: 5000,
		continuous: true,
		numeric: true
	});

	$(".flickrGallery").easySlider({
		controlsShow:true,						   
		auto: true,
		speed: 500,
		pause: 6000,
		continuous: true
	});

	var initEvent = nextEvent();
	$(".countHeader").html(initEvent.title);
	$(".counterDownTimer").countdown({
		until: initEvent.date, 
		format: 'DHMS',
		onExpiry: function() { 
			var event = nextEvent();
			$(".countHeader").html(event.title);
			$(this).countdown("change", { until: event.date }); 
		}, 
		layout: 
		'<div class="days"><span class="countLabel">DAYS</span><div class="image{d10}"></div><div class="image{d1}"></div></div><div class="imageSep"></div><div class="hours"><span class="countLabel">HOURS</span><div class="image{h10}"></div><div class="image{h1}"></div></div><div class="imageSep"></div><div class="minutes"><span class="countLabel">MINUTES</span><div class="image{m10}"></div><div class="image{m1}"></div></div><div class="imageSep"></div><div class="seconds"><span class="countLabel">SECONDS</span><div class="image{s10}"></div><div class="image{s1}"></div></div>'
	});

 //SETTING HEIGHT FOR COLUMNS
    function equalHeight(group) {
        var tallest = 0;
        group.each(function() {
            var thisHeight = $(this).height();
            if (thisHeight > tallest) {
                tallest = thisHeight + 25;
            }
        });
        group.height(tallest);
    }

    equalHeight($("#left-container, #latest_news"));
	




//country window pop up
	$('.close_box').click(function(){
		$('.country_overlay').fadeOut('fast');
	});
	
	$('#left-container a.country_popup').click(
		function(){
			$(this).parent().find('.country_overlay').fadeIn('medium');		
	})
	
	
//PNG FIX
//$("#global_video, ul#main-nav").pngfix();

	

//scrollpane function
// :not(#competition #info_box, #left-container .entry .scroll_container) prevents scrollbar on the competition page due to issues with sIFR. may be fixed later
	//	$('#info_box, #left-container .entry .scroll_container:not(#competition #left-container .entry .scroll_container)').jScrollPane({
//			showArrows:true, 
//			scrollbarWidth: 10,
//			wheelSpeed: 12,
//			maintainPosition: false
//		});
	
	$(".scroll_container, #info_box").jScrollPane({
		
		showArrows: true,
		scrollbarWidth: 10,
		wheelSpeed: 12,
		maintainPosition: false
	
	});
									   
	
	
	$('#st_menu ul li a').bind("click",function() {
		$('#st_menu ul li').removeClass('active');
		$(this).parent().addClass('active');
	});	
	
	//show and hide content for submenu content	
	$('#tools-of-the-trade, #event-information #foot-tools-of-the-trade').bind("click",function() {
		$('#st_menu ul li').removeClass('active');																						
		$('#st_menu .submenu01').parent().addClass('active');																						
		$('#info_box').children().hide();
		$('.tools-of-the-trade').fadeIn('fast');
		$('#info_box')[0].scrollTo(0);
		return false;			
	});
	
	$('#designing-the-show, #event-information #foot-designing-the-show').bind("click",function() {
		$('#info_box').children().hide();
		$('.designing-the-show').fadeIn('fast');	
		$('#info_box')[0].scrollTo(0);
		return false;														 
	});
	
	$('#barge-facts, #event-information #foot-barge-facts').bind("click",function() {
		$('#st_menu ul li').removeClass('active');
		$('#st_menu .submenu03').parent().addClass('active');
		$('#info_box').children().hide();
		$('.barge-facts').fadeIn('fast');
		$('#info_box')[0].scrollTo(0);
		return false;
	});
	
	$('#history-of-the-fireworks, #event-information #foot-history-of-the-fireworks').bind("click",function() {
		$('#st_menu ul li').removeClass('active');																									
		$('#st_menu .submenu04').parent().addClass('active');
		$('#info_box').children().hide();
		$('.history-of-the-fireworks').fadeIn('fast');
		$('#info_box')[0].scrollTo(0);
		return false;
	});
	
	$('#safety-tips, #event-information #foot-safety-tips').bind("click",function() {
		$('#info_box').children().hide();
		$('.safety-tips').fadeIn('fast');
		$('#info_box')[0].scrollTo(0);
		return false;
	});


	var myFile = document.location.toString();
	if (myFile.match('#')) { // the URL contains an anchor
		// click the navigation item corresponding to the anchor
		var myAnchor = '#' + myFile.split('#')[1];
		$('#st_menu a[href="' + myAnchor + '"]').click();
	}

	
//animate the voting content on homepage
	var fadeDuration = 500;
	$('.vote-tab').toggle(
		function(){
			$(this).parent().animate({ top: 50}, fadeDuration);
			$('.text-vote .close').css('display','block');
	},
		function(){
			$(this).parent().animate({top: 341}, fadeDuration);
			$('.text-vote .close').css('display','none');			
	})

	
//fade in the navigation button with animated fadein
	$(function(){
		$('#main-nav li')
		.removeClass('highlight')
		.find('a')
		.append('<span class="hover" />').each(function(){
				var $span = $('> span.hover' , this).css('opacity' , 0);
				$(this).hover(function(){
					//on hover
					$span.stop().fadeTo(500,1);
				}, function() {
					//off hover
					$span.stop().fadeTo(500, 0);
				})
		});
	});			

	$('#sponsors_block ul li img').hover(
		function() {
			$(this).css({marginTop:"0px"});
	},
		function() {
			$(this).css({marginTop:"-36px"});
	})
	
	$('#sponsors_block').cycle({ 
		fx:     'fade', 
		speed:   300, 
		timeout: 3000, 
		next:   '#s3', 
		pause:   2 
	});																									 

	if ($.browser.msie && $.browser.version <= 6.0) { // if ie 6
		$('img#footer-fcvlogo').attr('src','/wp-content/themes/celebrationoflight/images/fcv-ie.gif'); // replace with a gif image
	}

});

$(window).bind('load', function() { // this needs to load after the window has loaded.
//resize the homepage main background image
  resizeBackground();
  $(window).resize(resizeBackground);
  
    function resizeBackground() {
    img_w = $("img#background").width();
    img_h = $("img#background").height();
   
    window_w = $(window).width();
    window_h = $(window).height();
   
    $("img#background").css({ width: "auto", height: "auto"});
   
    var new_img_w = $(window).width();
    var new_img_h =  (new_img_w / img_w) * img_h;
    $("img#background").css({ width: new_img_w, height: new_img_h});
   
    if (new_img_h < window_h) {
      var new_img_h = window_h;
      var new_img_w =  (new_img_h / img_h) * img_w;
      $("img#background").css({ width: new_img_w, height: new_img_h});
    }
    
    }
});