﻿/* Clears Text in Search Text Box */
/* Displays 'Popup Media Player' popup */

//0 - disabled; 1 - enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(divId){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#" + divId).fadeIn("slow");
		popupStatus = 1;
	}
}

//Disabling popup
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupWindow").fadeOut("slow");
		$("#loginWindow").fadeOut("slow");
		popupStatus = 0;
	}
}

//Centering popup
function centerPopup(divId){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#" + divId).height();
	var popupWidth = $("#" + divId).width();
	var xy = getScrollXY();
	
	//Diplay Login screen at the top of the page
	if(divId == 'loginWindow') {
	    $("#" + divId).css({
		    "position": "absolute",
		    "top": 52,
		    "left": windowWidth/2-popupWidth/2 + 285
	    });
	} else { //Display Media Player in the center of the page
        $("#" + divId).css({
		    "position": "absolute",
		    "top": windowHeight/2-popupHeight/2 + xy[1] - 60,
		    "left": windowWidth/2-popupWidth/2 - 175
	    });	
	}
	//only need force for IE6
	$("#backgroundPopup").css({
		"height": windowHeight
	});	
}

//Determine Scrolling Offset if Any
function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [scrOfX, scrOfY];
}

$(document).ready(function(){
	//Click the watch slidecast link
	$("#watch_slidecast").click(function(){
		centerPopup('popupWindow');
		loadPopup('popupWindow');
	});
	
	//Click the login link
	$("#login").click(function(){
		centerPopup('loginWindow');
		loadPopup('loginWindow');
	});
				
	//Click the X or Cancel button
	$("#closeLogin").click(function(){
		disablePopup();
	});
	
	//Click the X or Cancel button
	$("#closePlayer").click(function(){
		disablePopup();
	});
	
	//Press Escape to Close Media Player
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});	
	
});

/** Displays 'Send Report to a Friend' popup **/
