
jQuery(window).load(function () {
  setTimeout("clearInput('#search-input')",100);	//clear search box after page load
  setTimeout("clearInput('#Login_ID')",100);		//clear enews
  setTimeout("clearInput('#login-username')",100);	//clear enews
  setTimeout("clearInput('#login-password')",100);	//clear enews
});

jQuery(document).ready(function(){
	jQuery("#featured-on-lsusports .header").dblclick(function() {
		jQuery("#hidden-login").slideToggle(500);
	});
	jQuery("#search-input").focus(function() {
		jQuery("#search-input").css("background","#ffffff");
	});	
	jQuery("#search-input").blur(function() {
		if(jQuery("#search-input").val()=='') 
			jQuery("#search-input").css("background-image","url(/fls/5200/site_graphics/bg-search.png)");
	});
	jQuery("#Login_ID").focus(function() {
		jQuery("#Login_ID").css("background","#ffffff");
	});	
	jQuery("#Login_ID").blur(function() {
		if(jQuery("#Login_ID").val()=='') 
			jQuery("#Login_ID").css("background","url(/fls/5200/site_graphics/bg-enews-text.png) no-repeat");
	});
	jQuery("#breaking-news div.button").click(function() {
		jQuery("#breaking-news").slideUp();
		setCookie('bnhide','YES',1);
	});
	if(jQuery("#latest-headlines .row").length > 0)
		setupLatestHeadlinesTimes();
	if(jQuery("#classroom-and-community .row").length > 0)
		setupClassroomAndCommunityTimes();
	jQuery("#schedule-at-a-glance .schedule .controls .left-arrow").click(function() {
		page = jQuery("#schedule-at-a-glance .schedule .data .page").html();
		ajaxGetScheduleAtAGlance(page,'schedule','back');
	});
	jQuery("#schedule-at-a-glance .schedule .controls .right-arrow").click(function() {
		page = jQuery("#schedule-at-a-glance .schedule .data .page").html();
		ajaxGetScheduleAtAGlance(page,'schedule','forward');
	});
	if(jQuery("#follow-lsu").length>0) {
		getLastTweet();	
	}
	if(jQuery("body.article #article-image").length>0) {
		imageHeight = jQuery("body.article #article-image").height();
		jQuery("#neulion-video").css("height",imageHeight+"px");
		if(jQuery("body.article #article-image .videoId").html()>'') {
			jQuery("body.article #article-image .play-button").fadeIn(1000);
			jQuery("#article-image .play-button").mouseenter(function(){
		    	//jQuery(this).css("opacity","1");
		    	jQuery(this).addClass("active");
		    }).mouseleave(function(){
		    	//jQuery(this).css("opacity",".8");
		    	jQuery(this).removeClass("active");
		    });
			jQuery("#article-image .play-button").click(function () {
				articlePlayVideo();
			});	
		}
	}
	jQuery("#bread-crumbs a:last").css("color","#210742");
	/**/
	if(jQuery(".ad-sponsors .drip-pan-group").length>1) {
		setInterval("dpRotate()",10000);
	}
	
	if(jQuery("#article-related-links a").length==0) {
		jQuery("#article-related-links").hide();	
	}
	scheduleAddDivider();
	fixArticleCommentLink();	//on articles fix link so on page links work
	getBaseUrl();
});

function fixArticleCommentLink() {
	currentUrl = window.location.href;
	articleCommentLinks = jQuery("#article-content .link a.facebook-link");
	for(x=0;x<articleCommentLinks.length;x++) {
		currentHref = jQuery(articleCommentLinks[x]).attr("href");
		jQuery(articleCommentLinks[x]).attr("href",currentUrl+currentHref);
	}
}

function getBaseUrl() {
	urlTokens = window.location.href.split('/');
	url = urlTokens[0]+'//'+urlTokens[2];
	return url;
}

function scheduleAddDivider() {
	/*
	linkGroups = jQuery("#schedule-at-a-glance .row .links");
	totalLinkGroups = linkGroups.length;
	for(x=0;x<totalLinkGroups;x++) {
		links = jQuery("span.link",linkGroups[x]);
		linksTotal = jQuery("span.link",linkGroups[x]).length;
		if(linksTotal>1) {
			newLinks = ''
			for(i=0;i<linksTotal;i++) {
				if((i!=0) && (i!=(linksTotal))) {
					newLinks = newLinks + '<span>|</span>';
				}	
				if(jQuery(links[i]).html()!='<span class="link"></span>')
					newLinks = newLinks + ('<span class="link">'+jQuery(links[i]).html()+'</span>');
			}
			jQuery(linkGroups[x]).html(newLinks);
		}
	}
	*/
}

function dpRotate() {
	total = jQuery(".ad-sponsors .drip-pan-group").length;
	for(x=0;x<total;x++) {
		if(jQuery(".ad-sponsors .drip-pan-group:eq("+x+")").hasClass("active")) {
			current = x;
			break;	
		}
	}
	jQuery(".ad-sponsors .drip-pan-group").removeClass("active");
	if(current==(total - 1))
		next = 0;
	else
		next = current + 1;
	jQuery(".ad-sponsors .drip-pan-group:eq("+next+")").addClass("active");
}

function dpAdOn(jThis) {
	jThis.css('top','-48px');
}

function dpAdOff(jThis) {
	jThis.css('top','0px');
}

function articleText(sign) {
	articleTextObj = jQuery("#article-content .text");
	currentFontSize = articleTextObj.css("font-size");
	strLen = currentFontSize.length;
	currentFontSize = parseInt(currentFontSize.substr(0,strLen-2));
		if(sign=='+') {
			if(currentFontSize < 18) {
				//console.log("+");
				currentFontSize ++;
				articleTextObj.css("font-size",currentFontSize+"px");
			}
		}
		else {
			if(currentFontSize > 9) {
				//console.log("-");
				currentFontSize --;
				articleTextObj.css("font-size",currentFontSize+"px");
			}
		}	
}

function articlePlayVideo() {
	id = jQuery("body.article #article-image .videoId").html();
	if(id>0) {
		jQuery("#neulion-video").css("display","block");
    	neulionPlayer(id);
	}
}

function getLastTweet() {
	spid = jQuery("#follow-lsu .data .spid").html();
	jQuery.ajax({
   		type: "POST",
   		url: getBaseUrl()+"/ajaxLastTweet.dbml",
   		data: "DB_OEM_ID=5200&spid="+spid,
   		success: function(data){
   			if(jQuery.trim(data)>'') {
   				dataArray = data.split("|");
				twitterDate = dataArray[1];
				twitterText = dataArray[0];
   				start = twitterText.indexOf("http://");
   				if(start>0) {
   					for(x=start;x<=twitterText.length;x++) {
   						currentCharacter = twitterText[x];	//non-IE browsers
   						if(currentCharacter = 'undefinied')
   							currentCharacter = twitterText.charAt(x);	//IE only
   						if(currentCharacter==" ") {
   							end = x;
   							break;
   						}	
   						end = x;
   					}				
   					linkText = twitterText.substring(start,end); 
   					newLinkText = '<a target="_BLANK" class="twitter-link" href="'+linkText+'">'+linkText+'</a>';
   					twitterText = twitterText.replace(linkText,newLinkText); 
   				}
   				/*
   				if(twitterDate) {					
					twitterDateMon = twitterDate.substr(8,3); 
					twitterDateDD = twitterDate.substr(5,2); 
					twitterDateHH = twitterDate.substr(17,2); 
					twitterDateHH = parseInt(twitterDateHH);
					if(twitterDateHH>12) {
						twitterDateHH = twitterDateHH - 12;
						twitterAMPM = 'PM';
					}
					else {
						twitterAMPM = 'AM';
					}
					if(twitterDateHH==0) {
						twitterDateHH = '12';	
					}
					twitterDateMM = twitterDate.substr(20,2);
				}
				*/
   				//List of twitter names to remove from start of twitter postings
   				var replaceTwitterNames = new Array('LSUsports: ','LSUCoachMiles: ','LSUVolleyball: ','LSUTrackField: ','LSUSoccer: ','LSUCoachStarkey: ','lsu_softball');
   				for(x=0;x<replaceTwitterNames.length;x++) {
   					twitterText = twitterText.replace(replaceTwitterNames[x],"");
					twitterText = twitterText.replace(replaceTwitterNames[6],"LSUSoftball");
   				}
	   			jQuery("#follow-lsu .quote").html(twitterText);
	   			//jQuery("#follow-lsu .date").html(twitterDateMon+' '+twitterDateDD+', '+twitterDateHH+':'+twitterDateMM+' '+twitterAMPM);
	   			//jQuery("#follow-lsu .date").html(twitterDateMon+' '+twitterDateDD);
	   			jQuery("#follow-lsu .date").html(twitterDate);
	   			jQuery("#follow-lsu").animate({height:"40px",opacity:"1"},1000);		
   			}
   			else {
   				//don't show	
   			}
   		}
 	});
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function ajaxGetScheduleAtAGlance(page,tab,direction) {
	jQuery("#schedule-at-a-glance .loading").fadeIn(500);
	if(direction=='forward')
		page++;
	else if(direction=='back')
		page--;
		
	jQuery.ajax({
   		type: "POST",
   		url: getBaseUrl()+"/ajaxScheduleEvents.dbml",
   		data: "DB_OEM_ID=5200&page="+page+"&type="+tab,
   		success: function(data){
     	if(tab=='schedule') {
     		jQuery("#schedule-at-a-glance .schedule").html(data);
     		jQuery("#schedule-at-a-glance .schedule .controls .right-arrow").bind("click", function(e){
		    	page = jQuery("#schedule-at-a-glance .schedule .data .page").html();
				ajaxGetScheduleAtAGlance(page,'schedule','forward');
		    });	
		   	jQuery("#schedule-at-a-glance .schedule .controls .left-arrow").bind("click", function(e){
		    	page = jQuery("#schedule-at-a-glance .schedule .data .page").html();
				ajaxGetScheduleAtAGlance(page,'schedule','back');
		    });	
		    jQuery("#schedule-at-a-glance .tabs").hide();
		    jQuery("#schedule-at-a-glance ."+tab).show();
			jQuery("#schedule-at-a-glance .loading").fadeOut(500);
     	}
     	else if(tab=='scores') {
     		jQuery("#schedule-at-a-glance .scores").html(data);
     		jQuery("#schedule-at-a-glance .scores .controls .right-arrow").bind("click", function(e){
		    	page = jQuery("#schedule-at-a-glance .scores .data .page").html();
				ajaxGetScheduleAtAGlance(page,'scores','forward');
		    });	
		   	jQuery("#schedule-at-a-glance .scores .controls .left-arrow").bind("click", function(e){
		    	page = jQuery("#schedule-at-a-glance .scores .data .page").html();
				ajaxGetScheduleAtAGlance(page,'scores','back');
		    });	
		    jQuery("#schedule-at-a-glance .tabs").hide();
		    jQuery("#schedule-at-a-glance ."+tab).show();
			jQuery("#schedule-at-a-glance .loading").fadeOut(500);
     	}
     	else if(tab=='records') {
     		jQuery("#schedule-at-a-glance .records").html(data);
     		jQuery("#schedule-at-a-glance .records .controls .right-arrow").bind("click", function(e){
		    	page = jQuery("#schedule-at-a-glance .records .data .page").html();
				ajaxGetScheduleAtAGlance(page,'records','forward');
		    });	
		   	jQuery("#schedule-at-a-glance .records .controls .left-arrow").bind("click", function(e){
		    	page = jQuery("#schedule-at-a-glance .records .data .page").html();
				ajaxGetScheduleAtAGlance(page,'records','back');
		    });	
		    jQuery("#schedule-at-a-glance .tabs").hide();
		    jQuery("#schedule-at-a-glance ."+tab).show();
			jQuery("#schedule-at-a-glance .loading").fadeOut(500);
     	}
     	setTimeout("scheduleAddDivider()",500);
   	}
 	});
}

function selectScheduleTab() {
	ajaxGetScheduleAtAGlance(1,'schedule','none')
}

function selectScoresTab() {
	ajaxGetScheduleAtAGlance(1,'scores','none')
}

function selectRecordsTab() {
	ajaxGetScheduleAtAGlance(1,'records','none')
}

function clearInput(jSelector) {
	jQuery(jSelector).val('');
}

function setupLatestHeadlinesTimes() {
	hourFraction = 1/24;
	minuteFraction = 1/60;
	for(x=0;x<jQuery("#latest-headlines .row").length;x++) {
		message = '';
		diff = jQuery("#latest-headlines .row:eq("+x+") .data .diff").html();	
		if(diff<1) {
			if(diff<hourFraction) {
				totalMinutes = Math.round(diff/minuteFraction);
				message = ' - ' + totalMinutes + ' minutes';
			}
			else {
				totalHours = Math.round(diff/hourFraction);
				message = ' - ' + totalHours + ' hours';
			}
		}
		else {
			//more then a day
		}
		jQuery("#latest-headlines .row:eq("+x+") span.time").html(message);
	}
}

function setupClassroomAndCommunityTimes() {
	hourFraction = 1/24;
	minuteFraction = 1/60;
	for(x=0;x<jQuery("#classroom-and-community .row").length;x++) {
		message = '';
		diff = jQuery("#classroom-and-community .row:eq("+x+") .data .diff").html();	
		if(diff<1) {
			if(diff<hourFraction) {
				totalMinutes = Math.round(diff/minuteFraction);
				message = ' - ' + totalMinutes + ' minutes';
			}
			else {
				totalHours = Math.round(diff/hourFraction);
				message = ' - ' + totalHours + ' hours';
			}
		}
		else {
			//more then a day
		}
		jQuery("#classroom-and-community .row:eq("+x+") span.time").html(message);
	}
}

/******************************************************************************
	START Featured on LSUSports.net Slider
******************************************************************************/
jQuery(document).ready(function(){
	buildFeaturedSlider();
	jQuery("#slider-featured").easySlider({
		trigger: 'slider-featured-data',
		firstShow: true,
		lastShow: true,
		auto: false,
		continuous: true,
		pause: 10000,
		speed: 1000
	});
	jQuery("#featured-on-lsusports .control-left").click(function () {
		jQuery("#prevBtn").trigger("click");	
	});
	jQuery("#featured-on-lsusports .control-right").click(function () {
		jQuery("#nextBtn").trigger("click");	
	});
});
function buildFeaturedSlider() {
	objAds = jQuery("#featured-on-lsusports div.ad-loader div.ad");	
	current = 1;currentGroup = 1;groupSize = 3;
	for(x=0;x<objAds.length;x++) {
		if(current==1) {jQuery("#featured-on-lsusports ul").append('<li class="group'+currentGroup+'"></li>');	}
		jQuery("#featured-on-lsusports ul li.group"+currentGroup).append(jQuery(objAds)[x]);
		if((current==1) || (current==2)) {jQuery("#featured-on-lsusports ul li.group"+currentGroup).append('<div class="divider"></div>');}
		if(current==groupSize) {current = 1;currentGroup ++;}
		else {current ++;	}
	}
	jQuery("#featured-on-lsusports").animate({height:"108px",opacity:"1"},1000);	
}
/******************************************************************************
	END Featured on LSUSports.net Slider
******************************************************************************/

/******************************************************************************
	START photo-finish
******************************************************************************/
var rotPF = {
	current : 0,
	total : 10,
	interval : 10000,
	rotate : true
};
jQuery(document).ready(function(){
	if(jQuery("#photo-finish .album").length>1) {
		rotPF.total=jQuery("#photo-finish .album").length;
		setInterval("photoFinishRotate()",rotPF.interval);
		jQuery("#photo-finish .left-button").click(function() {
			photoFinishPreviousButton();
		});
		jQuery("#photo-finish .right-button").click(function() {
			photoFinishNextButton();
		});
	}
});

function photoFinishSelect(num) {
	rotPF.rotate = false;
	jQuery("#photo-finish .album").fadeOut(250);
	jQuery("#photo-finish .dot").removeClass("active");
	rotPF.current = num;
	jQuery("#photo-finish .dot:eq("+rotPF.current+")").addClass("active");
	setTimeout("photoFinishShow()",250);
	setTimeout("photoFinishSetActive()",550);
}

function photoFinishRotate() {
	if(rotPF.rotate)
		photoFinishNext();	
}

function photoFinishPreviousButton() {
	rotPF.rotate = false;
	photoFinishPrevious();
}

function photoFinishNextButton() {
	rotPF.rotate = false;
	photoFinishNext();
}

function photoFinishPrevious() {
	for(x=0;x<jQuery("#photo-finish .album").length;x++) {
		if(jQuery("#photo-finish .album:eq("+x+")").hasClass("active")) {
			rotPF.current=x;
			//jQuery("#photo-finish .album").removeClass("active");
			jQuery("#photo-finish .album").fadeOut(250);
			jQuery("#photo-finish .dot").removeClass("active");
			if(rotPF.current==0) 
				rotPF.current = rotPF.total - 1;
			else 
				rotPF.current --;
			//jQuery("#photo-finish .album:eq("+rotPF.current+")").addClass("active");
			//jQuery("#photo-finish .album:eq("+rotPF.current+")").fadeIn(500);
			jQuery("#photo-finish .dot:eq("+rotPF.current+")").addClass("active");
			setTimeout("photoFinishShow()",250);
			setTimeout("photoFinishSetActive()",550);
			break;	
		}	
	}
}

function photoFinishNext() {
	for(x=0;x<jQuery("#photo-finish .album").length;x++) {
		if(jQuery("#photo-finish .album:eq("+x+")").hasClass("active")) {
			rotPF.current=x;
			//jQuery("#photo-finish .album").removeClass("active");
			jQuery("#photo-finish .album").fadeOut(250);
			jQuery("#photo-finish .dot").removeClass("active");
			if(rotPF.current<(rotPF.total - 1)) 
				rotPF.current ++;
			else 
				rotPF.current = 0;
			//jQuery("#photo-finish .album:eq("+rotPF.current+")").addClass("active");
			//jQuery("#photo-finish .album:eq("+rotPF.current+")").fadeIn(500);
			jQuery("#photo-finish .dot:eq("+rotPF.current+")").addClass("active");
			setTimeout("photoFinishShow()",250);
			setTimeout("photoFinishSetActive()",550);
			break;	
		}	
	}
}

function photoFinishShow() {
	jQuery("#photo-finish .album:eq("+rotPF.current+")").fadeIn(250);
}

function photoFinishSetActive() {
	jQuery("#photo-finish .album").removeClass("active");
	jQuery("#photo-finish .album:eq("+rotPF.current+")").addClass("active");
}
/******************************************************************************
	END photo-finish
******************************************************************************/

/******************************************************************************
	START lsu-video
******************************************************************************/
jQuery(document).ready(function() {
	if(jQuery("#tab-featured-videos").length>0) {
		if(jQuery("#geaux-zone .video .live").length>0) {
			selectLsuVideoTab(jQuery("#tab-geau-zone"));
		}
		else {
			selectLsuVideoTab(jQuery("#tab-featured-videos"));
		}
	}
	jQuery("#lsu-videos .button").click(function() {
		selectLsuVideoTab(jQuery(this));
	});	
});

function selectLsuVideoTab(jThis) {
	previousTabsWidthTotal = 0;
	jQuery("#lsu-videos .button").removeClass("active");
	jThis.addClass("active");	
	for(x=0;x<jQuery("#lsu-videos .button").length;x++) {
		if(jQuery("#lsu-videos .button:eq("+x+")").hasClass("active")) {
			index = x;
			break;
		}
		else {
			previousTabsWidthTotal = previousTabsWidthTotal + jQuery("#lsu-videos .button:eq("+x+")").width();
			continue;	
		}
	}
	curTabWidth = jThis.width();
	arrowWidth = jQuery("#lsu-videos .arrow").width();
	arrowLeft = previousTabsWidthTotal + (curTabWidth/2) - (arrowWidth/2);
	jQuery("#lsu-videos .arrow").animate({left:arrowLeft+"px"},500);
	jQuery("#lsu-videos .tabs .content").fadeOut(250);
	local_index = index;
	setTimeout("showLsuVideoContent(local_index)",250);
}

function showLsuVideoContent(index) {
	jQuery("#lsu-videos .tabs .content:eq("+index+")").fadeIn(250).addClass("active");
}
/******************************************************************************
	END lsu-video
******************************************************************************/

/******************************************************************************
	START on-the-block
******************************************************************************/
jQuery(document).ready(function() {
	if(jQuery("#on-the-block .auction").length>1)
		setInterval("rotateAuctions()",10000);
});

function rotateAuctions() {
	auctions = jQuery("#on-the-block .auction");
	auctionsTotal = auctions.length;
	current = 0;
	for(x=0;x<auctionsTotal;x++) {
		if(jQuery("#on-the-block .auction:eq("+x+")").hasClass("active")) {	
			current = x;
			break;
		}
	}
	if(current==(auctionsTotal-1)) 
		current = 0;
	else
		current ++;
	auctions.removeClass("active");
	jQuery("#on-the-block .auction:eq("+current+")").addClass("active");
}
/******************************************************************************
	END on-the-block
******************************************************************************/

/******************************************************************************
	START Rotator
******************************************************************************/
var rotObject = {
	current : 0,
	last : 0,
	total : 4,
	interval : 10000,
	rotate : true,
	playingVideo : false,
	next : 1,
	previous : 4,
	oemid : 5200
};

jQuery(document).ready(function(){
	if(jQuery("body").hasClass("sport")) 
		rotObject.rotate = false;	//don't rotate on sport pages
	if(jQuery("body").hasClass("article")) 
		rotObject.rotate = false;	//don't rotate on article pages
	if(jQuery("#rotator").length > 0) 
		buildRotator();	
	jQuery("#rotator .play-button").mouseenter(function(){
    	jQuery(this).addClass("active");
    }).mouseleave(function(){
    	jQuery(this).removeClass("active");
    });
	jQuery("#rotator .play-button").click(function () {
		rotPlayVideo();
	});	
	jQuery("#rotator .video-close").click(function () {
		rotStopVideo();
	});	
}); 
function buildRotator() {
	jQuery("#rotator").animate({height:"360px",opacity:"1"},1000);	
	setTimeout("rotChangeOverlayHeadline()",1000);
	for(x=0;x<jQuery("#rotator .data").length;x++) {
		imageSrc = jQuery("#rotator .data .large-image:eq("+x+")").html();
		articleId = jQuery("#rotator .data:eq("+x+") .articleId").html();
		jQuery("#rotator .main-image").append('<img id="main-'+x+'" class="rot-image" onclick="document.location.href=\'/ViewArticle.dbml?DB_OEM_ID=5200&ATCLID='+articleId+'\'" src="'+imageSrc+'"/>');
		headline = jQuery("#rotator .data:eq("+x+") .headline").html();
		shortHeadline = jQuery("#rotator .data:eq("+x+") .short-headline").html();
		jQuery("#rotator .storys").append('<div onclick="rotSelect('+x+')" class="story"><div class="selected"></div><div class="text">'+shortHeadline+'</div></div>');
		if(x==0) {
			jQuery("#main-0").addClass("active");	
			videoId = jQuery("#rotator .data:eq(0) .videoId").html();
			if(videoId > '') 
				jQuery("#rotator .play-button").css("display","block");	
		}
	}
	setInterval("rotAuto()",9000);
}

function rotSubStorySelect() {
	jQuery("#rotator .storys .story .selected").fadeOut(250);
	jQuery("#rotator .storys .story .text").css("color","#777777");	
	setTimeout("rotSubStoryActivate()",250);
}

function rotSubStoryActivate() {
	jQuery("#rotator .storys .story .selected:eq("+rotObject.current+")").fadeIn(250);
	jQuery("#rotator .storys .story .text:eq("+rotObject.current+")").css("color","#ffffff");	
}

function rotSlideUpHeadline() {
	jQuery("#rotator .overlay-headline").animate({height:"79px"	},500);
	//jQuery("#rotator .overlay-headline .headline")[0].style.removeAttribute('filter');

}

function rotSlideDownHeadline() {
	jQuery("#rotator .overlay-headline").animate({height:"0px"	},500);
	//jQuery("#rotator .overlay-headline .headline")[0].style.removeAttribute('filter');
}

function fixClearType(obj) {
	//element.style.removeAttribute('filter');
}

function rotAuto() {
	if(rotObject.rotate) 
		rotNext();	
}

function rotNext() {
	rotObject.last = rotObject.current;
	if(rotObject.current==rotObject.total) {
		rotObject.current = 0;
		rotSetupSubStory(rotObject.current);
	}
	else {
		rotObject.current ++;
		rotSetupSubStory(rotObject.current);
	}
}
/*
These functions are not currently needed
Uncomment if controls are added to the rotator
-----------------------------------------------
function rotPrevious() {
	rotObject.last = rotObject.current;
	if(rotObject.current==0) {
		rotObject.current = rotObject.total;
		rotSetupSubStory(rotObject.current);
	}
	else {
		rotObject.current --;
		rotSetupSubStory(rotObject.current);
	}
}

function rotButtonPrevious() {
	rotObject.rotate = false;	
	rotPrevious();
}

function rotButtonNext() {
	rotObject.rotate = false;	
	rotNext();
}

function rotButtonPlayPause() {
	if(rotRotate)
		rotObject.rotate = false;
	else
		rotObject.rotate = true;
}
*/
function rotSelect(num) {
	rotObject.rotate = false;
	rotObject.last = rotObject.current;
	rotObject.current = num;	
	rotStopVideo();
	setTimeout("rotSetupSubStory()",100);
}

function rotSetupSubStory() {
	videoId = jQuery("#rotator .data:eq("+rotObject.current+") .videoId").html();
	if(videoId > '') 
		jQuery("#rotator .play-button").show();	
	else {
		jQuery("#rotator .play-button").hide();	
		//jQuery("#rotator .play-button").hide();
	}
	if(rotObject.current == rotObject.total)
		rotObject.next = 0;
	else
		rotObject.next = rotObject.current + 1;
	if(rotObject.current == 0)
		rotObject.previous = rotObject.total;
	else
		rotObject.previous = rotObject.current - 1;
	jQuery("#main-"+rotObject.current).addClass("next");
	rotSlideDownHeadline();
	setTimeout("rotChangeOverlayHeadline()",500);
	setTimeout("rotSelectSubStory()",10);
}

function rotChangeOverlayHeadline() {
	jContent = jQuery("#rotator .overlay-headline .content");
	jContent.html('');
	headline = jQuery("#rotator .data:eq("+rotObject.current+") .headline").html();
	articleId = jQuery("#rotator .data:eq("+rotObject.current+") .articleId").html();
	photoAlbumId = jQuery("#rotator .data:eq("+rotObject.current+") .photoAlbumId").html();
	if(articleId>'') {
		headline = '<a href="/ViewArticle.dbml?DB_OEM_ID=5200&ATCLID='+articleId+'">'+headline+'</a>';	
	}
	//shortHeadline = headline = jQuery("#rotator .data:eq("+rotObject.current+") .short-headline").html();
	jContent.prepend('<div class="headline">'+headline+'</div>');
	jContent.prepend('<div class="links"><a class="overlay-link" href="/ViewArticle.dbml?DB_OEM_ID='+rotObject.oemid+'&ATCLID='+articleId+'">Read More <span>&#187</span></a></div>');
	buyPhoto = jQuery("#rotator .data:eq("+rotObject.current+") .buyPhoto").html();
	relatedVideos = jQuery("#rotator .data:eq("+rotObject.current+") .relatedVideos").html();
	if(buyPhoto>'') {
		/* 
		//Pictopia
		photoVars = buyPhoto.split("|");
		jQuery("#rotator .overlay-headline .content .links").append('<br /><a class="overlay-link" href="javascript:goPtp(\''+photoVars[0]+'\',\''+photoVars[1]+'\',\''+photoVars[2]+'\',\''+photoVars[3]+'\',\''+photoVars[4]+'\');">Buy This Photo <span>&#187</span></a>');
		*/
		//Replay Photos
		jQuery("#rotator .overlay-headline .content .links").append('<br /><a class="overlay-link" href="javascript:goToReplayPhotos('+buyPhoto+');">Buy This Photo <span>&#187</span></a>');
		
	}
	if(relatedVideos>'') {
		videoIds = relatedVideos.split("|");
		//jQuery("#rotator .overlay-headline .content .links").append('<br /><a class="overlay-link" href="javascript:openOnDemandViewer('+videoIds[0]+','+videoIds[1]+');">Video <span>&#187</span></a>');
		jQuery("#rotator .overlay-headline .content .links").append('<br /><a class="overlay-link" href="/mediaPortal/player.dbml?DB_OEM_ID=5200&id='+videoIds[1]+'">Video <span>&#187</span></a>');
	}
	if(photoAlbumId>'') {
		jQuery("#rotator .overlay-headline .content .links").append('<br /><a class="overlay-link" href="/PhotoAlbum.dbml?DB_OEM_ID=5200&PALBID='+photoAlbumId+'">Photo Album <span>&#187</span></a>');
	}
	rotSlideUpHeadline();
	rotSubStorySelect();
}

function rotSelectSubStory() {
	//jQuery("#main-"+rotObject.last).animate({"opacity":"0"},500);	
	for(x=0;x<jQuery(".rot-image").length;x++) {
		if(x==rotObject.current) {
			jQuery(".rot-image:eq("+x+")").fadeIn(500);
		}
		else {
			jQuery(".rot-image:eq("+x+")").fadeOut(500);
		}	
	}
	setTimeout("rotSetActive()",600);
}

function rotSetActive() {
	//jQuery(".rot-image").css("opacity","1");
	jQuery(".rot-image").removeClass("active");
	jQuery("#main-"+rotObject.current).addClass("active");
	jQuery(".rot-image").removeClass("next");
}

function rotPlayVideo() {
	rotObject.rotate = false;
	rotObject.playingVideo = true;
	jQuery("#neulion-video").css("display","block");
	videoId = jQuery("#rotator .data:eq("+rotObject.current+") .videoId").html();
    neulionPlayer(videoId);
    jQuery("#rotator .video-close").show();
}
	
function rotStopVideo() {
	rotObject.playingVideo = false;
	if(jQuery("#jtvshlembed").length>0) {
		try {document.getElementById('jtvshlembed').pauseVideo();}
		catch(ex) {/*setTimeout("rotStopVideo()",1000);*/}
	}
	jQuery("#neulion-video").hide();
	jQuery("#jtvshlAdContainer").hide();
	jQuery("#rotator .video-close").hide();
}
/******************************************************************************
	END Rotator
******************************************************************************/

/******************************************************************************
	START Scoreboard
******************************************************************************/
jQuery(document).ready(function(){
	jQuery("#scoreboard div.slider").easySlider({
		trigger: 'slider-scorebaord-data',
		prevId: 'prev-scoreboard-button',
		nextId: 'next-scoreboard-button',
		firstShow: true,
		lastShow: true,
		auto: false,
		continuous: true,
		pause: 4000,
		speed: 100
	});
	scoreboardLi = jQuery("#scoreboard .slider ul li");
	for(x=0;x<scoreboardLi.length;x++) {
		if(jQuery("#scoreboard .slider ul li:eq("+x+")").hasClass("center")) {
			index = x; 
			break;
		}
	}
	jQuery("#slider-scorebaord-data").html(index+1);
	jQuery("#slider-scorebaord-data").trigger("click");	

	jQuery("#scoreboard .control-left").click(function () {
		jQuery("#prev-scoreboard-button").trigger("click");	
	});
	jQuery("#scoreboard .control-right").click(function () {
		jQuery("#next-scoreboard-button").trigger("click");	
	});
	jQuery("#scoreboard .content .current-sport").click(function () {
		jQuery("#scoreboard-sport-list").toggle();	
	});
	jQuery(window).resize(function () { 
      positionScoreBoard();
    });
	jQuery("#scoreboard-sport-list a").click(function () {
		liTag = jQuery(this).parent();
		newSportName = jQuery(this).html();
		jQuery("#scoreboard .current-sport").html('Loading...<img src="/fls/5200/site_graphics/scoreboard-loader.gif"/>');
		newSportId = jQuery(".data .sport-id",liTag).html();
		jQuery("#scoreboard-sport-list").hide();
		getScoreBoardSport(newSportId,newSportName);
	});
	jQuery("#scoreboard .date span.live").mouseover(function() {
			jQuery(this).addClass("active");
			for(x=0;x<jQuery("#scoreboard .date span.live").length;x++) {
				if(jQuery("#scoreboard .date span.live:eq("+x+")").hasClass("active")) {
					current = x;
					break;	
				}
			}
			jQuery("#scoreboard span.live").removeClass("active");
			jQuery("#scoreboard .live-box:eq("+current+")").show();
			jQuery("#scoreboard .live-box").bind("mouseleave", function(e){
		    	jQuery("#scoreboard .live-box").hide();
		    	jQuery("#scoreboard span.live").removeClass("active");
		    });	
	});
	
	moveScoreBoard();
});

function getScoreBoardSport(id,name) {
	jQuery("#scoreboard").animate({height:"17px"},1000);
	jQuery.ajax({
   		type: "POST",
   		url: getBaseUrl()+"/ajaxScoreboard.dbml",
   		data: "DB_OEM_ID=5200&SPID="+id,
   		success: function(data){
   			jQuery("#scoreboard .current-sport").html(name);
   			jQuery("#scoreboard .slider ul").html(data);
   			jQuery("#scoreboard div.slider").easySlider({
				trigger: 'slider-scorebaord-data',
				prevId: 'prev-scoreboard-button',
				nextId: 'next-scoreboard-button',
				firstShow: true,
				lastShow: true,
				auto: false,
				continuous: true,
				pause: 4000,
				speed: 100
			});
			
			scoreboardLi = jQuery("#scoreboard .slider ul li");
			totalLi = scoreboardLi.length;
			var scoreBoardShowTime = totalLi * 100;
			//console.log("scoreBoardShowTime:"+scoreBoardShowTime);
			setTimeout("showScoreBoardAjax()",scoreBoardShowTime);
		   			
   			/*
   			totalLiTags = jQuery("#scoreboard .slider ul li").length;
   			liWidth = jQuery("#scoreboard .slider ul li:eq(0)").width();
   			jQuery("#scoreboard .slider ul").css("width",totalLiTags*liWidth+"px");
   			console.log("totalLiTags:"+totalLiTags);
   			console.log("liWidth:"+liWidth);
   			jQuery("#scoreboard .slider ul li").css("float","left");
   			*/
   		}
 	});
}

function moveScoreBoard() {
	jQuery("body").prepend(jQuery("#scoreboard"));
	jQuery("body").prepend(jQuery("#scoreboard-sport-list"));
	positionScoreBoard();
}

function positionScoreBoard() {
	scoreBoardBoxPos = jQuery("#scoreboard-box").position();
	mainHeaderPos = jQuery("#main-header").position();
	newLeft = scoreBoardBoxPos.left + mainHeaderPos.left;
	newTop = scoreBoardBoxPos.top + mainHeaderPos.top;
	sportListTop = newTop + 20;
	sportListLeft = newLeft + 119;
	jQuery("#scoreboard").css("top",newTop+"px").css("left",newLeft+"px");
	jQuery("#scoreboard-sport-list").css("top",sportListTop+"px").css("left",sportListLeft+"px");

	scoreboardLi = jQuery("#scoreboard .slider ul li");
	totalLi = scoreboardLi.length;
	scoreBoardShowTime = totalLi * 100;
	setTimeout("showScoreBoard()",scoreBoardShowTime);
}

function showScoreBoardAjax() {
	jQuery("#scoreboard").animate({height:"79px"},1000);
}

function showScoreBoard() {
	jQuery("#scoreboard").animate({height:"79px",opacity:"1"},1000);
}

/******************************************************************************
	END Scoreboard
******************************************************************************/


