var storyNum = 0;
var toId = 0;
var playing = true;
var whatsHot = 0;
$(document).ready(function(){
	swapStories();
	
	var bannerPos = $("#bannerDiv").offset();
	
	//var coverRoo = '<div id="coverooBox"><a href="/giving/shop.asp?shop=cmn"><img src="/sg-images/coveroo-case.jpg" border="0" /></a><span>X</span><h2>Limited Time Cover!</h2><p>Give your phone a whole new look in seconds with a Coveroo case or cover! Coveroo will make a donation of 15% of the retail value for each case or cover sold. Show your support for Children&rsquo;s Miracle Network or your favorite team!</p><a href="/giving/shop.asp?shop=cmn" class="bodyLink">Shop Now &gt;&gt;</a></div>';
	
	/*
	var popContent = '<div id="homepopBox"><span>X</span><h2>We Raised Hope for Cancer!</h2><h3>Thanks to you we exceeded our $55 million goal!</h3></div>';
	$("#bannerDiv").append(popContent);
	$("#homepopBox").css('left',bannerPos.left+458+'px').css('top',bannerPos.top+'px').fadeIn();
	$("#homepopBox > span").click(function(){$("#homepopBox").hide();});
	*/
	
	/*
	$("#coverooBox").css('left',bannerPos.left+458+'px').css('top',bannerPos.top+'px').show();
	$("#coverooBox > span").click(function(){$("#coverooBox").hide();});
	*/
	
	/*
	$("#donationHead > span").click(function(){
		$("#widgetStuff").hide();
	});
	*/
	
	$("#homeNews > div").click(function(event){
																			var clickId = $(this).attr("id");
																			location.href = "/about-us/news-story.asp?story=" + clickId;
																			});
	$("#status > a").not("#control").hover(function(){
																									$(this).css("background-position","0px -20px");
																									},
																									function(){
																										var hotDot = '#l' + whatsHot;
																										$(this).not(hotDot).css("background-position","0px 0px");
																									});
	$("#status > a").not("#control").click(function(event){
																	clearTimeout(toId);
																	var clickId = $(this).attr("id");
																	clickId = clickId.substr(1);
																	swapStories(clickId);
																	});
	$("#control").hover(function(){
															 if(playing){
																 $(this).css("background-position","0px -20px");
															 }else{
																 $(this).css("background-position","-20px -20px");
															 }
															},
											function(){
															 if(playing){
																 $(this).css("background-position","0px 0px");
															 }else{
																 $(this).css("background-position","-20px 0px");
															 }
															 });
	$("#control").click(function(event){
															 if(playing){
																 clearTimeout(toId);
																 $(this).css("background-position","-20px 0px");
																 playing = false;
															 }else{
																 swapStories();
																 $(this).css("background-position","0px 0px");
															 }
															});
	/*
	$.getScript("http://t2g-widget.mobilecause.com/campaigns/13ZCk7P0xokvb/donations/embed_widget.js",function(){
		$("#widgetStuff").show();
	});
	*/
});

function swapStories(jumpTo)
{
	var lastBox = whatsHot;
	if(jumpTo != null){
		storyNum = jumpTo;
		$("#control").css("background-position","0px 0px");
	}
	whatsHot = storyNum;
	var contentDiv = '#c' + storyNum;
	var hotDot = '#l' + storyNum;
	var type = stories[0][storyNum];
	var ref = stories[1][storyNum];
	$(contentDiv).load("/datause/data.asp?ref="+ref+'&type='+type,function(status){
		if(status != 'error'){ 
			for(i=0;i<4;i++)
			{
				if(i != lastBox)
				{
					var tempDiv = '#c' + i;
					$(tempDiv).css('left',480);
				}
				var tempDot = '#l' + i;
				$(tempDot).css('background-position','0px 0px');
			}
			var checkH = $(contentDiv).outerHeight();
			/*
			if(checkH > 460)
			{
				$(contentDiv).css({'height':480,'overflow':'hidden'});
				$(contentDiv).find('.moreLink').show();
			}
			*/
			if(lastBox != whatsHot)
			{
				$("#c"+lastBox).animate({
																left:-480
																});
			}
			$(contentDiv).animate({
														left:20
														});
				$(contentDiv).find('.moreLink').show();
			playing = true;
			$(hotDot).css('background-position','0px -20px');
			storyNum++;
			if(storyNum >= 4){storyNum = 0;}
			toId = setTimeout("swapStories()",7000);
		}
	});
}
