﻿///
// JScript File
var events=new Array();
var imageList = new Array();
var thumbList = new Array();
var titleList = new Array();
var descripList = new Array();
var linkList = new Array();
var dbIDList = new Array();
var promoPlayer=null;
var rotateTime=5000;
var promoPaused=false;
var Accord = null;
//var detList = new Array();
var vidList = new Array();
//var vidDetList = new Array();
var meadiaBuilt = false;
var curImg;
var nxtImg;
var cshImg;
var currentState=0;
var eventSignature;
var playing = false;
var hideDetailTimer=new Array();

var activeLocation = 2;

function crossFadeObjects(objHide,objShow){
    beginAnimation(fadeElem,0,100,10000,objShow,reset);
    beginAnimation(fadeElem,100,0,10000,objHide,reset);    
}
function animEvent(func,start,end,time,id,targetID,callback){
	this.value=start;	
	this.time=time;
	this.end=end;
	this.start=start;
	this.func=func;
	this.func.value=this.value;
	this.id=id;
	this.targetID=targetID;
	this.step=((start-end)*Math.abs(start-end))/time;
	this.callback=callback;
	this.nextStep=function(){		
		this.value=this.value-this.step;
		this.func.value=this.value;
		if((start<end && this.value<this.end) || (start>end && this.value>this.end)){
			this.func();			
			var funcFire='fireTimeout("' + id + '")'    
            setTimeout(funcFire,1);    			
		}else{
			this.value=this.end;
			this.func.value=this.value;
			this.func();
			this.callback();
			this.cleanup();			
		}
		return false;
	}
	this.cleanup=function(){	    
	    this.value=null;
	    this.time=null;
	    this.end=null;
	    this.start=null;
	    this.func.value=null;
	    this.func=null;	    
	    this.id=null;
	    this.step=null;
	    this.nextStep=null;
	    this.cleanup=null;
	    this.callback=null;
	    cleanEventsArray();
	}	
}
function cleanEventsArray(){
    for(var i=0;i<events.length;i++){
        if(events[i].id==null){            
            events.splice(i,1);
        }
    }
}
function beginAnimation(func,start,end,time,targetID,callback){
	var id=new Date();
	events.push(new animEvent(func,start,end,time,id,targetID,callback));
	events[events.length-1].nextStep();
}
function fireTimeout(id){    
    for(var i=0;i<events.length;i++){
        if(events[i].id==id){
            events[i].nextStep();
        }
    }    
}
function fadeElem(){   
   // alert(this.targetID);      
    setOpacity(this.targetID,this.value)
}
function growElem(){
    tmpHeight=stripPX(document.getElementById(this.targetID).style.height)
    //self.status=tmpHeight;
}
function stripPX(str){
    var string2 = new String(str)
    if(string2.indexOf("PX")>-1){
        string2=string2.substr(0,string2.indexOf("PX")-1);
    }
    return parseInt(string2)
}

function setOpacity(obj,opacity){
    
    var object = document.getElementById(obj).style;     
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")";         
    if(opacity==0){
        object.display="none"
    }else{
        object.display=""
    }
}
function displayImages(){
}
function pausePromo(){    
    var fndIndex;
    for(var i = 0; i<document.getElementById("promo_container").childNodes.length; i++){
        if(this==document.getElementById("promo_container").childNodes[i]){
            fndIndex=i;
            break;
        }
    }
    
    fndIndex=fndIndex-activeLocation;
    
    if(fndIndex>0){
        for(i=fndIndex;i>0;i--){
            sRight();
        }
    }else{
        for(i=fndIndex;i<0;i++){
            sLeft();
        }
    }
}

function getElemIndex(descrip){
    return Right(descrip,descrip.length-4)
}
function promo_jumpToElement(dbid){
    if(scene.status()=="Playing"){
        scene.stopVid();
    }
    if(!promoPaused){
        promoPause();
    }
    
    if(!dbid || isNaN(dbid)){
        
        dbid = this.id.split("_")[2];
    }
    for(var cnt=0;cnt<document.getElementById("promo_container").childNodes.length;cnt++){        
        if(document.getElementById("promo_container").childNodes[activeLocation+1]==document.getElementById("elem_" + dbid)){
            if(!promoPaused){
                promoPause();
            }
            break;
        }
        document.getElementById("promo_container").appendChild(document.getElementById("promo_container").childNodes[0])
    }    
    loadImage();    
}

function changeLocation(index){    
    if(!promoPaused){
        promoPause();
    }
    for(var cnt=0;cnt<document.getElementById("promo_container").childNodes.length;cnt++){
        if(document.getElementById("promo_container").childNodes[1]==document.getElementById("elem" + index)){
            break;
        }
        document.getElementById("promo_container").appendChild(document.getElementById("promo_container").childNodes[0])
    }
    loadImage();
}

function sLeft(){    
    if(!promoPaused){
        promoPause();
    }
    try{    
        if(scene.status()=="Playing"){
            scene.stopVid();
        }
    }catch(e){}
    loadImageLeft();
    //promoPlayer=setInterval("countDown()",1000);
}
function countDown(){
    var divCountdown = document.getElementById("promo_countDown");
    var divCountDownLabel = document.getElementById("promo_countDown_label");
    var divPauseLabel= document.getElementById("promo_paused");
    
    if(!promoPaused){
        divPauseLabel.innerHTML = "";
        divPauseLabel.style.backgroundImage="";
        if(divCountdown.style.width==""){
            divCountdown.style.width="165px";
        }
        if(divCountdown.style.width=="0px"){
            
            loadImage();
            divCountdown.style.width="165px";
            divCountDownLabel.innerHTML="";
        }else{
            //divCountDownLabel.innerHTML="Click to Pause";
            
            divCountdown.style.width=stripPX(divCountdown.style.width)-33 + "px";
            if(stripPX(divCountdown.style.width)==0){
                divCountDownLabel.innerHTML="Loading Next Media...";
            }else{
                divCountDownLabel.innerHTML="";
            }
        }
    }else{
        divPauseLabel.innerHTML = "Paused<br>Click to continue slideshow.";
        //background-image:url(/_graphics/promoplayer/transparent.png);
        divPauseLabel.style.backgroundImage="url(/_graphics/promoplayer/transparent.png)";
        divCountdown.style.width="165px";
    }
    divCountdown = null;
    divCountDownLabel = null;
}
function resetTimer(){
    
}
function promoPause(){
    promoPaused=!promoPaused;
    if (!promoPaused && (scene.status() == "Playing" || getPlayerState()!=-1)) {
        hideVideo();        
        stopVideo();        
    }
}
function sRight(){
    if(!promoPaused){
        promoPause();
    }
    try{
        if (scene.status() == "Playing" || getPlayerState() != -1) {
            hideVideo();
            stopVideo();
        }
    }catch(e){}
    loadImage();
    //promoPlayer=setInterval("countDown()",1000);
}
function newImage(url){
    imageList.push(url);
}
function newImage(img,thumbnail,title,descrip,video,link,dbID){
    var newElem = document.getElementById("elem_" + dbID)
    if(!newElem){
        imageList.push(img);
        thumbList.push(thumbnail);
        try {
            document.getElementById("promoitemcount").innerHTML = thumbList.length
        } catch (e) { }
        
        titleList.push(title);
        descripList.push(descrip.replace("\n","<br>"));
        vidList.push(video);
        linkList.push(link);
        dbIDList.push(dbID);    
        var container = document.getElementById("promo_container");
        newElem=document.createElement("div");
        newElem.id="elem_" + dbID;
        newElem.className="promo_box_short";
        newElem.onclick=pausePromo;
        newElem.style.backgroundImage="url(" + thumbnail + ")";
        container.appendChild(newElem);
        container=null;
    }
    newElem=null;
}
function playVideo(indx) {
    if(!promoPaused){
        promoPause();
    }
    promoPlayer = -1;  
    var player ;
    if(-1!= navigator.userAgent.indexOf("MSIE")){
        player= document.getElementById("promo_player_container")
    }else{
        player= document.getElementById("promo_player_container")
    }

    var nxtID
    if (!indx) {
        nxtID = getArrayIDForDBID(nxtImg.split("_")[1]);
    } else {
        nxtID = indx-1
    }
    if (vidList[nxtID] != "") {
        if (vidList[nxtID].substr(0, 3) != "yt:") {
            player.style.visibility = "visible";
            player.style.display = "";
            document.getElementById("playerDetails").style.visibility = "hidden";
        } else {
            document.getElementById("youtubePlayerVideo").style.visibility = "visible";
            document.getElementById("playerDetails").style.visibility = "visible";
            player.style.display = "none";
        } 
    }
    try{
    if(scene.status!="Playing")
    {   
        startVideo();
    }
    }catch(e){alert(e.message);};
    player=null;  
    if(!promoPaused){
        promoPause();
    }
}
function hideVideo(){
    var player 
    if(-1!= navigator.userAgent.indexOf("MSIE")){
        player= document.getElementById("promo_player_container")
    }else{
        player= document.getElementById("promo_player_container")
    }
    player.style.visibility = "hidden";
    document.getElementById("youtubePlayerVideo").style.visibility = "hidden";
    document.getElementById("playerDetails").style.visibility = "hidden";
    clearVideo();
    player=null;
}
function raiseVideoEnded(){
    hideVideo();
}
function switchVidDetail(){
//    var container = document.getElementById("promo_player_det");
//    container.childNodes[0].className="promo_vid_box"
//    container.appendChild(container.childNodes[0])
    
}
function startVideo(){
    var player 
    if(-1!= navigator.userAgent.indexOf("MSIE")){
        player= scene;
    }else{
        player= scene;
    }
   
    enableVideo()
    try {
        if (scene.getVideoSource() != "") {
            scene.playVid();
        } else {
        player();
        }
    }catch(e){
    //setTimeout("startVideo()",1000);
    }
    player=null;
}
function stopVideo(){
    var player 
    if(-1!= navigator.userAgent.indexOf("MSIE")){
        player= scene
    }else{
        player= scene
    }
    try{
    player.stopVid(); 
    }catch(e){
    //setTimeout("stopVideo()",1000);
    }

    try {
        stop()
        clearVideo()
    } catch (e) {
    }
    player=null;
}
//function playVideo(){    
//    var player = document.getElementById("promo_player")
//    if(!playing)
//    {           
//        player.URL=vidList[currentVideo];   
//        player.controls.play(); 
//        currentVideo+=1;
//        self.status+=currentVideo;
//        if(currentVideo==vidList.length){
//            currentVideo=0;
//        }
//    }
//    player=null;        
//}

function loadImage(id){
    if(scene.status()!="Playing"){
        var currentImage;
        var currentVideo;
        var nextImage;
        currentImage=document.getElementById("promo_container").childNodes[activeLocation];  
        if(!currentImage){
        currentImage=document.getElementById("promo_container").childNodes[activeLocation-1];
        }
        if(!currentImage){
        currentImage=document.getElementById("promo_container").childNodes[activeLocation-2];
        }             
        curImg=currentImage.id
        nextImage=currentImage.nextSibling;
        if(!nextImage){
            nextImage=document.getElementById("promo_container").childNodes[0];
        }        
        nxtImg = nextImage.id
        cacheImage=nextImage.nextSibling;
        if(!cacheImage){
            cacheImage = document.getElementById("promo_container").childNodes[0];
        }        
        cshImg = cacheImage.id
        document.getElementById("promo_container").appendChild(document.getElementById("promo_container").childNodes[0])
        loadMedia();
        
        currentImage=null;
        currentVideo=null;
        nextImage=null;       
    }
}
function loadImageLeft(id){
    if(scene.status()!="Playing"){
        var currentImage;
        var currentVideo;
        var nextImage;
        currentImage=document.getElementById("promo_container").childNodes[activeLocation];  
        if(!currentImage){
        currentImage=document.getElementById("promo_container").childNodes[activeLocation-1];
        }
        if(!currentImage){
        currentImage=document.getElementById("promo_container").childNodes[activeLocation-2];
        }    
        curImg=currentImage.id         
        nextImage=currentImage.previousSibling;
        if(!nextImage){
            nextImage=document.getElementById("promo_container").childNodes[document.getElementById("promo_container").childNodes.length-1];
        } 
        nxtImg = nextImage.id       
        cacheImage=nextImage.previousSibling;
        if(!cacheImage){
            cacheImage = document.getElementById("promo_container").childNodes[document.getElementById("promo_container").childNodes.length-1];
        }       
        cshImg = cacheImage.id
        document.getElementById("promo_container").insertBefore(document.getElementById("promo_container").childNodes[document.getElementById("promo_container").childNodes.length-1],document.getElementById("promo_container").childNodes[0])
        loadMedia();
        
        currentImage=null;
        currentVideo=null;
        nextImage=null;
    }
}
function loadMedia(){
        
        var curID = getArrayIDForDBID(curImg.split("_")[1]);
        var nxtID = getArrayIDForDBID(nxtImg.split("_")[1]);
        var cshID = getArrayIDForDBID(cshImg.split("_")[1]);
        
        hideVideo();
        stopVideo();
        document.getElementById("promo_cache").style.backgroundImage="url(" + imageList[cshID] + ")";
        setOpacity("promo_image1",100);
        setOpacity("promo_image2",0);
        document.getElementById("promo_image2").style.backgroundImage="url(" + imageList[nxtID] + ")"; 
        crossFadeObjects("promo_image1","promo_image2");
        try {
            document.getElementById("promoitemindex").innerHTML = nxtID + 1;
        } catch (e) { }
        if(linkList[nxtID]==""){
            document.getElementById("promo_web_link").style.display="none";         
        }else{
            document.getElementById("promo_web_link").style.display="";
            document.getElementById("promo_web_link").href=linkList[nxtID];
        }
        document.getElementById("promo_show_details").style.display="";
        document.getElementById("detailHeading").innerHTML = titleList[nxtID]
        if(document.getElementById("promo_show_details").style.height!="29px"){
            hideDetails();
        }
        if (descripList[nxtID] != "") {
            //var elem2 = document.createElement("div")            
            //elem2.innerHTML="<br>"    + descripList[nxtID]
            document.getElementById("detailData").innerHTML = "<BR/>" + descripList[nxtID]//.appendChild(elem2);
            //elem2=null;
        } else {
        document.getElementById("detailData").innerHTML = "" //.appendChild(elem2);
        }
        if(vidList[nxtID]==""){
            document.getElementById("promo_play_vid").style.display = "none";
            if (linkList[nxtID] == "") {
                document.getElementById("promo_image1").href = "";
            } else {
                document.getElementById("promo_image1").href = linkList[nxtID];
            } 
            
        }else{
            document.getElementById("promo_play_vid").style.display = "";
            document.getElementById("promo_image1").href = "javascript:playVideo();"            
        }
}
function enableVideo() {

    var nxtID 
    if(!nxtImg){
        nxtID=0
    }else{
        nxtID= getArrayIDForDBID(nxtImg.split("_")[1]);
    }
    //alert(nxtID);
    scene.setVideoSource("");
    //try {
        if (vidList[nxtID].substr(0, 3) == "yt:") {
            //clearVideo();
            //alert(vidList[nxtID].split(":")[1]);
            setYouTube();
            //alert(vidList[nxtID].split(":")[1]);
            
            
            
        } else {
            try {
                scene.setBgImage(imageList[nxtID]);
            } catch (e) { }
            scene.setVideoSource(vidList[nxtID]);
            var vid = new String(vidList[nxtID]);
            if (vid.indexOf(".wmv") > 0 || vid.indexOf(".wma") > 0) {
                scene.setPauseStop(true);
            } else {
                scene.setPauseStop(false);
            }
        }
    //} catch (e) { }

    }
    function setYouTube() {
        if (ytplayer) {
            var nxtID
            if (!nxtImg) {
                nxtID = 0
            } else {
                nxtID = getArrayIDForDBID(nxtImg.split("_")[1]);
            }
            loadNewVideo(vidList[nxtID].split(":")[1], 0);
            setVolume(100);
            play();
        } else {
            setTimeout("setYouTube()", 1000);
        }
    }
//function loadImage(id){
//    if(scene.status()!="Playing"){
//    if(document.getElementById("promo_container").childNodes[0].style.display=="none"){
//        skipLocation();
//    }else{
//    nextImage=id
//    var cacheImage=0;
//    if(!nextImage){
//     nextImage=currentImage+1;     
//    }
//    
//    if(nextImage==imageList.length){
//        nextImage=0;        
//    }
//    cacheImage=nextImage+1;    
//    if(cacheImage>imageList.length){
//        cacheImage=0;
//    }
//    //self.status+=nextImage +"|"
//    document.getElementById("promo_cache").style.backgroundImage="url(" + imageList[cacheImage] + ")"; 
//    
//    document.getElementById("promo_container").appendChild(document.getElementById("promo_container").childNodes[0])
//    if(!imageList[nextImage]){
//        var fireStr="loadImage(" + id + ")";
//        setTimeout(fireStr,100);
//    }else{        
//        setOpacity("promo_image1",100);
//        setOpacity("promo_image2",0);
//        document.getElementById("promo_image2").style.backgroundImage="url(" + imageList[nextImage] + ")";        
//        
//        crossFadeObjects("promo_image1","promo_image2");    
//        
//        if(linkList[nextImage]==""){
//            document.getElementById("promo_web_link").style.display="none";            
//        }else{
//            document.getElementById("promo_web_link").style.display="";
//            document.getElementById("promo_web_link").href=linkList[nextImage];
//        }
//        document.getElementById("promo_show_details").style.display="";
//        document.getElementById("promo_show_details").innerHTML=titleList[nextImage] 
//        if(document.getElementById("promo_show_details").style.height!="29px"){
//            showDetails();
//        }
//       if(descripList[nextImage]!=""){           
//            var elem2 = document.createElement("div")            
//            elem2.innerHTML="<br>"    + descripList[nextImage]
//            document.getElementById("promo_show_details").appendChild(elem2);
//            elem2=null;            
//        }
//        
//        hideVideo();
//        stopVideo();
//        if(vidList[nextImage]==""){
//            document.getElementById("promo_play_vid").style.display="none";
//        }else{
//           document.getElementById("promo_play_vid").style.display=""; 
//           try{
//           
//           scene.setBgImage(imageList[nextImage]);          
//           scene.setVideoSource(vidList[nextImage]);            
//           var vid = new String(vidList[nextImage]);   
//           if(vid.indexOf(".wmv")>0){
//            scene.setPauseStop(true);
//           }else{            
//            scene.setPauseStop(false);
//           }
//           }catch(e){}   
//        }
//        currentImage=nextImage;
//    }
//    }
//    }
//}

//function loadImageLeft(id){
//    if(scene.status()!="Playing"){
//    nextImage=id
//    var cacheImage=0;
//    if(!nextImage){
//     nextImage=currentImage-1;     
//    }
//    
//    if(nextImage==-1){
//        nextImage=imageList.length-1;        
//    }
//    cacheImage=nextImage-1;
//    if(cacheImage==-1){
//        cacheImage=imageList.length-1;
//    }    
//    self.status+=nextImage +"|"
//    document.getElementById("promo_cache").style.backgroundImage="url(" + imageList[cacheImage] + ")"; 
//    
//    document.getElementById("promo_container").insertBefore(document.getElementById("promo_container").childNodes[imageList.length-1],document.getElementById("promo_container").childNodes[0])
//    if(!imageList[nextImage]){
//        var fireStr="loadImage(" + id + ")";
//        setTimeout(fireStr,100);
//    }else{        
//        setOpacity("promo_image1",100);
//        setOpacity("promo_image2",0);
//        document.getElementById("promo_image2").style.backgroundImage="url(" + imageList[nextImage] + ")";        
//        
//        crossFadeObjects("promo_image1","promo_image2");    
//        
//        if(linkList[nextImage]==""){
//            document.getElementById("promo_web_link").style.display="none";            
//        }else{
//            document.getElementById("promo_web_link").style.display="";
//            document.getElementById("promo_web_link").href=linkList[nextImage];
//        }
//        document.getElementById("promo_show_details").style.display="";
//        document.getElementById("promo_show_details").innerHTML=titleList[nextImage] 
//        if(document.getElementById("promo_show_details").style.height!="29px"){
//            alert(document.getElementById("promo_show_details").style.height);
//            showDetails();
//        }
//        if(descripList[nextImage]!=""){           
//            var elem2 = document.createElement("div")            
//            elem2.innerHTML="<br>"    + descripList[nextImage]
//            document.getElementById("promo_show_details").appendChild(elem2);
//            elem2=null;            
//        }
//        hideVideo();
//        stopVideo();
//        if(vidList[nextImage]==""){
//            document.getElementById("promo_play_vid").style.display="none";
//        }else{
//           document.getElementById("promo_play_vid").style.display="";           
//           try{
//           
//           scene.setBgImage(imageList[nextImage]);
//           scene.setVideoSource(vidList[nextImage]); 
//           var vid = new String(vidList[nextImage]);   
//           if(vid.indexOf(".wmv")>0){
//            scene.setPauseStop(true);
//           }else{            
//            scene.setPauseStop(false);
//           }
//           }catch(e){}          
//           
//        }
//        currentImage=nextImage;
//    }
//    }
//}
function donegrow(){
}

function showDetails(switchText){
   document.getElementById("promo_show_details").style.overflow = "hidden";
   for (var i = 0; i < hideDetailTimer.length; i++) {
        clearTimeout(hideDetailTimer.pop());
    }
    //self.status = hideDetailTimer.length;
    if(promoPlayer!=-1){
        if(!promoPaused){
            promoPause();
        }
    }
    document.getElementById("promo_show_details").style.height="195px";
    document.getElementById("promo_show_details").style.top = "175px";
    if (document.getElementById("detailHeading").offsetHeight) {
        document.getElementById("detailData").style.height = 195-document.getElementById("detailHeading").offsetHeight + "px";
    } else {
        document.getElementById("detailData").style.height = "159px";
    }
    try{
        
    document.getElementById(switchText).innerHTML="(Mouse out to Hide Details)";
    }catch(e){}
    
}
function slowHide(switchText) {
    if (hideDetailTimer.length > 0) {
        clearTimeout(hideDetailTimer.pop())
    }
    var str = "hideDetails('" + switchText + "');"
    hideDetailTimer.push(setTimeout(str, 1000));
}
function hideDetails(switchText) {
    if (promoPlayer == -1) {
        promoPlayer = setInterval("countDown()", 1000);
    }
    document.getElementById("promo_show_details").style.height = "29px";
    document.getElementById("promo_show_details").style.top = "344px";
    document.getElementById("detailData").style.height = "0px";
    
    try {
        document.getElementById(switchText).innerHTML = "(Mouse over to Show Details)";
    } catch (e) { }
    if (hideDetailTimer.length > 0) {

        for (var i = 0; i < hideDetailTimer.length; i++) {
            clearTimeout(hideDetailTimer.pop());
        }
       // self.status = hideDetailTimer.length;
        //hideDetailTimer = new Array();
    }
}
function reset(){    
    document.getElementById("promo_image1").style.backgroundImage=document.getElementById("promo_image2").style.backgroundImage
    setOpacity("promo_image1",100);
    setOpacity("promo_image2",0);
    setOpacity("promo_cache",0);
}
function Right(str, n)
{
      if (n <= 0)
          return "";
      else if (n > String(str).length)
          return str;
      else
   {
          var iLen = String(str).length;
          return String(str).substring(iLen, iLen - n);
      }
}
function filterContent(){    
// try{
        if(scene.status()=="Playing"){
            scene.stopVid();
        }
        var filterContainer=document.getElementById(this.id + "-content");
        var promoControl = document.getElementById("promo_container");
        var tempHolder = document.getElementById("holdFiltered");
        var nElemID                
        for(var c=promoControl.childNodes.length-1; c >-1 ; c--){        
            tempHolder.appendChild(promoControl.childNodes[c])        
        }     
        
        for(var i=0; i < filterContainer.childNodes.length; i++){  
            try{
                var tmpElemID =filterContainer.childNodes[i].id;                
                tmpElemID = tmpElemID.split("_")[2];
                nElemID ="elem_" + tmpElemID;        
                if(nElemID!=0){
                    promoControl.appendChild(document.getElementById(nElemID));
                }
            }catch(e){}
            setWidth();
        }
        
        loadImage();       
        try{
        syncChannelDD(parseInt(this.id.split("_")[1]))
        }catch(e){}
        
  //}catch(e){}
}
function getArrayIDForDBID(dbID){
    var retElemID = -1
    for(var i=0;i<dbIDList.length;i++){
        if(dbIDList[i]==dbID){
            retElemID = i;
            break;
        }
    }
    return retElemID;
}
function setWidth(){
    var maxWidth=675;
    var buttonWidth=135;
    var promoContainer = document.getElementById("promo_container");
    var promoBorder = document.getElementById("promo_border");
    switch(promoContainer.childNodes.length){
        case 3:
            promoContainer.style.width= 135*3 + "px";
            promoContainer.style.marginLeft =135+ "px";
            promoContainer.style.marginRight =135+ "px";
            activeLocation=1;
        break;
        case 2:
            promoContainer.style.width= 135*3 + "px";
            promoContainer.style.marginLeft =135+ "px";
            promoContainer.style.marginRight =135+ "px";
            activeLocation=1;
            //promoBorder.style.left =(675-(135))/2+ "px";
        break;
        case 1:
            promoContainer.style.width= 135 + "px";
            promoContainer.style.marginLeft =2*135+ "px";
            promoContainer.style.marginRight =2*135+ "px";
            activeLocation=0;
            //promoBorder.style.left =(675-(135))/2+ "px";
        break;
        default:
            promoContainer.style.width= 675 + "px";            
            promoContainer.style.marginLeft =0+ "px";
            promoContainer.style.marginRight =0+ "px";
            activeLocation=2;
            //promoBorder.style.left =0 + "px";
        break;
    }
    
}
function collapseAccordion(){ 
    setTimeout("accordionCollapseAction();",500);
}
function accordionCollapseAction(){
   var acc = $find('acChannels_AccordionExtender');
    acc.set_SelectedIndex(-1);
}
function buildMedia() {    
    var mPage
    if (typeof(messagingPage)=='undefined') {
        var mPage = document.URL
        var segments = mPage.split("/")
        var len = 0;
        for (var i = 0; i < 3; i++) {
            len += segments[i].length
        }
        mPage = mPage.substr(len + 2);
        if (mPage.indexOf("?") > 0) {
            mPage = mPage.split("?")[0];
        }
        if (mPage.substr(mPage.length - 1, 1) == "/") {
            mPage+="default.aspx"
        }
    }else{
        mPage = messagingPage;
    }
    
    var flestr="getMedia('" + mPage + "')"
    setTimeout(flestr, 500);
    meadiaBuilt = true;
}
function getMedia(mPage) {
    QPlayer.Media.Gather(mPage, buildMediaChanger, OnMediaFailed);
}
function OnMediaFailed(error, userContext, methodName){
    alert(error.get_message() + "\n" + userContext + "\n" + methodName);
}
function buildMediaChanger(result, userContext, methodName) {   

    var firstID = ""
    for(var i=0; i<result.length;i++){   
        if(i==0){
            firstID = "channel_" + result[0].channelID + "-header";
        }
        if (document.getElementById("mediaChanger")) {
            addAccordionChannel(result[i].channelID, "mediaChanger", result[i].title);
            addMediaElem(result[i].channelID, result[i].mediaId, result[i].mediaTitle);
            newImage(result[i].imagePath, makeThumbnailURL(result[i].imagePath), '<b>' + result[i].mediaTitle + '</b><br>' + result[i].mediaSubTitle, result[i].mediaDescription, result[i].videoPath, result[i].link, result[i].mediaId);
        } else {
            vidList.push(result[i].videoPath)               
        }
    }    
    try {
        new Accordian('mediaChanger', 5, 'header_standard');
        setWidth();
        loadImage();
        promoPlayer = setInterval('countDown();', 1000);
        setTimeout("document.getElementById('" + firstID + "').onclick()", 10);
    } catch (e) {if (vidList.length > 0) { playVideo(1); } }
}
function makeThumbnailURL(str){
    var retSTR = new String(str);
    retSTR=retSTR.substr(0,retSTR.lastIndexOf("/")) + "/thumbnails/" + retSTR.substr(retSTR.lastIndexOf("/")+1,retSTR.length-(retSTR.lastIndexOf("/")+1));
    return retSTR    
}
function addAccordionChannel(chID,trgtID,chTitle){    
    var target = document.getElementById(trgtID);
    var newChannel = document.getElementById("channel_" + chID + "-header");
    
    if(!newChannel){
        var newIDContain = document.createElement("channel_" + chID);
        newChannel = document.createElement("div");
        newChannel.id = "channel_" + chID + "-header";
        newIDContain.id="channel_" + chID ;
        newIDContain.className = "accordion_label";
        newChannel.innerHTML = chTitle;
        newChannel.className="accordion_headings header_highlight";
        newIDContain.onclick=filterContent;
        var newChannelContent = document.createElement("div");
        newChannelContent.id="channel_" + chID + "-content";
        newChannelContent.className="channelContent";
        newIDContain.appendChild(newChannel);
        target.appendChild(newIDContain);
        target.appendChild(newChannelContent);
        newChannelContent=null;
    }
    target = null;
    newChannel = null;
}
function addMediaElem(chID,mID,mediaTitle){
    var target = document.getElementById("channel_" + chID + "-content");
    var newMedia = document.getElementById("channel_"+ chID + "_" + mID);
    if(!newMedia){
        newMedia = document.createElement("a");
        newMedia.id = "channel_"+ chID + "_" + mID;
        newMedia.onclick = promo_jumpToElement;
        newMedia.innerHTML=mediaTitle;
        newMedia.className="contentMedia";
        target.appendChild(newMedia);
    }
    target = null;
    newMedia=null;
}



