$(document).ready(function(){		
	t = $("#count").attr('title');
	e = 1;
	s = t;
	setTimeout(function(){fadeThis(s);}, 4000);
	function fadeThis(s){
		if(s == e){
			$("#" + t).fadeIn("slow", function(){
				s = t;
				for(i=2;i<s;i++){
					$("#" + i).fadeIn("fast");
				}
			});
			setTimeout(function () {fadeThis(s);}, 4000);
		} else {
			$("#" + s).fadeOut("slow");
			s--;
			setTimeout(function () {fadeThis(s);}, 4000);
		}
	}
	
	/*********** BANNER ROTATOR ***********/

	$("#bb1").css({"display":"block"});
	$("#ib1").css({"top":"-20px"});

	var bnum = 3;				//Number of banners
	var first = 0;				//First news item
	var speed = 400;			//Spped of headline fade out
	var newsPause = 4000;		//Headline display time
	var bannerPause = 4000;		//Banner display time

	bannerInterval = setInterval(rotateBanner, bannerPause);

	function rotateBanner(id){
		if(id){
			id = id.substr(1);
		}
		for(i=1;i<=bnum;i++){
			if($("#bb"+i).css("display") == "block"){
				cur = i;
				rotateCheck(cur,id);
				break;
			}
		}
	}

	function rotateCheck(cur,id){
		if(id){
			next = id;
		} else if(cur == bnum){
			next = 1;
		} else {
			next = cur+1;
		}
		$("#bb"+cur).css({"display":"none"});
		$("#ib"+cur).animate({
			top:'0'
		}, 'fast');
	
		$("#bb"+next).css({"display":"block"});
		$("#ib"+next).animate({
			top:'-20'
		}, 'fast');
	}
	
	$(".bannerbox").hover(function(){
		clearInterval(bannerInterval);
	},function(){
		bannerInterval = setInterval(rotateBanner, bannerPause);
	});
	
	$(".panelbttn").hover(function(){
		clearInterval(bannerInterval);
		pbn = $(this).attr("id");
		if($("#b"+pbn).css("display") != "block"){
	rotateBanner(pbn);
		}
	},function(){
		bannerInterval = setInterval(rotateBanner, bannerPause);
	
	});
	
	/*********** NEWS SCROLLER ***********/
	
	newsInterval = setInterval(newsNext, newsPause);
	
	function newsNext(){
		first = $('ul#listticker li:first').html();
		$('ul#listticker').append("<li>"+first+"</li>");
		$('ul#listticker li:first')
		.animate({opacity: 0}, speed)
		.fadeOut(speed, function() {
	$(this).remove();
		});
	}
	
	function newsPrev(){
		last = $('ul#listticker li:last').html();
		$('ul#listticker li:last').remove();
		$('ul#listticker li:first')
		.animate({opacity: 0}, speed)
		.fadeOut(speed, function() {
	$('ul#listticker').prepend("<li>"+last+"</li>");
		});
		$('ul#listticker li:first')
		.animate({opacity: 1}, '1')
		.fadeIn(speed)
	}
	
	$("#news").hover(function(){
		clearInterval(newsInterval);
	}, function(){
		newsInterval = setInterval(newsNext, newsPause);
	});
	
	$("#newsprev").click(function(){
		newsPrev();
	
	});
	$("#newsnext").click(function(){
		newsNext();
		return false;
	});
	
	/*********** COUNTDOWNS ***********/
	
	$("#countdown_dashboard").countDown({
		targetDate: {
			"day": 		16,
			"month": 	9,
			"year": 	2010,
			"hour": 	13,
			"min": 		0,
			"sec": 		0,
			"utc":		true
		},
		omitWeeks: true
	});
	
	$("#countdown_dashboard2").countDown({
		targetDate: {
			"day": 		18,
			"month": 	10,
			"year": 	2010,
			"hour": 	6,
			"min": 		0,
			"sec": 		0,
			"utc":		true
		},
		omitWeeks: true
	});
	
	$(".sccity, .sccity2").mouseover(function(){
		bgi = "/images/top-banners/" + $(this).attr("id") + "-over2.jpg";
		$(this).css("background-image", "url('" + bgi + "')");
	}).mouseout(function(){
		$(this).css("background-image", "none");
	});	
	
	/*********** OTHER ***********/
	
	$(".follow").mouseover(function(){
		thisbg = $(this).attr("src")
		bglength = thisbg.length ;
		thisover = thisbg.substr(0,(bglength - 4));
		thisover = thisover + "o.gif";
		$(this).attr("src", thisover);
	}).mouseout(function(){
		$(this).attr("src", thisbg);
	});

	$(".hpv").mouseover(function(){
		hid = "#f" + $(this).attr("id");
		for(i=1;i<=3;i++){
	$("#fv" + i).css("display", "none");
		}
		$(hid).css("display", "block");
	});
});