var focusMediaId;
var timeoutId;
var capCount = 1;

function ItemMouseOver(element,mediaId)
{
  element.style.backgroundColor='#2a2a2a';
  element.style.border = "1px solid #ff0000"; 
  RotateThumbs(mediaId);
}

function ItemMouseOut(element)
{
   element.style.backgroundColor='#1a1a1a';
   element.style.border = "1px solid #999999"; 
   StopThumbRotate();
}

//10 thumbs exist with each video
function RotateThumbs(mediaId)
{
    focusMediaId = mediaId;
    var img = document.getElementById("THUMB_" + focusMediaId);
    
    if (capCount >= 9)
       capCount = 1;
    else
       capCount++;
        
      //  alert("rotatethumbs");
        
    img.src = "Data/videos/" + focusMediaId + "/" +  focusMediaId + "_" + capCount + ".jpg";
    
   timeoutId =  setTimeout("RotateThumbs(" +  focusMediaId +   ")",500)  
    
} 

function StopThumbRotate()
{
    capCount = 1;
    clearTimeout ( timeoutId );
    var img = document.getElementById("THUMB_" + focusMediaId);
     img.src = "Data/videos/" + focusMediaId + "/" +  focusMediaId + "_" + capCount + ".jpg";
}



/////////////////////////////////////////////BEGIN PAGEBAR FUNCTIONS////////////////////////////////////////


//execute hidden buttons click event, 
//pagerId refers to the pager on the screen, 
//pagePos refers to the new page position
function pageItem(filter,pagePos,sort)
{
    
    var btn = document.getElementById('btnAjax'); //Hidden button to execute
    var hd = document.getElementById('hfData'); //Hidden field to hold postback data
    //Set the value of the hidden fields used to hold the data

    //alert(hd.Value);
    hd.value = filter + "," + pagePos + "," + sort;

    //click button to fire postback
    if (btn) btn.click();

}




//////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////BEGIN RATING FUNCTIONS////////////////////////////////////////

 var picArray = new Array();
 var beenRated = false;


function rateOver(pos)
{
    if  (picArray.length == 0)
        SetExisting();
        
  if(!beenRated)
    {
  for (i=1;i< pos +1;i++)
  {
    var img = document.getElementById("sb" + i);
        img.src = "i/redStarbh1.gif";
  }
      
  for(i=pos+1;i < 6;i++)
  {
    var img = document.getElementById("sb" + i);
        img.src = "i/redStarbh0.gif";
  }

    //show rating text
    var txt = document.getElementById("rateText");
        
    switch(pos)
    {
        case 1:
            txt.innerHTML = "Bad";
            break;
        case 2:
            txt.innerHTML = "Watchable";
            break;
        case 3:
            txt.innerHTML = "Good";
            break;
        case 4:
            txt.innerHTML = "Quality Porn";
            break;
        case 5:
            txt.innerHTML = "Totally Awesome";
            break;
    }    
 }
    


}

//set rate back to old
function rateOut(pos)
{
 //alert("picarrayLen=" + picArray.length);
 if(!beenRated)
    document.getElementById("rateText").innerHTML = "Rate this Video";
 
  for(i=0;i < picArray.length;i++)
  {
     var img = document.getElementById("sb" + (i + 1));
        img.src = picArray[i];
  }

}

//call server side ajax function
function RateIt(rate,mediaId)
{
    if(!beenRated)
    {
        beenRated = true;
        document.getElementById("rateText").innerHTML = "Thank you for Rating!";
    
        RateVideo(rate,mediaId);
    
        rateOut(1);
    }
        
}

function SetExisting()
{
     for(i=1;i<6;i++)
       {
         var img = document.getElementById("sb" + i);
         picArray.push(img.src);
        }

}






//////////////////////////////////////////////////////////////////////////////////////////////////////


//Standard Error Out message box
function OnCallError(error,userContext,methodName)
{
    if(error !== null){
     //    txtresult.innerHTML = "Cannot Details on this video, try refreshing this page";
        alert(error.get_message());
        }
 }
 
 
 //Pause Video
function RateVideo(rate,mediaId)
{
  var txtresult =  document.getElementById('spanRatings');
  PageMethods.RateVideo(rate,mediaId,OnRateVideoComplete,OnCallError,txtresult);

}

function OnRateVideoComplete(result,txtresult,methodName){
	 txtresult.innerHTML = result;
	
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////

function closeProf()
{
    document.getElementById('divLink').style.visibility = "hidden";
    
    document.getElementById('player').style.visibility = "visible";
    
}

function ShowLink()
{
    document.getElementById('divLink').style.visibility = "visible";
 
    document.getElementById('txtLinkVideo').value =  "http://www.xred2.com/watch.aspx?id="+ mediaId;
 
    document.getElementById('txtEmbedVideo').value = "<embed src='http://www.xred2.com/XRedPlayer.swf' quality='high' bgcolor='#000000'  width='600' " +                                                       " height='470' flashvars='vid=" +  mediaId  + "&sl=true&play=false' " +                                                      " name='Player' align='middle' allowScriptAccess='sameDomain' allowFullScreen='true'type='application/x-shockwave-flash' " +                                                     " pluginspage='http://www.macromedia.com/go/getflashplayer' />";
  
    //hide player - fucking flash won't go under a div 
    document.getElementById('player').style.visibility = "hidden";

}

//////////////////////////////////////////////BEGIN TEXT SELECTION FUNCTIONS///////////////////////////////////////
//Selects text in an text area, call on the onclick etc
function selectText(id)
{  var text =  document.getElementById(id);
    text.focus();
    text.select();
}
//Copy to clipboard function IE only
function ClipBoard(id) 
{   var text =  document.getElementById(id);
    Copied =  text.createTextRange();
    Copied.execCommand("Copy");
}
/////////////////////////////////////////////END TEXT SELECTIONS FUNCTIONS//////////////////////////////////
//<td width=45% align=center id=countdown><script type="text/javascript">countdown(1740);</script></td>

function countdown(sec)
  {
    var min="";
    var n_sec="";
    var tmp_res;
    if (sec<1) 
    {
      document.getElementById('countdown').innerHTML="<a href='/'>check out the new videos !</a>";
    } 
    else
    {
      if (sec>60) { tmp_res=sec%60; min=((sec-tmp_res)/60)+"min"; n_sec=tmp_res+"s"; }
      else n_sec=sec+"s";
      document.getElementById('countdown').innerHTML="new videos in "+min+" "+n_sec;
      setTimeout("countdown("+(sec-1)+")",1000);
    }
  }



function AddToBag(docId){ 


if (getCookie("FAV") == null){ 
    setCookie("FAV",docId,9000);
    }else{ 
if (getBagCount() < 100){ 

    var cVal = getCookie("FAV"); 
      setCookie("FAV",(cVal.length > 0 ? docId + "," + cVal  :  docId),9000); 
     ShowBagCount(); ShowAddedText(docId); 
    
   }else { alert('You have two many items in your WatchList please remove some');}  } }