//ghetto fix because FF refuses to see subdomains of domains are on the same server
//var arr = window.location.hostname.split(".");
//document.domain = arr[arr.length-2]+"."+arr[arr.length-1];

var quicklinkText = new Array("My Dog Tag", "Tickets", "HailStateTV", "Live Stats", "Mobile", "mstatestore.com", "mstatepix.com", "RSS Feeds", "Facebook", "Twitter", "Youtube");
var quicklinkLink = new Array("javascript: dogTagLogin()", "https://tkt.xosn.com/tickets/TicketLanding.dbml?db_oem_id=16800", "javascript:openLiveEventViewer(0,0,-1,-1,-1,'','','NONE')", "/liveStats/liveStats.dbml?db_oem_id=16800", "/ViewArticle.dbml?ATCLID=205178194&DB_OEM_ID=16800", "http://www.mstatestore.com", "/PhotoStoreOnline.dbml?db_oem_id=16800", "/RSSFeed.dbml?DB_OEM_ID=16800&SPID=11006&SPSID=91783 ", "/ViewArticle.dbml?DB_OEM_ID=16800&ATCLID=204975202", "/ViewArticle.dbml?DB_OEM_ID=16800&ATCLID=204975202", "http://www.youtube.com/user/mstateathletics");
var breakingNewsTop = 0;
var breakingNewsHeight = 0;
var rotatorIndex = 0;
var rotatorTotal = 0;
var rotatorPage = 1;
var rotatorTime = 5000;
var rotatorTimer = null;
var rotatorArrow = 0;
var rotatorPageTotal = 0;
var schedulelastrun = 0;

jQuery(document).ready(function () {
	jQuery("#quicklinks div.quicklink").each(function() {
		jQuery(this).bind("mouseenter", function() {
			jQuery(this).animate({
				top: -2
			}, 250);
			
			jQuery(".on", this).css('visibility', 'visible');
			jQuery(".off", this).css('visibility', 'hidden');
			/*
			jQuery(".on", this).animate({
				opacity: 1
			}, 250);
			*/
			jQuery("#quicktext").html(quicklinkText[jQuery("#quicklinks .quicklink").index(this)]);
		});
		
		jQuery(this).bind("mouseleave", function() {
			jQuery(this).animate({
				top: 5
			}, 250);
			
			jQuery(".on", this).css('visibility', 'hidden');
			jQuery(".off", this).css('visibility', 'visible');
			/*
			jQuery(".on", this).animate({
				opacity: 0
			}, 250);*/
			
			jQuery("#quicktext").html('');
		});
		
		jQuery(this).bind("click", function() {
			location.href = quicklinkLink[jQuery("#quicklinks .quicklink").index(this)];
		});
	});
	
	if (ishome == 'YES') {
		//start the breaking news slider if it has enough entries
		if (jQuery("#breakslider") ) {
			breakingNewsHeight = jQuery("#breakslider").height();
			if (breakingNewsHeight > 30) {
				setTimeout("breakingNews()", 7000);	
			}	
		}
	}
	
			
	if(jQuery("#mainimage").html() != null ) {
		//if the ajax variable is yes  
		/* Removed ajax from the rotator since file cache screws up the sync
		if (useAjax == 'YES') {
			//finish filling out the rotator on page load
			jQuery.ajax({
				type:"POST",
				url:getBaseUrl()+"/share/finishrotatormain.dbml",
				data: "DB_OEM_ID="+oemid+"&SPID="+spid+"&SPSID="+spsid+"&key="+key+"&is_home_page="+ishome+"&articleIdlist="+articleIdList,
				success: function(data) {
					jQuery("#rotatortemp").html(data);
					
					//console.log(jQuery("#rotatortemp .mainstory") );
					jQuery("#rotator #mainimage").append(jQuery("#rotatortemp .mainstory") );
					
					jQuery("#rotator #subimages").append(jQuery("#rotatortemp .page") );
					jQuery("#rotator #subimages").append('<div class="clear"></div>');
					var totalwidth = 690+parseInt(jQuery("#add_width").val());
					jQuery("#rotator #subimages").css('width', totalwidth+'px');
					
					jQuery("#rotatortemp").html('');
					
					rotatorTotal = jQuery("#rotator #mainimage .mainstory").size();
					rotatorPageTotal = parseInt(rotatorTotal/5);
					
					//gross
					jQuery("#rotator #subimages .subitem .overlay").animate({
						opacity: .6
					}, 0);
					jQuery("#rotator #subimages .subitem .overlay:eq(0)").css('opacity', '0');
					
					rotatorSetup();
				}
				,error: function(XMLHttpRequest, textStatus, errorThrown) {
					alert("errorThrown:"+errorThrown);
				}
			});
		}
		
		else {*/
			rotatorPageTotal = jQuery("#rotatorpages").html();
			rotatorTotal = jQuery("#rotatortotal").html();

			//gross
			jQuery("#rotator #subimages .subitem .overlay").animate({
				opacity: .6
			}, 0);
			jQuery("#rotator #subimages .subitem .overlay:eq(0)").css('opacity', '0');
			
			rotatorSetup();
		//}	
	}
	
	jQuery("#arrowleft").bind('click', function() {
		tabSlideLeft();
	});	
	
	jQuery("#arrowright").bind('click', function() {
		tabSlideRight();
	});	
	
	var icons = {
		header: "accordion_off left",
		headerSelected: "accordion_on left"
	};
	
	jQuery("#accordion").accordion({
		icons: icons,
		change: function(event, ui) {
			if (jQuery(ui.newContent).hasClass('loading')) {
				jQuery.ajax({
					type:"POST",
					url:getBaseUrl()+"/sections/accordion.dbml",
					data: "DB_OEM_ID="+oemid+"&key="+key+"&acc_ad_id="+jQuery(ui.newContent).parent().attr('id'),
					success: function(data) {
						jQuery(ui.newContent).parent().html(data);
						jQuery(ui.newContent).parent().removeClass('loading')
					}
					,error: function(XMLHttpRequest, textStatus, errorThrown) {
						alert("errorThrown:"+errorThrown);
					}
				});
			}
		}
	});
	
	if (jQuery("#accordion").html() != null) {
		//adjust accordion content height
		var accordionHeight = 417 - (jQuery("#accordion h3").size() * 33);
		jQuery("#accordion .ui-accordion-content").css('height', accordionHeight);
	}
	
	if (jQuery("#adbelt").html() != null ) {
		jQuery("#adbelt .slider").css('width', jQuery("#adbelt .slider .adbeltad").size()*250);
		jQuery("#adbelt .slider .adbeltad:eq(2)").addClass('center');
		/*jQuery("#adbelt .slider .adbeltad.center").css('width', '250px');
		jQuery("#adbelt .slider .adbeltad.center").css('height', '72px');
		jQuery("#adbelt .slider .adbeltad.center").css('padding', '0px');
		jQuery("#adbelt .slider .adbeltad.center img").css('width', '250px');
		jQuery("#adbelt .slider .adbeltad.center img").css('height', '72px');*/
		
		//if the ajax variable is yes
		if (useAjax == 'YES') {
			//load in the rest of the ads for the adbelt
		
			jQuery.ajax({
				type:"POST",
				url:getBaseUrl()+"/share/finishadbelt.dbml",
				data: "DB_OEM_ID="+oemid+"&SPID="+spid+"&SPSID="+spsid+"&key="+key+"&is_home_page="+ishome,
				success: function(data) {
					jQuery("#adbelttemp").html(data);
					
					jQuery("#adbelt .adbeltad.last").removeClass('last');
					
					var newsliderwidth = jQuery("#adbelttemp .adbeltad").size() * 250;
					newsliderwidth = newsliderwidth + jQuery("#adbelt .slider").width();
					//add some extra pixels to stop the last element flicker
					newsliderwidth = newsliderwidth + 10;
					jQuery("#adbelt .slider").css('width', newsliderwidth+'px');
					
					jQuery("#adbelt .slider").append(jQuery("#adbelttemp .adbeltad") );
					
					jQuery("#adbelttemp").html('');
					
					jQuery("#adbelt .adbeltad:last").addClass('last');
				}
				,error: function(XMLHttpRequest, textStatus, errorThrown) {
					alert("errorThrown:"+errorThrown);
				}
			});
		}
	}
	
	//set up schedules
	if (jQuery("#schedules").html() != null) {
		jQuery("#schedules .content .item").each(function () {
			jQuery(".bar:last", this).hide();
		});
		
		jQuery("#schedules .content").bind('scroll', function(){
			if ( (jQuery("#schedules .content").scrollTop() + jQuery("#schedules .content").height()) >= jQuery("#schedules .content .contentheight").height() -100 )
				scheduleLoadMore();
		});
	}
	
	if(jQuery("#mainimage").html() != null )
		rotate();
	if (jQuery("#maroontothemax").html() != null )
		settab(currenttab);
	if (jQuery("#adbelt").html() != null )
		setTimeout('adrotate();', 3000);
		
	jQuery("body").prepend('<div id="dogtag"></div>');

	var dogtagleft = jQuery("#quicklinks .quicklink:eq(0)").offset().left - 54;
	var dogtagtop = jQuery("#quicklinks .quicklink:eq(0)").offset().top + 32;
	jQuery("#dogtag").css('left', dogtagleft+'px');
	jQuery("#dogtag").css('top', dogtagtop+'px');
	jQuery("#dogtag").html(jQuery("#dogtagcontent").html() );
	jQuery("#dogtagcontent").html('');
	
	jQuery("#quicklinks .quicklink:eq(0) .arrow").css('paddingLeft', '5px');
	
	jQuery("#dogtag input.text").focus(function() {
		jQuery(this).css('background', '#fff');
	});
	
	jQuery("#list-menu .subnav .mens .mens div").mouseenter(function() {
		jQuery(this).css('background', '#660000');
		jQuery('a', this).css('color', '#ffffff');
	}).mouseleave(function() {
		jQuery(this).css('background', 'none');
		jQuery('a', this).css('color', '#000000');
	});
	
	jQuery("#list-menu .subnav .womens .womens div").mouseenter(function() {
		jQuery(this).css('background', '#660000');
		jQuery('a', this).css('color', '#ffffff');
	}).mouseleave(function() {
		jQuery(this).css('background', 'none');
		jQuery('a', this).css('color', '#000000');
	});
	
	if (jQuery("#eggtimer").length > 0) {
		scheduleTime = jQuery.trim(jQuery("#eggtimer .usetime").html())+'00';
		tempdiff = getTimeDifference(scheduleTime, false);
		diffSplit = tempdiff.split(':');
		
		countDays = diffSplit[2];
		countHours = diffSplit[3];
		countMinutes = diffSplit[4];
		countSeconds = diffSplit[5];
		

		if (countHours < 10)
			countHours = '0'+countHours;	
		if (countMinutes < 10)
			countMinutes = '0'+countMinutes;	
		if (countSeconds < 10)
			countSeconds = '0'+countSeconds;	
		
		jQuery("#eggtimer .days").html(countDays);
		jQuery("#eggtimer .hours").html(countHours);
		jQuery("#eggtimer .minutes").html(countMinutes);
		jQuery("#eggtimer .seconds").html(countSeconds);
		
		setInterval(function(){countDown(jQuery("#eggtimer"));}, 60000);

	}
});

	/**************************************************************************************************************************************************************/
	/*                                                                                                                                                                                                                */
	/*   countdown setup                                                                                                                                                                             */
	/*                                                                                                                                                                                                                */
	/**************************************************************************************************************************************************************/


function countDown(timeContainer) {
	days = jQuery.trim(jQuery(timeContainer).find('.days').html());
	hours = jQuery.trim(jQuery(timeContainer).find('.hours').html());
	minutes = jQuery.trim(jQuery(timeContainer).find('.minutes').html());
	seconds = jQuery.trim(jQuery(timeContainer).find('.seconds').html());
	
	seconds++;
	if (seconds > 59) {
		minutes++;
		seconds = 0;
	}
	if (minutes > 59) {
		hours++;
		minutes = 0;
	}
	if (hours > 23) {
		days++;
		hours = 0;
	}
	
	//leading 0s
	if (hours.toString().length < 2)
		hours = '0'+hours;
	if (minutes.toString().length < 2)
		minutes = '0'+minutes;
	if (seconds.toString().length < 2)
		seconds = '0'+seconds;
	
	jQuery(timeContainer).find('.days').html(days);
	jQuery(timeContainer).find('.hours').html(hours);
	jQuery(timeContainer).find('.minutes').html(minutes);
	jQuery(timeContainer).find('.seconds').html(seconds);
}

function getTimeDifference(itemTime, futureTime) {
	var temp = new Date();
	var currentDate = new Date(temp.getUTCFullYear(), temp.getUTCMonth(), temp.getUTCDate(), temp.getUTCHours(), temp.getUTCMinutes(), temp.getUTCSeconds());
	var eventDate = new Date(itemTime.substr(0, 4), (itemTime.substr(4, 2)-1), itemTime.substr(6, 2), itemTime.substr(8, 2), itemTime.substr(10, 2), itemTime.substr(12, 2));
	
	//console.log(currentDate);
	//console.log(eventDate);
	
	var currentTime = currentDate.getTime();
	var eventTime = eventDate.getTime();
	
	if (futureTime) {
		differenceTime = (eventTime - currentTime)/1000;
	}
	else {
		differenceTime = (currentTime - eventTime)/1000;
	}
	
	//console.log(differenceTime);
	differenceSecs = differenceTime % 60;
	differenceTime = Math.floor(differenceTime / 60);
	differenceMins = differenceTime % 60;
	differenceTime = Math.floor(differenceTime / 60);
	differenceHours = differenceTime % 24;
	differenceTime = Math.floor(differenceTime / 24);
	differenceDays = differenceTime; 
	
	return '0:0:'+differenceDays+':'+differenceHours+':'+differenceMins+':'+differenceSecs+':0';
}


function breakingNews() {
	newtop = breakingNewsTop + 30;
	
	if (newtop >= breakingNewsHeight)
		newtop = 0;
	
	jQuery("#breakslider").animate({
		top: -newtop
	}, 250);
	
	breakingNewsTop = newtop;
	setTimeout("breakingNews()", 7000);	
}

function rotatorSetup() {
	jQuery	("#subimages .subitem").bind("click", function() {
		jumpTo(jQuery("#subimages .subitem").index(this));
	});
	
	jQuery("#subpage .page").bind("click", function() {
		pageTo((jQuery("#subpage .page").index(this)+1));
	});
}

function rotate() {
	rotatorTimer = setTimeout("rotateForward()", rotatorTime);
}

function rotateForward() {
	//before increment
	jQuery("#mainimage .mainstory:eq("+rotatorIndex+")").fadeOut(1000);
	jQuery("#subimages .subitem:eq("+rotatorIndex+") .overlay").animate({
		opacity: .6
	}, 1000);
	setTimeout('jQuery("#subimages .subitem:eq('+rotatorIndex+') .subtitle").css("background", "#000");', 1000);
	
	rotatorIndex++;
	rotatorArrow = rotatorArrow + 138;
	if (rotatorIndex == rotatorTotal) {
		rotatorIndex = 0;
		rotatorArrow = 0;
	}
	
	//after increment
	jQuery("#mainimage .mainstory:eq("+rotatorIndex+")").fadeIn(1000);
	jQuery("#subimages .subitem:eq("+rotatorIndex+") .subtitle").css('background', '#660000');
	jQuery("#subimages .subitem:eq("+rotatorIndex+") .overlay").animate({
		opacity: 0
	}, 1000);
	
	if( (rotatorIndex) % 5 == 0) {
		pageForward();
		rotatorArrow = 0;
	}
	
	jQuery("#subrotator .arrowline .arrow").animate({
		left: rotatorArrow
	}, 500);
	
	clearTimeout(rotatorTimer);
	rotatorTimer = setTimeout("rotate()", rotatorTime);
}

function rotateBackward() {
	//before decrement
	jQuery("#mainimage .mainstory:eq("+rotatorIndex+")").fadeOut(1000);
	jQuery("#subimages .subitem:eq("+rotatorIndex+") .overlay").animate({
		opacity: .6
	}, 1000);
	setTimeout('jQuery("#subimages .subitem:eq('+rotatorIndex+') .subtitle").css("background", "#000");', 1000);
	
	rotatorIndex--;
	rotatorArrow = rotatorArrow - 138;
	
	if (rotatorIndex == -1) {
		rotatorIndex = rotatorTotal-1;
		
		if (rotatorIndex >= 10)
			arrowNum = rotatorIndex - 10;
		else if (rotatorIndex >=5)
			arrowNum = rotatorIndex - 5;
			
		rotatorArrow = arrowNum*138;
	}
	
	//console.log(rotatorIndex);
	
	//after decrement
	jQuery("#mainimage .mainstory:eq("+rotatorIndex+")").fadeIn(1000);
	jQuery("#subimages .subitem:eq("+rotatorIndex+") .overlay").animate({
		opacity: 0
	}, 1000);
	jQuery("#subimages .subitem:eq("+rotatorIndex+") .subtitle").css('background', '#660000');
	
	if( rotatorIndex == (rotatorTotal-1) || rotatorIndex == 4 || rotatorIndex == 9) {
		pageBackward();

		switch(rotatorPage) {
			case 1:
				tempPage = 'one';
			break;
			case 2:
				tempPage = 'two';
			break;
			case 3:
				tempPage = 'three';
			break;
		}
		
		rotatorArrow = jQuery("#subimages .page."+tempPage+" .subitem:last").index() * 138;
	}
	
	jQuery("#subrotator .arrowline .arrow").animate({
		left: rotatorArrow
	}, 500);
	
	clearTimeout(rotatorTimer);
	rotatorTimer = setTimeout("rotate()", rotatorTime);
}

function pageForward() {
	switch(rotatorPage) {
		case 1:
			currentPage = 'one';
			nextPage = 'two';
			slideLeft = 690;
		break;
		case 2:
			currentPage = 'two';
			if (rotatorPageTotal == 3) {
				nextPage = 'three';
				slideLeft = 1380;
			}
			else {
				nextPage = 'one';
				slideLeft = 0;
			}	
		break;
		case 3:
			currentPage = 'three';
			nextPage = 'one';
			slideLeft = 0;
		break;
	}
	
	jQuery("#subimages").animate({
		left: -slideLeft
	}, 500);
	
	jQuery("#subpage .page."+currentPage).css('background', 'url(/fls/16800/site_graphics/subpage_off.png) no-repeat');
	jQuery("#subpage .page."+nextPage).css('background', 'url(/fls/16800/site_graphics/subpage_on.png) no-repeat');
	
	rotatorPage++;
	if (rotatorPage > 3)
		rotatorPage = 1;
}

function pageBackward() {
	switch(rotatorPage) {
		case 1:
			currentPage = 'one';
			if (rotatorPageTotal == 3) {
				nextPage = 'three';
				slideLeft = 1380;
			}
			else {
				nextPage = 'two';
				slideLeft = 690;
			}	
		break;
		case 2:
			currentPage = 'two';
			nextPage = 'one';
			slideLeft = 0;
		break;
		case 3:
			currentPage = 'three';
			nextPage = 'two';
			slideLeft = 690;
		break;
	}
	
	jQuery("#subimages").animate({
		left: -slideLeft
	}, 500);
	
	jQuery("#subpage .page."+currentPage).css('background', 'url(/fls/16800/site_graphics/subpage_off.png) no-repeat');
	jQuery("#subpage .page."+nextPage).css('background', 'url(/fls/16800/site_graphics/subpage_on.png) no-repeat');
	
	rotatorPage--;
	if (rotatorPage == 0)
		rotatorPage = rotatorPageTotal;
}

function jumpTo(itemNum) {
	//before increment
	jQuery("#mainimage .mainstory:eq("+rotatorIndex+")").fadeOut(1000);
	jQuery("#subimages .subitem:eq("+rotatorIndex+") .overlay").animate({
		opacity: .6
	}, 1000);
	setTimeout('jQuery("#subimages .subitem:eq('+rotatorIndex+') .subtitle").css("background", "#000");', 1000);
	
	arrowNum = itemNum;
	
	if (itemNum >= 10)
		arrowNum = itemNum - 10;
	else if (itemNum >= 5)
		arrowNum = itemNum - 5;
	
	rotatorIndex = itemNum;
	rotatorArrow = arrowNum*138;
		
	//after increment
	jQuery("#mainimage .mainstory:eq("+itemNum+")").fadeIn(1000);
	jQuery("#subimages .subitem:eq("+itemNum+") .overlay").animate({
		opacity: 0
	}, 1000);
	jQuery("#subimages .subitem:eq("+itemNum+") .subtitle").css('background', '#660000');
	
	jQuery("#subrotator .arrowline .arrow").animate({
		left: rotatorArrow
	}, 500);
	
	clearTimeout(rotatorTimer);
}

function pageTo(pageNum) {
	hideNeuLionVid();
	
	jumpTo((pageNum-1)*5);
	switch(rotatorPage) {
		case 1:
			currentPage = 'one';
		break;
		case 2:
			currentPage = 'two';
		break;
		case 3:
			currentPage = 'three';
		break;
	}
	
	switch(pageNum) {
		case 1:
			nextPage = 'one';
			slideLeft = 0;
		break;
		case 2:
			nextPage = 'two';
			slideLeft = 690;
		break;
		case 3:
			nextPage = 'three';
			slideLeft = 1380;
		break;
	}
	
	rotatorPage = pageNum;
	
	jQuery("#subimages").animate({
		left: -slideLeft
	}, 500);
	
	jQuery("#subpage .page."+currentPage).css('background', 'url(/fls/16800/site_graphics/subpage_off.png) no-repeat');
	jQuery("#subpage .page."+nextPage).css('background', 'url(/fls/16800/site_graphics/subpage_on.png) no-repeat');
	
	clearTimeout(rotatorTimer);
	rotatorTimer = setTimeout("rotate()", rotatorTime);
}

function rotatorStop() {
	clearTimeout(rotatorTimer);	
}

function showNeuLionVid(vidid){
	rotatorStop();
	jQuery("#NeulionVidContainer").show();
	neulionPlayer(vidid);
	rotate = true;
	playerRunning = true;
}

function hideNeuLionVid(){
	if (jQuery("#NeulionVidContainer").css('display') != 'none'){
		jQuery("#NeulionVidContainer").hide();
		slProxy("hide"); // handle Silverlight
		if (jQuery("#jtvshlembed") && document.getElementById('jtvshlembed').pauseVideo){
			document.getElementById('jtvshlembed').pauseVideo();
			playerRunning = false;
		}
		rotate();
	}
}

function showNeuLionVidArticle(vidid){
	jQuery("#articleVideoContainer").show();
	jQuery("#NeulionVidContainer").show();
	neulionPlayer(vidid);
	playerRunning = true;
}

function hideNeuLionVidArticle(){
	if (jQuery("#NeulionVidContainer").css('display') != 'none'){
		jQuery("#articleVideoContainer").hide();
		jQuery("#NeulionVidContainer").hide();
		if (jQuery("#jtvshlembed") && document.getElementById('jtvshlembed').pauseVideo){
			document.getElementById('jtvshlembed').pauseVideo();
			playerRunning = false;
		}
		rotate();
	}
}

function settab(tabid) {
	jQuery("#"+currenttab).removeClass('on').addClass('off');
	jQuery("#"+tabid).removeClass('off').addClass('on');
	
	jQuery("#maroontothemax .header ."+currenttab).removeClass('on').addClass('off');
	jQuery("#maroontothemax .header ."+tabid).removeClass('off').addClass('on');
	
	if (jQuery("#"+tabid).hasClass('loading')) {
		jQuery.ajax({
			type:"POST",
			url:getBaseUrl()+"/tabs/"+tabid+".dbml",
			data: "DB_OEM_ID="+oemid+"&key="+key+"&spid="+spid,
			success: function(data) {
				jQuery("#"+tabid).html(data);
				jQuery("#"+tabid).removeClass('loading');
			}
			,error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert("errorThrown:"+errorThrown);
			}
		});
	}
	
	currenttab = tabid;
}

function tabSlideLeft() {
	jQuery("#arrowleft").unbind('click');
	var maxlength = jQuery("#"+currenttab+" .slider").width();
	var pos = jQuery("#"+currenttab+" .slider").position();
	var newpos = 0;
	
	if ( (pos.left + 228) <= 0)
		newpos = pos.left + 228;
	else
		newpos = pos.left;
	
	jQuery("#"+currenttab+" .slider").animate({
		left: newpos
	}, 500);
	
	setTimeout('jQuery("#arrowleft").bind("click", function() {tabSlideLeft();})', 500);	
}

function tabSlideRight() {
	jQuery("#arrowright").unbind('click');
	var maxlength = jQuery("#"+currenttab+" .slider").width();
	var pos = jQuery("#"+currenttab+" .slider").position();
	var newpos = 0;
	
	if ( (pos.left - 228) > (-maxlength+228))
		newpos = pos.left - 228;
	else
		newpos = pos.left;
	
	jQuery("#"+currenttab+" .slider").animate({
		left: newpos
	}, 500);
	
	setTimeout('jQuery("#arrowright").bind("click", function() {tabSlideRight();})', 500);
}

function adrotate() {
	var adpos = jQuery("#adbelt .slider").position();
	var adleft = adpos.left;
	var centerindex = jQuery("#adbelt .slider .adbeltad").index(jQuery("#adbelt .slider .adbeltad.center"));
	
	if (jQuery("#adbelt .slider .adbeltad.center").hasClass('last')) {
		adleft = 375;
	}
	else {
		adleft = adleft - 250;
	}
	
	/*jQuery("#adbelt .slider .adbeltad.center img").animate({
		width: 234,
		height: 60
	}, 500);
		
	jQuery("#adbelt .slider .adbeltad.center").animate({
		width: 234,
		height: 60,
		paddingTop: 6,
		paddingBottom: 6,
		paddingLeft: 8,
		paddingRight: 8
	}, 500);*/
	
	jQuery("#adbelt .highlight").fadeOut(500);
	
	setTimeout('adrotate2('+centerindex+', '+adleft+');', 500);
	//adrotate2(centerindex, adleft);
}

function adrotate2(centerindex, adleft) {
	jQuery("#adbelt .slider .adbeltad:eq("+centerindex+")").removeClass('center');
	jQuery("#adbelt .slider").animate({
		left: adleft
	}, 1000);
	
	setTimeout('adrotate3('+centerindex+', '+adleft+');', 1000);
}

function adrotate3(centerindex, adleft) {
	if (jQuery("#adbelt .slider .adbeltad:eq("+centerindex+")").hasClass('last')) {
		centerindex = 0;
	}
	else {
		centerindex++;
	}

	jQuery("#adbelt .slider .adbeltad:eq("+centerindex+")").addClass("center");
	
	/*
	jQuery("#adbelt .slider .adbeltad.center").animate({
		width: 250,
		height: 72,
		paddingTop: 0,
		paddingBottom: 0,
		paddingLeft: 0,
		paddingRight: 0
	}, 500);
	
	jQuery("#adbelt .slider .adbeltad.center img").animate({
		width: 250,
		height: 72
	}, 500);*/
	jQuery("#adbelt .highlight").fadeIn(500);
	
	setTimeout('adrotate();', 3000);
}

function scheduleLoadMore() {
	var startRow = jQuery("#schedules .content .item").size()+1;
	var endRow = startRow+9;
	var scheduleFlag = startRow%10;
	var lastDate = jQuery("#schedules #lastdate").attr('date');
	jQuery("#schedules #lastdate").remove();
	
	if(startRow != schedulelastrun) {
		//if the starting row is not 10, assume there's no more
		if (scheduleFlag == 1) {
			//only load 50 stories
			if (startRow < 50) {
				jQuery("#schedules .loading").show();
				jQuery.ajax({
					type:"POST",
					url:getBaseUrl()+"/share/schedules.dbml",
					data: "DB_OEM_ID="+oemid+"&key="+key+"&schedule.start_row="+startRow+"&schedule.end_row="+endRow+"&sch_count=1&schedule.last_date="+lastDate+"&SPID="+spid,
					success: function(data) {
						jQuery("#schedules .content .contentheight").append(data);
						jQuery("#schedules .content .item").each(function () {
							jQuery(".bar:last", this).hide();
						});
						jQuery("#schedules .loading").hide();
					}
					,error: function(XMLHttpRequest, textStatus, errorThrown) {
						alert("errorThrown:"+errorThrown);
					}
				});
			}
		}
		schedulelastrun = startRow;
	}
}

function popupMedia(sid) {
//	/mediaPortal/player.dbml?&DB_OEM_ID=16800	
	window.open('/mediaPortal/player.dbml?DB_OEM_ID=16800&SID='+sid, 'newwindow', 'width=1035,height=1194');
}

function dogTagLogin() {
	if (jQuery("#dogtag").css('display') == 'none')
		jQuery("#dogtag").fadeIn(500);
	else
		jQuery("#dogtag").fadeOut(500);
}
	
function getBaseUrl() {
     urlTokens = window.location.href.split('/');
     url = urlTokens[0]+'//'+urlTokens[2];
     return url;
}

function toggleLoginBox() {
	jQuery("#hail-state-tv-login").fadeToggle();
}

jQuery(document).ready(function() {
	jQuery("#login-username").focus(function() {
		jQuery("#login-username").css("background","#ffffff");
	});	
	jQuery("#login-username").blur(function() {
		if(jQuery("#login-username").val()=='') 
			jQuery("#login-username").css({
				"background-image":"url('/fls/16800/site_graphics/2011/email-bg.png')",
				"background-color":"#ffffff",
				"background-repeat":"no-repeat"
			});
	});	
	jQuery("#login-password").focus(function() {
		jQuery("#login-password").css("background","#ffffff");
	});	
	jQuery("#login-password").blur(function() {
		if(jQuery("#login-password").val()=='') 
			jQuery("#login-password").css({
				"background-image":"url('/fls/16800/site_graphics/2011/password-bg.png')",
				"background-color":"#ffffff",
				"background-repeat":"no-repeat"
			});
	});	
});





