﻿/*************************************************************************
              Shemaroo Entertainment Pvt. Ltd.          
                Shemaroo TV (Version 1.3)       
                    By Manish Sathe       
              last updated on 7th Oct 2008             
        Copyright (c) 2008 Shemaroo Ent. Pvt. Ltd.      


    WARNING: This software program is protected by copyright      
    law and international treaties. Unauthorized reproduction     
    or distribution of this program, or any portion of it, may    
    result in severe civil and criminal penalties, and will be 
    prosecuted to the maximum extent possible under the law.

***************************************************************************/
var Player_active=false;
var SHEM_TV_AJAX= new AJAX();
var Player_State="";


var defSHEM_TV_top="294";
var defSHEM_TV_left="365";

var SHEM_TV_top=defSHEM_TV_top;
var SHEM_TV_left=defSHEM_TV_left;

var takeDeffPos="YES"

var SHEM_TV_id="";
var SHEMTV_Out;
var SHEM_TV_lastID=0;
var SHEM_TV_pos=0;
var SHEM_TV_resetpos=false;


function ShowTrailer(id,pos)
{
obj=document.getElementById(id)
xtop=obj.offsetTop
xleft=obj.offsetLeft
if(pos=='right')
 {
 xleft=obj.offsetWidth+xleft
 }
if(pos=='left')
 {
 xleft=xleft-335
 }
if(pos=='bottom')
 {
 xtop=xtop+obj.offsetHeight
 }
if(pos=='top')
 {
 xtop=xtop-340
 }
SHEM_TV_top=xtop
SHEM_TV_left=xleft
takeDeffPos="NO"
PlayTV(id);
}



function PlayTV(id)
{
if(takeDeffPos=="YES")
 {
 SHEM_TV_top=defSHEM_TV_top;
 SHEM_TV_left=defSHEM_TV_left;
 }
takeDeffPos="YES"
if(id==""){return;}
if(!Player_State==""){CloseTV();}
try{SHEMTV_Out.close();}catch(err){};
CreatePlayer();
SHEM_TV_id=id;
mplayer=document.getElementById("mPlayer")
mplayer.innerHTML="<img border='0' src='/trailers/ShemarooTV/loading_trailer.jpg' width='163' height='48'>"
SHEM_TV_AJAX.abort();
Player_State="Loading"
SHEM_TV_AJAX.open('get',"/Trailers/ShemarooTV/SHEM_TV_Resp.asp?req=player&id="+id+"&ts"+Date);
SHEM_TV_AJAX.onreadystatechange=MediaArrived;
SHEM_TV_AJAX.send(null);
if(SHEM_TV_lastID!=id){SHEM_TV_pos=0;} 
SHEM_TV_lastID=id;
}

function MediaArrived()
{
if(SHEM_TV_AJAX.readyState != 4)
 {
 mplayer=document.getElementById("mPlayer")
 mplayer.innerHTML="<img border='0' src='/trailers/ShemarooTV/loading_trailer.jpg' width='163' height='48'>"
 }else if(SHEM_TV_AJAX.readyState == 4)
 {
 re=SHEM_TV_AJAX.responseText;
 
 document.getElementById("mPlayer").innerHTML=re;
  try{
   if(SHEM_TV_resetpos==true)
     {
     document.MMP.controls.CurrentPosition=SHEM_TV_pos;
     SHEM_TV_resetpos=false;
     }
  }catch(err)
   {
   }
 if(document.MMP){Player_State="Playing"}
 }
}


function CloseTV()
{

mmpx=document.getElementById("MMP")
mplayer=document.getElementById("mPlayer")
if(document.MMP)
 {
 try{
   document.MMP.controls.stop();
   document.MMP.url="";
   }catch(err){
   }
 }
 mmpx.style.visibility='hidden';
 mp=document.getElementById("mPlayer")
 mp.removeChild(mmpx);
 mplayer.innerHTML="<img border='0' src='/trailers/ShemarooTV/images/loading_trailer.jpg' width='163' height='48'>"
 document.getElementById("T_Box").style.visibility="hidden";
 document.body.removeChild(document.getElementById("T_Box"));
 Player_State="";
 Player_active=false;
}

function HideTV()
{
try{
   document.MMP.controls.stop();
   }catch(err){
   }
 document.MMP.style.visibility='hidden';
 document.getElementById("T_Box").style.visibility="hidden";
}

function PopOut_TV()
{
try{
 SHEM_TV_pos=document.MMP.controls.CurrentPosition;
 }catch(err)
 {
 SHEM_TV_pos=0;
 }
 SHEMTV_Out=window.open("/trailers/ShemarooTV/SHEM_TV_out.asp?id="+SHEM_TV_id+"&pos="+SHEM_TV_pos,"SHEMAROO_OUT_tv","width=335,height=340")
 SHEMTV_Out.focus();
 SHEM_TV_pos=0;
 Player_State="External";
 CloseTV();
}

function PopIn_TV(id,pos)
{
SHEM_TV_resetpos=true;
SHEM_TV_pos=pos
PlayTV(id);
}
/////////Player function//////////////
function PlayerTopMouseOver()
{
document.getElementById("TBox_title").style.cursor='move';
}
function PlayerTopmouseDown()
{
valP=true;
document.getElementById("TBox_title").style.cursor='move';
}
function PlayerTopmouseUp()
{
valP=false;
document.getElementById("TBox_title").style.cursor='';
}

///////////////////////////////////

isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=false;
var valP=false;

function ddInit(e){
if(valP==false){return;};
  topDog=isIE ? "BODY" : "HTML";
  whichDog=isIE ? document.all.T_Box : document.getElementById("T_Box");  
  hotDog=isIE ? event.srcElement : e.target;  
  while (hotDog.id!="TBox_title"&&hotDog.tagName!=topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
  }  
  if (hotDog.id=="TBox_title"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDog.style.left);
    nowY=parseInt(whichDog.style.top);
    ddEnabled=true;
    document.body.onmousemove=dd;
  }
}

function dd(e){
  if (!ddEnabled) return;
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  SHEM_TV_top=whichDog.style.top;
  SHEM_TV_left=whichDog.style.left;
  return false;  
}

function ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

function hideMe(){
  if (isIE||isNN) whichDog.style.visibility="hidden";
  else if (isN4) document.theLayer.visibility="hide";
}

function showMe(){
  if (isIE||isNN) whichDog.style.visibility="visible";
  else if (isN4) document.theLayer.visibility="show";
}


////////////////////////////

function CreatePlayer()
{
if(Player_active==true)
 {
 return;
 }else{
 Player_active=true;
 }
pBox=document.createElement("div");
pBox.className="ShemarooTV";
pBox.id="T_Box";
pBox.style.position="absolute";
pBox.style.top=SHEM_TV_top;
pBox.style.left=SHEM_TV_left;
var xt="<table align='center' width=335 height=340 border=0 cellpadding=0 cellspacing=0><tr><td onmouseover='PlayerTopMouseOver()' onmousedown='PlayerTopmouseDown()' onmouseup='PlayerTopmouseUp()'>"
xt=xt + "<ilayer width='100%' onSelectStart='return false'>"
xt=xt + "<layer width='100%' onMouseover='isHot=true;if (isN4) ddN4(T_Box)' onMouseout='isHot=false'>"
xt=xt + "<img id='TBox_title' src='/trailers/ShemarooTV/Trailer_window_01.jpg' width=255 height=24 alt=></td></layer></ilayer>"
xt=xt + "<td>"
			xt=xt + "<map name='FPMapTV'>"
			xt=xt + "<area title='Close' href='javascript:CloseTV()' shape='rect' coords='61, 5, 76, 18'>"
			xt=xt + "<area alt='Pop Out' href='javascript:PopOut_TV()' shape='rect' coords='44, 3, 57, 15'>"
			xt=xt + "</map>"
			xt=xt + "<img src='/trailers/ShemarooTV/Trailer_window_02.jpg' width='80' height=24 border=0 usemap='#FPMapTV' border=0></td>"

xt=xt + "</tr>"
xt=xt + "<tr>"

		xt=xt + "<td width=335 height=316 align=center colspan=2 id='mPlayer'>"
		xt=xt + "<img border=0 src='/trailers/ShemarooTV/loading_trailer.jpg' width=163 height=48></td>"
	xt=xt + "</tr>"


xt=xt + "</table>"
var nCon=document.createTextNode(xt)

pBox.innerHTML=xt;
document.body.appendChild(pBox); 

document.body.onmousedown=ddInit;
document.body.onmouseup=Function("ddEnabled=false");

return;
}


