//	
// Surrey 2010 Celebration v1.0.0 
// Site by Sofresh [info@sofresh.ca]
// 

$(document).ready(function(){
	$.preloadCssImages();
	
	/*if ($('.slideBanner').html() != null){ slideBanner(); }*/
						   
	if ($('.lineup_ct_overal').html() != null){
		
		// onload from submenu
		var readUrl = location.href;
		var selectedDate = readUrl.substring(Number(readUrl.length)-2, readUrl.length);
		if (readUrl.match("#feb") == null){
			//$("#lineup_ct_overal").html('<p class="loading_page"></p>').load("feb12.html");
		}
		else{
			$('.current').removeClass('current');
			$('.e_days_lavaLamp a').each(function (i) {
				var selectedDay = $(this).html();
				selectedDay = selectedDay.substring(selectedDay.length-2,selectedDay.length);
				if (selectedDay==selectedDate) $(this).parent().addClass('current');
			});
			
			$('#lineup_ct_overal').html('<p class="loading_page"></p>').load("feb"+selectedDate+".html");
		}		
		
		
		// init slidermenu
		$(function() {
			$(".e_days_lavaLamp").lavaLamp({
				fx: "easeOutQuint", 
				speed: 500,
				click: function(event, menuItem) {
					$('.current').removeClass('current');
					$('.e_days_active').removeClass('e_days_active');
					$(this).addClass('e_days_active');
					 return true;
				}
			});
		});
			
		
		// oncolick from submenu
		$('.lineup_submenu a').click(function(){			
			var selectedDay_sub = $(this).html();
				selectedDay_sub = selectedDay_sub.substring(selectedDay_sub.length-2,selectedDay_sub.length);
			$("#lineup_ct_overal").html('<p class="loading_page"></p>').load("feb"+selectedDay_sub+".html");
			
			
			$('.e_days').html('<ul class="e_days_lavaLamp">'
					+'<li class="12"><a href="#feb12"><strong>FRI</strong> 12</a></li> '
					+'<li class="13"><a href="#feb13"><strong>SAT</strong> 13</a></li> '
					+'<li class="14"><a href="#feb14"><strong>SUN</strong> 14</a></li> '
					+'<li><span><strong>MON</strong> 15</span></li> '
					+'<li><span><strong>TUE</strong> 16</span></li> '
					+'<li class="17"><a href="#feb17"><strong>WED</strong> 17</a></li> '
					+'<li class="18"><a href="#feb18"><strong>THU</strong> 18</a></li> '
					+'<li class="19"><a href="#feb19"><strong>FRI</strong> 19</a></li> '
					+'<li class="20"><a href="#feb20"><strong>SAT</strong> 20</a></li> '
					+'<li class="21"><a href="#feb21"><strong>SUN</strong> 21</a></li> '
					+'<li><span><strong>MON</strong> 22</span></li> '
					+'<li><span><strong>TUE</strong> 23</span></li> '
					+'<li class="24"><a href="#feb24"><strong>WED</strong> 24</a></li> '
					+'<li class="25"><a href="#feb25"><strong>THU</strong> 25</a></li> '
					+'<li class="26"><a href="#feb26"><strong>FRI</strong> 26</a></li> '
					+'<li class="27"><a href="#feb27"><strong>SAT</strong> 27</a></li> '
					+'<li class="28"><a href="#feb28"><strong>SUN</strong> 28</a></li>'
				+'</ul>');
			
			
			$('.current').removeClass('current');
			$('.e_days_lavaLamp a').each(function (i) {
				var selectedDay = $(this).html();
				selectedDay = selectedDay.substring(selectedDay.length-2,selectedDay.length);
				if (selectedDay==selectedDay_sub) $(this).parent().addClass('current');				
			});			
			
			$('.back').remove();
			$(function() {
				$(".e_days_lavaLamp").lavaLamp({
					fx: "easeOutQuint", 
					speed: 500,
					click: function(event, menuItem) {
						$('.current').removeClass('current');
						$('.e_days_active').removeClass('e_days_active');
						$(this).addClass('e_days_active');
						 return true;
					}
				});
			});
			//window.location.reload();
			
			$('.e_days_lavaLamp a').click(function(){
				/*$('.lineup_ct').hide();
				$('#lineup_'+selectedDay).fadeIn();	*/
				
				var selectedDay = $(this).html();
					selectedDay = selectedDay.substring(selectedDay.length-2,selectedDay.length);
				$("#lineup_ct_overal").html('<p class="loading_page"></p>').load("feb"+selectedDay+".html");
			});
			
		});
		
		
		// onclick from slidemenu
		$('.e_days_lavaLamp a').click(function(){
			/*$('.lineup_ct').hide();
			$('#lineup_'+selectedDay).fadeIn();	*/
			
			var selectedDay = $(this).html();
				selectedDay = selectedDay.substring(selectedDay.length-2,selectedDay.length);
			$("#lineup_ct_overal").html('<p class="loading_page"></p>').load("feb"+selectedDay+".html");
		});
	}
});



var speedScroll=800;
var numImagesLoad=1;
var numPageIndex=1;
var numItems;
var numImgBlockWidth=988;
var numImgBlockHeight=265;
var setAutoSlideBanner;
function slideBanner(){
	$('.loading').remove();
	$('.roundcorner').show();
	/*$('.slideBanner').css({ backgroundColor:"#000"});*/
	
	if (($.browser.msie) && ($.browser.version=="6.0")) $('.desBg').show();
	else $('.desBg').fadeIn(speedScroll);
	
	numItems=$('.slidePhoto').length;
	
	
	for (var i=0; i<numItems; i++)	$('.slidePhoto:eq('+i+')').css("left",(i*numImgBlockWidth));
	$('.slidePhotos').width(numImagesLoad * numImgBlockWidth);
	$('.slidePhotos').height(numImgBlockHeight);	
	$('.slidePhoto').css({ 'visibility':'visible'});	
	$('.slideDes div:first').fadeIn(speedScroll);
	
	setAutoSlideBanner = setTimeout("doSlideBanner()",5000);

}

function doSlideBanner(){
	clearTimeout(setAutoSlideBanner);
	if(numPageIndex < numItems){
		//$(".slidePhoto").animate({left:'-='+numImgBlockWidth+'px'}, speedScroll);
		$(".slidePhoto").animate({left:'-='+numImgBlockWidth+'px'}, { duration: speedScroll, /*easing: 'easeOutQuint',*/ complete: function(){}});
		numPageIndex++;		
	}
	else{
		var gotoFirst = numItems-1;
		$(".slidePhoto").animate({left:'+='+numImgBlockWidth*gotoFirst+'px'}, { duration: speedScroll, /*easing: 'easeOutQuint',*/ complete: function(){}});
		numPageIndex=1;
	}
	
	var preNumPageIndex = numPageIndex-1;
	$('.slideDes div').hide();
	$('.slideDes div:eq('+preNumPageIndex+')').fadeIn(speedScroll);	
	
	
	var autoSlideBanner = setTimeout("doSlideBanner()",5000);
}


/* Sub menu */
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#jsddm > li').bind('mouseover', jsddm_open)
   $('#jsddm > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;