$(document).ready(function() {

	if($.browser.mozilla){
		$("html").addClass("mozilla");
	}
	
	$("#header ul li a").hover(function() {
		
		$(this).find("span").show().animate({ height: "3px" }, { queue: false, duration: 250 });
		
	}, function() {
		
		$(this).find("span").animate({ height: "0px" }, { queue: false, duration: 250 });
		
	});
	
	var leftNav = 250;

	$("ul.left li a").hover(function() {

		$(this).find("div.roll").animate({ left: "-69px" }, { queue: false, duration: leftNav });

	}, function() {

		$(this).find("div.roll").animate({ left: "0px" }, { queue: false, duration: leftNav });

	});

	function slideClose(){

		$(".sidebar a.news").animate({ right: "0px" }, { queue: false, duration: 650});

		$(".slide-menu").animate({ right: "-240px" }, { queue: false, duration: 650}).removeClass("open");

	}

	function slideOpen(){

		$(".sidebar a.news").animate({ right: "240px" }, { queue: false, duration: 650});
		
		$(".slide-menu").animate({ right: "0px" }, { queue: false, duration: 650}).addClass("open");
		
	}

	$(".slide-menu a.close").click(function() {

		slideClose();
		return false;

	});

	$(".sidebar a.news").click(function() {
		
		slideOpen();
		
		setTimeout(function(){

			slideClose();

		}, 30000);

		return false;	

	});
	
	//cookie information
	
	function addCookie(tag, value) {
	var expireDate = new Date();
	var expireString = "";
	expireDate.setTime(expireDate.getTime() + (1000 * 60 * 60 * 24 * 365));
	expireString = "expires=" + expireDate.toGMTString();
	document.cookie = tag + "=" + escape(value) + ";" + expireString + "; path=/";
	}
	
	
	function getCookie(tag) {
	var value = null;
	var myCookie = document.cookie + ";";
	var findTag = tag + "=";
	var endPos;
	if (myCookie.length > 0) {
	    var beginPos = myCookie.indexOf(findTag);
	
	    if (beginPos != -1) {
	        beginPos = beginPos + findTag.length;
	        endPos = myCookie.indexOf(";",beginPos);
	    }
	    if (endPos == -1){
	        endPos = myCookie.length;
	    }
	   value = unescape(myCookie.substring(beginPos,endPos));
	   }
	 return value;
	}
	
	function deleteCookies(cookie1, cookie2) {
	var yesterday = 24 * 60 * 60 * 1000;
	var expireDate = new Date();
	expireDate.setTime (expireDate.getTime() - yesterday);
	
	document.cookie =cookie1 + "=" + escape("nothing") + ";" + "expires"+ 
	"=" + expireDate.toGMTString() +"; path=/";
	document.cookie =cookie2 + "=" + escape("nothing") + ";" + "expires"+
	"=" + expireDate.toGMTString() + "; path=/";
	
	}
	
	var checkCookie = "";
	checkCookie = getCookie("VisitNumber");
	update = parseInt(checkCookie);
	update += 1;
	
	if (checkCookie != null && checkCookie != 0){
		addCookie("VisitNumber", update);
	} else{
	    addCookie("VisitNumber", 1);
	}	
	
	if(checkCookie < 2){
		slideOpen();
		setTimeout(function(){
	
			slideClose();
	
		}, 30000);	
		
	} else {
	
		
	
	}
	
	rotateBG();
	
	function rotateBG(){
		
		$("#bgs img").hide();
		$("#bgs img:first").show().addClass("current");
		
		rotate();
		
		function rotate(){
			
			var waitTime = 4000;

			setTimeout(function() {
				nextPhoto();
			}, waitTime);
			
		}
		
		function nextPhoto(){
			var speed = 1000;
			
			var index = $("#bgs img").index($("#bgs img.current"));
			
			if(index == ($("#bgs img").length - 1)){
					
				$("#bgs img.current").fadeOut(speed).removeClass("current").parent().children("img:first").addClass("current");
				$("#bgs img.current").fadeIn(speed);
				rotate();
				
			} else {
				
				$("#bgs img.current").fadeOut(speed).removeClass("current").next().addClass("current");
				$("#bgs img.current").fadeIn(speed);
				rotate();
				
			}
			
			

		}
		
	}

	
});