/* channel surfer */

function writeHomePageChannelSurfer(playerUrl,width,height) {
	var adcategories = 'show,music,radio,technology,fashion,comedy,fashion,social,mobile,gaming,tv';
	var addescription = 'live streaming shows, backstage, live concerts, socializing';
	var adkeywords = 'chat,chatroom,stream,blog,concert,payperliv,prank,game,friends,feed,social network,concerts,movies,ringtone,student,college,travel,download,school,career';
		   
	var flashVars = "";
	
	var webId = jQuery.cookies.get("login");
	if (webId != null) {
		flashVars = "webId=" + webId;	
	}
	
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" height="'+height+'" width="'+width+'" id="channelSurfer">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write('<param name="allowFullScreen" value="true" />');
	document.write('<param name="movie" value="'+playerUrl+'" />');
	document.write('<param name="wmode" value="transparent">');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#ffffff" />');
	document.write('<param name="loop" value="false" />');
	document.write('<param name="adcategories" value="'+adcategories+'">');
	document.write('<param name="addescription" value="'+addescription+'">');
	document.write('<param name="adkeywords" value="'+adkeywords+'">');
	document.write('<param name="flashVars" value="'+flashVars+'" />');	        						
	document.write('<embed src="'+playerUrl+'&adcategories='+adcategories+'&addescription='+addescription+'&adkeywords='+adkeywords+'" flashVars="'+flashVars+'" ');
	document.write('quality="high" bgcolor="#ffffff" allowScriptAccess="always" allowFullScreen="true" type="application/x-shockwave-flash" wmode="transparent" ');
	document.write('pluginspage="http://www.macromedia.com/go/getflashplayer" height="'+height+'" width="'+width+'" loop="false" id="channelSurfer"/>');
	document.write('</object>');	        
}


/* schedule */

var DAY_IN_MILLIS = 24*60*60*1000;
var HOUR_IN_MILLIS = 60*60*1000;
var MINUTE_IN_MILLIS = 60*1000;

function writeScheduleTime(timeInMillis) {
	var timeHtml = "";
	var now = new Date();
	var timeDifference = timeInMillis - now.getTime();
	if (timeDifference < DAY_IN_MILLIS) {
		var hour = Math.floor(timeDifference / HOUR_IN_MILLIS);
		var minute = Math.floor((timeDifference % HOUR_IN_MILLIS) / MINUTE_IN_MILLIS);
		timeHtml = "Starting in<br><b>";
		if (hour > 1) 
			timeHtml += hour + " Hours<br>";
		else if (hour == 1)
			timeHtml += hour + " Hour<br>";
		if (minute > 1) 
			timeHtml += minute + " Minutes";
		else if (minute < 1)
			timeHtml += "1 Minute<br>";
			
		timeHtml += "</b>";
	} else {
		var startTime = new Date(timeInMillis);
		timeHtml += "<b>" + startTime.formatDate("l") + "<br>" + startTime.formatDate("n/j/y") + "<br>" + startTime.formatDate("g:i A") + "</b>";
	} 
	document.writeln(timeHtml);
}


/* rotating banner */

var banners;
var bannersCount = 0;
var currentBannerIndex = -1;
var bannerTimer;

function homeBannersNext() {
	clearTimeout(bannerTimer);
	var duration = 500;
	currentBannerIndex++;
	if (currentBannerIndex == bannersCount) {
		currentBannerIndex = 0;
		duration = 250 * bannersCount;
	}
	jQuery('#homeBanners').scrollTo(banners[currentBannerIndex],duration,{axis:'x'});
	
	bannerTimer = setTimeout("homeBannersNext()",5000);
}

function homeBannersPrevious() {
	clearTimeout(bannerTimer);
	var duration = 500;
	currentBannerIndex--;
	if (currentBannerIndex == -1) {
		currentBannerIndex = 0;
	}
	
	jQuery('#homeBanners').scrollTo(banners[currentBannerIndex],duration,{axis:'x'});
	
	bannerTimer = setTimeout("homeBannersNext()",5000);
}

function rotateHomeBanners() {
	banners = jQuery(".rotateImgCell");
	bannersCount = banners.length;
	jQuery("#homeBannersBox").css("width",(bannersCount*300)+"px");
	homeBannersNext();
}


function setNetworkBannerTimer(delay) {
	setTimeout("showNetworkBanner()",delay);	
}

var lastRanNum;
function showNetworkBanner() {
	var stickamNetworkBanner = jQuery('#stickamNetworkBanner');
	var networkBanners = jQuery('.hbCell');
	var ranNum = Math.floor(Math.random()*networkBanners.length);
	if (ranNum != lastRanNum)
		lastRanNum = ranNum;
	else
		lastRanNum = (ranNum == 0) ? ranNum + 1 : ranNum - 1;
		
	jQuery(stickamNetworkBanner).fadeOut("slow", function(){jQuery(stickamNetworkBanner).html(jQuery(networkBanners[lastRanNum]).html());
															jQuery(stickamNetworkBanner).fadeIn("slow");
														   });
	setTimeout("showNetworkBanner()",10000);													
}

function flashSubscribe(userId) {
	window.location.href="/member/subscription.do?method=loadLive&userId="+userId;
}
