function pophdchat() {
    
    if(typeof(winRef) == 'undefined' || winRef.closed){
        url = 'http://www.hdtrailerz.com/chat';
        winRef=window.open(url,'hdchat',' height=867,width=980,left = '+(screen.availWidth-970)/2+',top = 50, scrollbars=yes');
        if (window.focus) {winRef.focus()}
    } else {
      //give it focus (in case it got burried)
      winRef.focus();
    }

    return false;    

}



//redirect whne movie ends
var player = null;
var t = null;
function playerReady(obj){
    player = window.document[obj.id];
    addListeners();
    console.log('rrrun');
    console.log(obj.id);
    
}
function addListeners() {
    
    if (player) { 
        player.addModelListener("STATE", "stateListener");
    } else {
        setTimeout("addListeners()",500);
    }
}
function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
    currentState = obj.newstate; 
    previousState = obj.oldstate; 

    if ((currentState == "COMPLETED")&&(previousState == "PLAYING")) {
        $('#redirectinfo').css('display', 'block');
        t=setTimeout('document.location.href="http://www.hdtrailerz.com"+$("#similar_1").attr("href")',10000);
    }
    
    if ((currentState == "PLAYING")) {
        $('#redirectinfo').css('display', 'none');
        clearTimeout(t);
    }
}
function stopRedirect(){
    $('#redirectinfo').css('display', 'none');
    clearTimeout(t);    
}


