/* 
	Created By: Notion Age 	
	Version : 0.3
*/
$(document).ready(function(){
	var mydate= new Date();
	var rootPath = "http://www.7-eleven.com.sg/";
	var curhr=mydate.getHours();
	if($.cookie("css")) { //check if the css set by cookies..
		$("#mainstyle").attr("href", $.cookie("css"));
		if($.cookie("css")==rootPath+"css/nite.css"){
			$("a#day").show();
			$("a#night").hide();
			playFlashBackground(rootPath+"flash/nite.swf");
		}else{
			$("a#day").hide();
			$("a#night").show();
			playFlashBackground(rootPath+"flash/day.swf");
		}
	}else if ((curhr >= 19) || (curhr <= 7) ) { //if not use computer time, check whether the time is the later than 7pm n earlier than 7am then do....
		$("#mainstyle").attr("href", rootPath+"css/nite.css");
		playFlashBackground(rootPath+"flash/nite.swf");
		$.cookie("css", rootPath+"css/nite.css");
		$("a#day").show();
		$("a#night").hide();
	}else{ //if not use day css
		$("#mainstyle").attr("href", rootPath+"css/day.css");
		playFlashBackground(rootPath+"flash/day.swf");
		$.cookie("css", rootPath+"css/day.css");
		$("a#day").hide();
		$("a#night").show();
	}
	
	  //make style links work           
	  $("a#night").click(function() {
		  $.cookie("css", rootPath+"css/nite.css"); //, {expires: 365, path: '/'}
		  //$("#mainstyle").attr("href", "css/nite.css");
		  loadStyleSheet(this);
		  $("a#day").show();
		  $("a#night").hide();
		  return false;
		  });
		  
	  $("a#day").click(function() {
	      $.cookie("css", rootPath+"css/day.css"); //, {expires: 365, path: '/'}
		  //$("#mainstyle").attr("href", "css/day.css");
		  loadStyleSheet(this);
		  $("a#day").hide();
		  $("a#night").show();
		  return false;
		  });
});

function loadStyleSheet(obj) {
	$('body').append('<div id="overlay" />');
	$('body').css({height:'100%'});
	$('#overlay')
		.css({
			display: 'none',
			position: 'absolute',
			top:0,
			left: 0,
			width: '100%',
			height: '100%',
			zIndex: 1000,
			background: 'black url(http://www.7-eleven.com.sg/images/common/loading.gif) no-repeat center'
		})
		.fadeIn(500,function(){
			if(obj.id=="night"){
				$("#mainstyle").attr("href", "http://www.7-eleven.com.sg/css/nite.css");
				playFlashBackground("http://www.7-eleven.com.sg/flash/nite.swf");
			}else{
				$("#mainstyle").attr("href", "http://www.7-eleven.com.sg/css/day.css");
				playFlashBackground("http://www.7-eleven.com.sg/flash/day.swf");
			}
				$('#overlay').fadeOut(500,function(){
					$(this).remove();
				});	
		});
}

