/**************************************************************************
START ROTATOR
**************************************************************************/
if (location.href.indexOf('HomePage') >= 0) 
	var rotate = true;	
else
	var rotate = false;
var rotate_current = 1;
var rotate_end = 4;
var rotate_past = rotate_end;
var scheduleMenu = 0;

jQuery(document).ready(function () {
	
	jQuery("#rotatorHeadlines-1").animate({
		top: 313
	}, 500);
	
	jQuery("#rotatorHeadlineText-1").animate({
		top: 313
	}, 500);
	
	jTwitterText = jQuery("#twitterFeed .tweetText");
	addLinkToTwitter();
});

function addLinkToTwitter() {
	if(jTwitterText.length>0) {
		data = jTwitterText.html();
		data = jQuery.trim(data);
		start = data.indexOf("http://");
		if(start>0) {
			//console.log("start: "+start);
			for(x=start;x<=data.length;x++) {
				if(data.charAt(x)==' ') {
					
					end = x;
					break;
				}	
				end = x;
			}
			linkText = data.substring(start,end); 
			newLinkText = '<a target="_BLANK" class="twitter-link" href="'+linkText+'">'+linkText+'</a>';
			//console.log("end: "+end);
			start2 = data.indexOf("http://", end);
			//console.log("start2: "+start2);
			if (start2>0) {
				
				for(x=start2;x<=data.length;x++) {
					if(data.charAt(x)==' ') {
						end2 = x;
						break;
					}	
					end2 = x;
				}
				linkText2 = data.substring(start2,end2); 
				newLinkText2 = '<a target="_BLANK" class="twitter-link" href="'+linkText2+'">'+linkText2+'</a>';
				data = data.replace(linkText2,newLinkText2);
			}
			
			data = data.replace(linkText,newLinkText);
			//console.log('data: '+data);
			jTwitterText.html(data);
		}
	}
}

function changeArticle() {
	//rotate_past = rotate_current - 1;
	////console.log("old: "+rotate_past+" new: "+rotate_current);
		
	jQuery("#main-image-"+rotate_past).fadeOut(500);
	//jQuery("#Rotator .main-content").hide();
	//jQuery("#Rotator .main-content").css("display","none");
	
	jQuery("#rotatorHeadlines-"+rotate_past).animate({
		top: 365
	}, 500);
	
	jQuery("#rotatorHeadlineText-"+rotate_past).animate({
		top: 365
	}, 500);
	
	jQuery("#sub-arrow-"+rotate_past).css("visibility", "hidden");
	
	setTimeout('jQuery("#main-content-'+rotate_past+'").hide()',500);
	setTimeout('jQuery("#main-content-'+rotate_current+'").show()',500);
	
	setTimeout('jQuery("#main-image-'+rotate_current+'").fadeIn(500)',505);
	setTimeout('jQuery("#rotatorHeadlines-'+rotate_current+'").animate({ top: 313 }, 500)', 505);
	setTimeout('jQuery("#rotatorHeadlineText-'+rotate_current+'").animate({ top: 313 }, 500)', 505);
	//setTimeout('jQuery("#sub-arrow-'+rotate_current+'").animate({ opacity: 100 }, 500)', 505);
	jQuery("#sub-arrow-"+rotate_current).css("visibility", "visible");
	
	/*jQuery("#sub-rotator-"+rotate_current).animate({
	  width: 0
	}, 500);

	jQuery("#sub-rotator-"+rotate_current).css("border", "0px");
	jQuery("#sub-rotator-"+rotate_current).css("margin", "0px");

	jQuery("#sub-rotator-"+rotate_past).animate({
	  width: 80
	}, 500);
	
	jQuery("#sub-rotator-"+rotate_past).css("border", "1px solid #ccc");
	jQuery("#sub-rotator-"+rotate_past).css("margin", "0px 3px");*/
	
	// fixes IE's problem displaying a space for the div that's hidden
	//setTimeout('jQuery("#sub-rotator-'+rotate_current+'").css("display", "none")',500);
	
	//jQuery('#sub-rotator-count').html((rotate_current+1)+"/5&nbsp;&nbsp;");
}

function article(num) {
	rotate_past = rotate_current;
	rotate_current = num;
	//jQuery("#Rotator .main-content").fadeOut(500);
	//setTimeout('jQuery("#Rotator .main-content:eq('+rotate_current+')").fadeIn(500)',510);
	////console.log(rotate_current+' - '+rotate_past);
	//jQuery("#Rotator .main-content:eq('+rotate_current+')").css("display","block");
	
	changeArticle();
	
	rotate = false;
}

/*function subStoryOn(num) {
	////console.log('subStoryOn:'+num);
	jQuery("img.sub-image").css("borderStyle","solid")
	////console.log(jQuery("img.sub-image").css("borderColor"));
	
	jQuery("img.sub-image:eq("+num+")").css("border", "2px solid #fff");
	jQuery("img.sub-image:eq("+num+")").css("marginBottom", "2px");
	
	jQuery("img.sub-image:eq("+num+")").animate({
		borderWidth:"2px",
		marginBottom:"2px"
	},500);
	//jQuery("img.arrow:eq("+num+")").slideDown(500);
	
	jQuery("img.arrow:eq("+num+")").css("display", "block");
}*/

function rotateForward() {
	////console.log('Forward');
	rotate_past = rotate_current;
	if(rotate_current!=rotate_end)
		rotate_current ++;
	else
		rotate_current = 1;	
	changeArticle();
}

function rotateBack() {
	////console.log('Back');
	rotate_past = rotate_current;
	if(rotate_current!=1)
		rotate_current --;
	else
		rotate_current = rotate_end;	
	changeArticle();
}

function Rotate() {
	////console.log("Rotate()");
	if(rotate) {
		////console.log("go");
		rotateForward(false);
	}
	else {
		////console.log('stop');
	}
}

function toggle() {
	////console.log('toggle');
	if(rotate) 
		rotate = false;
	else 
		rotate = true;
}

jQuery(document).ready(function () {
	if(document.getElementById("rotatorContent")) 
		var r = setInterval('Rotate()',7000);	//call rotate every 5 seconds
	else {
		////console.log('no rotator');
	}

	jQuery("#twoColumnContainer").css("height", jQuery("#centertwocolumns").height());
	jQuery("#rightColContainer").css("height", jQuery("#rightcolumn").height());
});

/**************************************************************************
END ROTATOR
**************************************************************************/

	
function showScheduleMenu() {
	if (scheduleMenu == 0) {
		jQuery("#scheduleSportsMenu").fadeIn(500);
		scheduleMenu = 1;	
	}
	else {
		jQuery("#scheduleSportsMenu").fadeOut(500);
		scheduleMenu = 0;
	}
}