

//resize the window to the size of this popup
function resizeWin(pheight,pwidth,winobj,smooth) {

    //adapt the height for the toggle bar if it exists.
    var frameDoc = (document.location.href.indexOf('uberpop.php') != -1) ? frames : parent.frames;
    if ( frameDoc['playerFrame'].document.getElementById('togglecode') ) {
        pheight = (pheight * 1) + frameDoc['playerFrame'].document.getElementById('togglecode').offsetHeight;

    }

    var measures = getHeightAndWidth(winobj);
    var width = (pwidth * 1) + widthAdd;
    var height = (pheight * 1) + heightAdd

    newWidth = width - measures['width'];
    newHeight = height - measures['height'];

    if(smooth == 42){
        var resize_calc = (newWidth > 0) ? function(k){return Math.floor(k)} : function(k){return Math.ceil(k)};

        var tW = measures['width'];
        var tH = measures['height'];

        while(adjW != 0 && adjH != 0){

            var adjW = resize_calc((width - tW)/2);
            var adjH = resize_calc((height - tH)/2);

            winobj.resizeBy(adjW,adjH);
            tW = (tW + adjW);
            tH = (tH + adjH);
        }

    } else {
        winobj.resizeBy(newWidth,newHeight);
    }
}

function getHeightAndWidth(winobj){
    if (winobj.self.innerWidth) {
        //mozilla
        frameWidth = winobj.self.innerWidth;
        frameHeight = winobj.self.innerHeight;
    } else if (winobj.document.documentElement && winobj.document.documentElement.clientWidth) {
        //IE with doctype
        frameWidth = winobj.document.documentElement.clientWidth;
        frameHeight = winobj.document.documentElement.clientHeight;
    } else if (winobj.document.body) {
        //IE without doctype
        frameWidth = winobj.document.body.clientWidth;
        frameHeight = winobj.document.body.clientHeight;
    }

    var measures = new Object();
    measures['height'] = frameHeight;
    measures['width'] = frameWidth;

    return measures;

}

function mediaSettings(){
    //get the current source of the player iframe
    var curSrc = frames['playerFrame'].location.href;

    //clear out the force refresh
    curSrc = curSrc.replace(/&frz=1/,'');

    //append set_prefs
    var newSrc = curSrc+'&set_prefs=1';

    //set the new source
    frames['playerFrame'].location.replace(newSrc);

    return false;
}

function changeCam(camera, chat){

    //var nodes = document.getElementById('multicamera_row2').getElementsByTagName('LI');

    //turn off all the tabs
    //for ( var i = 0; i < nodes.length; i++) {
        ///nodes[i].className = 'tab';
    //}

    //turn on the selected tab
    //document.getElementById('a_'+camera).className = 'tabon';

    //set the src of the player iframe (this will trigger resizing if needed)
    var campage = "/pages/event/uberpop/player.php?event="+text_id+"&camera="+camera+"&frz=1";

    parent.document.getElementById('playerFrame').src = campage;

    //if there is  a chat room, change that too.
    if(chat != '' && parent.document.getElementById('chatFrame')) {
        var chatpage = "/pages/event/uberpop/chat.php?event="+text_id+"&chat=y&chatroom="+chat;
        parent.document.getElementById('chatFrame').src = chatpage;

    }

}

function resizeFrames(iframes,pheight,pwidth,fade){

    fade = true;

    var parDoc = (document.location.href.indexOf('uberpop.php') != -1) ? document : parent.document;
    var frameDoc = (document.location.href.indexOf('uberpop.php') != -1) ? frames : parent.frames;
    //parDoc.getElementById('overlay').className = '';
    var measures = getHeightAndWidth(parent.window);
    var reDel = 0;

    //adapt the height for the toggle bar if it exists.
    if ( frameDoc['playerFrame'].document.getElementById('togglecode') ) {
        pheight = (pheight * 1) + frameDoc['playerFrame'].document.getElementById('togglecode').offsetHeight;
    }


    var halfEdge = edgesWidth/2;

    if (parDoc.getElementById('playerdate')){
        parDoc.getElementById('playerdate').style.right = (playerOnly) ? halfEdge+'px' : '';
    }

        if (parDoc.getElementById('player-left-col')) {
            parDoc.getElementById('player-left-col').style.height = pheight + 'px';
            parDoc.getElementById('player-left-col').style.width = pwidth + 'px';
        }

        if (parDoc.getElementById('playerFrame')) {
            parDoc.getElementById('playerFrame').style.height = pheight + 'px';
            parDoc.getElementById('playerFrame').style.width = pwidth + 'px';
        }

        if (!playerOnly){

            if (parDoc.getElementById('player-right-col')){
                parDoc.getElementById('player-right-col').style.height = (pheight > 397 ) ? '397px' : pheight + 'px';
                parDoc.getElementById('player-right-col').style.display = 'block';
            }
                
            if (parDoc.getElementById('tabs')){
                parDoc.getElementById('tabs').style.display = 'block';
            }

            //spool though the frames, and make them the right height.

            for ( var i = 0; i < iframes.length; i++ ) {
                if( parDoc.getElementById(iframes[i]) ) {
                    parDoc.getElementById(iframes[i]).style.height = (pheight > 397 ) ? '397px' : pheight + 'px';

                    //resize the trivia game
                    if(iframes[i].indexOf('trivia_game') == 0) {
                        if(frameDoc[iframes[i]] && frameDoc[iframes[i]].document.getElementById('flash-trivia')){
                            frameDoc[iframes[i]].document.getElementById('flash-trivia').style.height = (pheight > 397 ) ? '397px' : pheight + 'px';
                            if( frameDoc[iframes[i]] && frameDoc[iframes[i]].document.getElementById('mymovie') ) {
                            	frameDoc[iframes[i]].document.getElementById('mymovie').style.height = (pheight > 397 ) ? '397px' : pheight + 'px';
                            }
                        }
                    }
                }
            }


            if (parDoc.getElementById('player-mpu-bottom'))
                parDoc.getElementById('player-mpu-bottom').style.display = (embedChat) ? 'none' : 'block';
                
            if (parDoc.getElementById('promoAnon')) {
                 if(embedChat) {
                    parDoc.getElementById('promoAnon').style.height = parDoc.getElementById('player-mpu-bottom').offsetHeight;
                 } else {
                    parDoc.getElementById('promoAnon').style.display = 'none'
                 }
            }
            

        } else { //playerOnly
        		
			if(parDoc.getElementById('player-right-col'))	
				parDoc.getElementById('player-right-col').style.display = 'none';
				
			if(parDoc.getElementById('tabs'))	
				parDoc.getElementById('tabs').style.display = 'none';
        
        }
        
        if (parDoc.getElementById('chatFrame')){
                if(embedChat) {
                    var chatWidth = (pwidth * 1) + 19 + 342;
                    parDoc.getElementById('chatFrame').style.width = chatWidth + 'px';
                    parDoc.getElementById('chatFrame').style.height = chatHeight + 'px';
                    parDoc.getElementById('chatFrame').style.display = 'block';
                    parDoc.getElementById('chatlink_side').style.display = 'none';
                    parDoc.getElementById('chatlink_bottom').style.display = 'none';
                } else {
                	//hide chat
                    parDoc.getElementById('chatFrame').style.display = 'none';
                    //show chat link
                    if(pwidth == 640 && res800x600) {
                       	parDoc.getElementById('chatlink_side').style.display = 'block';
                    	parDoc.getElementById('chatlink_bottom').style.display = 'none';
                    
                    } else {
                    
                 	   parDoc.getElementById('chatlink_side').style.display = 'none';
                    	parDoc.getElementById('chatlink_bottom').style.display = 'block';
                    
                    }
                }
            }

		

        parDoc.getElementById('overlay').className = 'displayNone';
		
		
}
