var numItemsTop = new Array(3);
var curBlock = 0;
var curPos = 0;
var curPosTop = new Array(3);
var curPosStation = 0;
var endPos = 0;
var endPosTop = new Array(3);
var endPosStation = 0;
var tempPosFeat = 82;
var tempPosFeatA = 82;
var tempPosFeatB = 82;
var tempPosTop = new Array(3);
var tempPosStation = 0;
tempPosTop['streaming'] = 0;
tempPosTop['download'] = 0;
tempPosTop['iptv'] = 0;
var busyScrolling = 0;
var featureBlock = 0;

if(document.all) { //ie speed
	var pause = 1;		
	var speed = 3;
} else { //ns speed
	var pause = 0;		
	var speed = 6;
}

function featureListUpOLD() {
	theObj = document.getElementById("featurelist0");
	curPos = theObj.offsetTop;
	if(curPos > ((numItems-2)*-82) && busyScrolling == 0) {
		endPos = (curPos-82);	
		busyScrolling = 1;		
		startBlock = document.getElementById("ftitle"+featureBlock);		
		startBlock.className = '';		
		curBlock++;
		scrollFeatureList();
	}
}

var curPosA = 0;
var curPosB = 0;
var endPosA = 0;
var endPosB = 0;

function featureListUp() {
	//alert('up');
	objA = $('featurelist0');
	objB = $('featurelist1');
	curPosA = Number(objA.offsetTop);
	curPosB = Number(objB.offsetTop);
	endPosA = (curPosA-82);
	endPosB = (curPosB-82);
	totalClicks = (numItems/2);
	AnimListUp();
}

function featureListDown() {
	//alert('down');
	objA = $('featurelist0');
	objB = $('featurelist1');
	curPosA = Number(objA.offsetTop);
	curPosB = Number(objB.offsetTop);
	endPosA = (curPosA+82);
	endPosB = (curPosB+82);
	totalClicks = (numItems/2);
	AnimListDown();
}

var totalClicks = 0;
var curClick = 2;
var toggleAB = 'b';
var animCount = 0;
function AnimListUp() {
	objA = $('featurelist0');
	objB = $('featurelist1');
	
	if((animCount + speed) > 82) {
		objA.style.top = endPosA+'px';
		objB.style.top = endPosB+'px';
		curPosA = endPosA;
		curPosB = endPosB;
		animCount = 82;
	} else {
		curPosA = (curPosA-speed);
		curPosB = (curPosB-speed);
		objA.style.top = curPosA+'px';		
		objB.style.top = curPosB+'px';
		animCount = animCount+speed;		
	}	
	if(animCount == 82) {
		animCount = 0;			
		curClick++;
		if(curClick == totalClicks) {
			if(toggleAB == 'a') {
				objA.style.top = (totalClicks*82)+'px';
				curPosA = Number(objA.offsetTop);
				toggleAB = 'b';
			} else {
				objB.style.top = (totalClicks*82)+'px';
				curPosB = Number(objB.offsetTop);
				toggleAB = 'a';
			}
			curClick = 0;
		} 
	} else {
		 setTimeout(AnimListUp, pause);		
	}
	
}
function AnimListDown() {
	objA = $('featurelist0');
	objB = $('featurelist1');
	
	if((animCount + speed) > 82) {
		objA.style.top = endPosA+'px';
		objB.style.top = endPosB+'px';
		curPosA = endPosA;
		curPosB = endPosB;
		animCount = 82;
	} else {
		curPosA = (curPosA+speed);
		curPosB = (curPosB+speed);
		objA.style.top = curPosA+'px';		
		objB.style.top = curPosB+'px';
		animCount = animCount+speed;		
	}	
	if(animCount == 82) {
		animCount = 0;			
		curClick--;
		if(curClick == totalClicks) {
			if(toggleAB == 'a') {
				objA.style.top = (0-(totalClicks*82))+'px';
				curPosA = Number(objA.offsetTop);
				toggleAB = 'b';
			} else {
				objB.style.top = (0-(totalClicks*82))+'px';
				curPosB = Number(objB.offsetTop);
				toggleAB = 'a';
			}
			curClick = 0;
		} 
	} else {
		 setTimeout(AnimListDown, pause);		
	}
	
}

function featureListDownOLD() {	
	theObj = document.getElementById("featurelist0");
	curPos = theObj.offsetTop;		
	if(curPos < 82 && busyScrolling == 0) {
		endPos = (curPos+82);	
		busyScrolling = 1;		
		startBlock = document.getElementById("ftitle"+featureBlock);		
		startBlock.className = '';	
		scrollFeatureList();
	}
}

var moveToFirst = 0;

function goToFirst() {	
	theObj = document.getElementById("featurelist0");
	curPos = theObj.offsetTop;		
	if(curPos < 82 && busyScrolling == 0) {
		endPos = 82;	
		busyScrolling = 1;		
		startBlock = document.getElementById("ftitle"+featureBlock);		
		startBlock.className = '';	
		moveToFirst = 1;
		scrollFeatureList();
	}
}



function scrollFeatureList() {
	theObj = document.getElementById("featurelist0");
	if(curPos>endPos) { //up
		//alert((tempPosFeat - speed)+"<"+ endPos)
		if((tempPosFeat - speed) < endPos) {
			tempPosFeat = endPos;
		} else {
			tempPosFeat = tempPosFeat - speed;
		}	
		theObj.style.top = tempPosFeat+'px';
		if(tempPosFeat > endPos) {
			timeoutID = window.setTimeout(scrollFeatureList, pause);
		} else {
			busyScrolling = 0;			
			if(moveToFirst == 0){
				endBlock = document.getElementById("ftitle"+(featureBlock+1));
				endBlock.className = 'playing';
				document.getElementById("home_stationtitle").innerHTML = arrStations[(featureBlock+1)][1];
				sendEvent('playitem',(featureBlock+1))
				featureBlock++;
			} else {
				endBlock = document.getElementById("ftitle0");
				endBlock.className = 'playing';
				document.getElementById("home_stationtitle").innerHTML = arrStations[0][1];
				featureBlock = 0;
			}
			//frames['player_home'].location.href= "/video/default.asp?s="+arrStations[(featureBlock+1)][0];
			
		}
	} else { //down
		if((tempPosFeat + speed) > endPos) {
			tempPosFeat = endPos;
		} else {
			tempPosFeat = tempPosFeat + speed;
		}
		theObj.style.top = tempPosFeat+'px';
		if(tempPosFeat < endPos) {
			timeoutID = window.setTimeout(scrollFeatureList, pause);
		} else {
			busyScrolling = 0;			
			if(moveToFirst == 0){
				endBlock = document.getElementById("ftitle"+(featureBlock-1));
				endBlock.className = 'playing';
				document.getElementById("home_stationtitle").innerHTML = arrStations[(featureBlock-1)][1];
				sendEvent('playitem',(featureBlock-1))
				featureBlock--;
			} else {
				endBlock = document.getElementById("ftitle0");
				endBlock.className = 'playing';
				document.getElementById("home_stationtitle").innerHTML = arrStations[0][1];			
				featureBlock = 0;
			}
			moveToFirst = 0;
			//frames['player_home'].location.href = "/video/default.asp?s="+arrStations[(featureBlock-1)][0];
			
		}
	}		
}

function featureListWMVUp() {	
	theObj = document.getElementById("featurelist0");
	curPos = theObj.offsetTop;
	if(curPos > ((numItems-2)*-82) && busyScrolling == 0) {
		endPos = (curPos-82);	
		busyScrolling = 1;		
		startBlock = document.getElementById("ftitle"+featureBlock);		
		startBlock.className = '';		
		curBlock++;
		scrollFeatureListWMV();
	}
}

function featureListWMVDown() {	
	theObj = document.getElementById("featurelist0");
	curPos = theObj.offsetTop;		
	if(curPos < 82 && busyScrolling == 0) {
		endPos = (curPos+82);	
		busyScrolling = 1;		
		startBlock = document.getElementById("ftitle"+featureBlock);		
		startBlock.className = '';	
		scrollFeatureListWMV();
	}
}



function goToFirstWMV() {	
	theObj = document.getElementById("featurelist0");
	curPos = theObj.offsetTop;		
	if(curPos < 82 && busyScrolling == 0) {
		endPos = 82;	
		busyScrolling = 1;		
		startBlock = document.getElementById("ftitle"+featureBlock);		
		startBlock.className = '';	
		moveToFirst = 1;
		scrollFeatureListWMV();
	}
}


function scrollFeatureListWMV() {
	theObj = document.getElementById("featurelist0");
	if(curPos>endPos) { //up
		if((tempPosFeat - speed) < endPos) {
			tempPosFeat = endPos;
		} else {
			tempPosFeat = tempPosFeat - speed;
		}	
		theObj.style.top = tempPosFeat+'px';
		if(tempPosFeat > endPos) {
			timeoutID = window.setTimeout(scrollFeatureListWMV, pause);
		} else {
			busyScrolling = 0;			
			if(moveToFirst == 0){
				try {
					endBlock = document.getElementById("ftitle"+(featureBlock+1));
					endBlock.className = 'playing';				
				} catch (e) {}
				doNext();
				featureBlock++;
				
			} else {
				endBlock = document.getElementById("ftitle0");
				endBlock.className = 'playing';
				featureBlock = 0;
			}
					
		}
	} else { //down
		if((tempPosFeat + speed) > endPos) {
			tempPosFeat = endPos;
		} else {
			tempPosFeat = tempPosFeat + speed;
		}
		theObj.style.top = tempPosFeat+'px';
		if(tempPosFeat < endPos) {
			timeoutID = window.setTimeout(scrollFeatureListWMV, pause);
		} else {
			busyScrolling = 0;			
			if(moveToFirst == 0){
				try {
					endBlock = document.getElementById("ftitle"+(featureBlock-1));
					endBlock.className = 'playing';
				} catch (e) {}
				doPrev();
				featureBlock--;
			} else {
				endBlock = document.getElementById("ftitle0");
				endBlock.className = 'playing';
				featureBlock = 0;
			}
			moveToFirst = 0;
		}
	}		
}
/* home - toplist */

function countDivsinDiv(divChild) {
	children = 0;
	var allArray = document.getElementsByTagName("div");
	for (i=0; i < allArray.length ; i++) {
		if (allArray[i].id.substring(0,divChild.length)==divChild) {
			children++;
		}
	}
	grpName = divChild.substring((divChild.lastIndexOf("_")+1),divChild.length);
	numItemsTop[grpName] = children;
}

var objToScroll = '';
function topListLeft(theObjAddon) {
	objToScroll = theObjAddon;
	theObj = document.getElementById("home_slider_sldcontent_"+theObjAddon);	
	countDivsinDiv("home_slider_item_"+theObjAddon)	
	curPosTop[theObjAddon] = theObj.offsetLeft;
	if(curPosTop[theObjAddon] > ((numItemsTop[theObjAddon]-5)*-105) && busyScrolling == 0) {
		endPosTop[theObjAddon] = (curPosTop[theObjAddon]-105);	
		busyScrolling = 1;		
		scrollTopList();
	}
}

function topListRight(theObjAddon) {		
	objToScroll = theObjAddon;
	theObj = document.getElementById("home_slider_sldcontent_"+theObjAddon);
	countDivsinDiv("home_slider_item_"+theObjAddon)
	curPosTop[theObjAddon] = theObj.offsetLeft;		
	if(curPosTop[theObjAddon] < 0 && busyScrolling == 0) {
		endPosTop[theObjAddon] = (curPosTop[theObjAddon]+105);	
		busyScrolling = 1;		
		scrollTopList();
	}
}

function scrollTopList() {
	theObj = document.getElementById("home_slider_sldcontent_"+objToScroll);
	if(curPosTop[objToScroll]>endPosTop[objToScroll]) { //up
		if((tempPosTop[objToScroll] - speed) < endPosTop[objToScroll]) {
			tempPosTop[objToScroll] = endPosTop[objToScroll];
		} else {
			tempPosTop[objToScroll] = tempPosTop[objToScroll] - speed;
		}	
		theObj.style.left = tempPosTop[objToScroll]+'px';
		if(tempPosTop[objToScroll] > endPosTop[objToScroll]) {
			timeoutID = window.setTimeout(scrollTopList, pause);
		} else {
			busyScrolling = 0;
		}
	} else { //down
		if((tempPosTop[objToScroll] + speed) > endPosTop[objToScroll]) {
			tempPosTop[objToScroll] = endPosTop[objToScroll];
		} else {
			tempPosTop[objToScroll] = tempPosTop[objToScroll] + speed;
		}
		theObj.style.left = tempPosTop[objToScroll]+'px';
		if(tempPosTop[objToScroll] < endPosTop[objToScroll]) {
			timeoutID = window.setTimeout(scrollTopList, pause);
		} else {
			busyScrolling = 0;
		}
	}		
}


function stationListLeft() {
	
	theObj = document.getElementById("station_content");	
	//countDivsinDiv("home_slider_item_"+theObjAddon)	
	curPosStation = theObj.offsetLeft;
	if(curPosStation > ((numItemsStation-2)*-370) && busyScrolling == 0) {
		endPosStation = (curPosStation-370);	
		busyScrolling = 1;		
		scrollStationList();
	}
}

function stationListRight() {		
	
	theObj = document.getElementById("station_content");
	//countDivsinDiv("home_slider_item_"+theObjAddon)
	curPosStation = theObj.offsetLeft;		
	if(curPosStation < 0 && busyScrolling == 0) {
		endPosStation = (curPosStation+370);	
		busyScrolling = 1;		
		scrollStationList();
	}
}

function scrollStationList() {

	theObj = document.getElementById("station_content");
	if(curPosStation>endPosStation) { //up
		if((tempPosStation - speed) < endPosStation) {
			tempPosStation = endPosStation;
		} else {
			tempPosStation = tempPosStation - speed;
		}	
		theObj.style.left = tempPosStation+'px';
		if(tempPosStation > endPosStation) {
			timeoutID = window.setTimeout(scrollStationList, pause);
		} else {
			busyScrolling = 0;
		}
	} else { //down
		if((tempPosStation + speed) > endPosStation) {
			tempPosStation = endPosStation;
		} else {
			tempPosStation = tempPosStation + speed;
		}
		theObj.style.left = tempPosStation+'px';
		if(tempPosStation < endPosStation) {
			timeoutID = window.setTimeout(scrollStationList, pause);
		} else {
			busyScrolling = 0;
		}
	}		
}


function createRequestObject(){
	var request_;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		request_ = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_ = new XMLHttpRequest();
	}
	return request_;
}
var http = createRequestObject();
var isBusy = false;

function getSubCats(){
	theCat = document.getElementById("c")[document.getElementById("c").selectedIndex].value;
	//if(theCat > 0){
		if (isBusy) {
			http.onreadystatechange = function () {}
			http.abort();
		}	
		http.open('get', '/content/ajax/getSubCats.asp?p='+ theCat);
		isBusy = true;
		
		theBox = document.getElementById("sc")
		//keep box width	
		boxWidth = theBox.offsetWidth;
		if(!isNaN(boxWidth)) {
			theBox.style.width = boxWidth+"px";
		}
		
		//clear box
		i=(theBox.length-1);
		while(i>-1) {		
			theBox.options[i] = null;
	    	i--;
		}
		newoption1 = new Option('Loading...','' , false, false);    						 
	    theBox.options[0] = newoption1; 
		http.onreadystatechange = handleSubCats;
		http.send(null);
	//}
}

function handleSubCats(){
	if(http.readyState == 1){
		
	}
	if(http.readyState == 4){
		var response = http.responseText;
		//fill the box with new data
		theBox = document.getElementById("sc");
		numOpts=0;
		//split into arrays
		arrLines = response.split("{n}");
		for(i=0;i<arrLines.length;i++) {
			arrTmp = arrLines[i].split("{#}");
			ChanID = arrTmp[0];
			ChanNM = arrTmp[1];
			ChanNM = decodeURIComponent(ChanNM);
			ChanNM = ChanNM.replace("&#039;","'");
			if(!isNaN(ChanID) && ChanNM!="" && ChanNM!="undefined"){				
				newoption1 = new Option(ChanNM,ChanID , false, false);    						 
    			theBox.options[i+1] = newoption1;
				numOpts++;
			}
		}
		if(numOpts>0) {
			newoption1 = new Option('Choose:','' , false, false);    						 
		} else {
			newoption1 = new Option('All','' , false, false);    						 
		}
	    theBox.options[0] = newoption1;
		 theBox.options[0].selected = true;
		isBusy = false;
	}
}

function getStationSubCats() {
	var randomnumber=Math.floor(Math.random()*11);
	var theCat = document.getElementById("ns_cat")[document.getElementById("ns_cat").selectedIndex].value;
	if(theCat > 0){
		if (isBusy) {
			http.onreadystatechange = function () {}
			http.abort();
		}	
		http.open('get', '/content/ajax/getStationSubCats.asp?p='+ theCat+'&rdm='+randomnumber);
		isBusy = true;
		
		theBox = document.getElementById("ns_subcat")
		//keep box width	
		boxWidth = theBox.offsetWidth;
		if(!isNaN(boxWidth)) {
			theBox.style.width = boxWidth+"px";
		}
		
		//clear box
		i=(theBox.length-1);
		while(i>-1) {		
			theBox.options[i] = null;
	    	i--;
		}
		newoption1 = new Option('Loading...','' , false, false);    						 
	    theBox.options[0] = newoption1; 
		http.onreadystatechange = handleSubCatsSignup;
		http.send(null);
	}
}

function handleSubCatsSignup(){
	if(http.readyState == 1){
		
	}
	if(http.readyState == 4){
		var response = http.responseText;
		//fill the box with new data
		theBox = document.getElementById("ns_subcat");
		numOpts=0;
		//split into arrays
		arrLines = response.split("{n}");
		for(i=0;i<arrLines.length;i++) {
			arrTmp = arrLines[i].split("{#}");
			ChanID = arrTmp[0];
			ChanNM = arrTmp[1];
			ChanNM = decodeURIComponent(ChanNM);
			ChanNM = ChanNM.replace("&#039;","'");
			if(!isNaN(ChanID) && ChanNM!="" && ChanNM!="undefined"){				
				newoption1 = new Option(ChanNM,ChanID , false, false);    						 
    			theBox.options[i+1] = newoption1;
				numOpts++;
			}
		}
		if(numOpts>0) {
			newoption1 = new Option('Choose:','' , false, false);    						 
		} else {
			newoption1 = new Option('All','' , false, false);    						 
		}
	    theBox.options[0] = newoption1;
		 theBox.options[0].selected = true;
		isBusy = false;
	}
}



function getSubCats2(){
	theCat = document.getElementById("c1")[document.getElementById("c1").selectedIndex].value;
	if(theCat > 0){
		if (isBusy) {
			http.onreadystatechange = function () {}
			http.abort();
		}	
		http.open('get', '/content/ajax/getSubCats.asp?p='+ theCat);
		isBusy = true;
		
		theBox = document.getElementById("sc1")
		//keep box width	
		boxWidth = theBox.offsetWidth;
		if(!isNaN(boxWidth)) {
			theBox.style.width = boxWidth+"px";
		}
		
		//clear box
		i=(theBox.length-1);
		while(i>-1) {		
			theBox.options[i] = null;
	    	i--;
		}
		newoption1 = new Option('Loading...','' , false, false);    						 
	    theBox.options[0] = newoption1; 
		http.onreadystatechange = handleSubCats2;
		http.send(null);
	}
}

function handleSubCats2(){
	if(http.readyState == 1){
		
	}
	if(http.readyState == 4){
		var response = http.responseText;
		//fill the box with new data
		theBox = document.getElementById("sc1");
		numOpts=0;
		//split into arrays
		arrLines = response.split("{n}");
		for(i=0;i<arrLines.length;i++) {
			arrTmp = arrLines[i].split("{#}");
			ChanID = arrTmp[0];
			ChanNM = arrTmp[1];
			ChanNM = decodeURIComponent(ChanNM);
			ChanNM = ChanNM.replace("&#039;","'");
			if(!isNaN(ChanID) && ChanNM!="" && ChanNM!="undefined"){				
				newoption1 = new Option(ChanNM,ChanID , false, false);    						 
    			theBox.options[i+1] = newoption1;
				numOpts++;
			}
		}
		if(numOpts>0) {
			newoption1 = new Option('Choose:','' , false, false);    						 
		} else {
			newoption1 = new Option('All','' , false, false);    						 
		}
	    theBox.options[0] = newoption1;
		 theBox.options[0].selected = true;
		isBusy = false;
	}
}



function playProgram(progid) {
	try{sendEvent('stop');}catch(e){}
	loadPlayer('/video/pl.asp?prog='+progid,'true');
	
	var so = new SWFObject("/swf/votesliderSYS2.swf", "vote", "117", "16", "7", "#FFFFFF");
	so.addParam("wmode", "transparent");
	so.addVariable("clipid", progid);
	so.write("player_rating");	
}

function playClipBare(clip) {
	try{sendEvent('stop');}catch(e){}
	loadPlayer('/video/mngmnt_prev_clip.asp?clip='+clip,'true');
}

function playProgramBare(progid) {
	try{sendEvent('stop');}catch(e){}
	loadPlayer('/video/pl.asp?prog='+progid,'true');
}

function waitFor() {
	try{sendEvent('stop');}catch(e){}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}

	return [curleft,curtop];
}

/* functions rely on prototype.js (must be included in a page before this script as well) */
function showToolTip(e,text,group){ 	
	try{
	    $('ToolTip').update("<table><tr><td class=ToolTipTD>"+text+"</td></tr></table>").setStyle({left:(Event.pointerX(e)+15)+'px',top:(Event.pointerY(e)+15)+'px'});	
		$('ToolTip').show();
	} catch(e) {
	}
} 

function hideToolTip(){ 
	$('ToolTip').hide();
} 

function updateSlider(slider,type,sorts) {
	switch(slider) {
		case 'streaming':
			gr=1;
			break;
		case 'download':
			gr=2;
			break;
	}
	theUrl = '/content/ajax/getTopFiles.asp?gr='+gr+'&vw='+type+'&srt='+sorts;
	new Ajax.Request(theUrl,{
		method: 'get',
		onSuccess: function(transport) {	
			$('home_slider_sldcontainer_'+slider).update(transport.responseText)
		}
	});
}


       delClip = function(idm,idu)
        {
        if(confirm('Are you sure you want to delete this clip?'))
        {
         theUrl = '/stationmanager/ajax/deleteClip.asp?id_media='+idm;
	        new Ajax.Request(theUrl,{
		    method: 'get',
		        onSuccess: function(transport) {	
			        alert(transport.responseText);
			        if(transport.responseText == "Clip deleted.")
			        {
			            getForm(0,0,'',2,idu);
			        }
		        }
	        });
	        }
        }
        
        delClip2 = function(idm,idu)
        {
        if(confirm('Are you sure you want to delete this clip?'))
        {
         theUrl = '/stationmanager/ajax/deleteClip.asp?id_media='+idm;
	        new Ajax.Request(theUrl,{
		    method: 'get',
		        onSuccess: function(transport) {	
			        alert(transport.responseText);
			        if(transport.responseText == "Clip deleted.")
			        {
			            getForm(0,0,'',2,idu);
			            document.location.href='/stationmanager/allClips.asp?tab=clips';
			        }
		        }
	        }); 
	        }
        }
        
        editClip = function(idm)
        {
            document.location.href='/stationmanager/editClips.asp?tab=clips&idm='+idm;
        }
        