// Xplana Modals
// © 2010 MBS Direct
// 01.14.2010 dh

// COMMON VARIABLES

// no conflict jQuery / mootools  
// rds 20100327  1632EST  jQuery.noConflict(); 

 

var modalStatus = 0; // disabled

// INVOKE MODAL FOCUS
function invokeFocus(){ 
	if(modalStatus==0){
		jQuery("#modal-focus").css({"opacity": "0.9"});
		jQuery("#modal-focus").fadeIn("slow");
		modalStatus = 1;
	}
}

// CLOSE MODAL
function closeModal(){
	if(modalStatus==1){
		jQuery("#modal-focus").fadeOut("slow");
		jQuery(".modal").fadeOut("slow");
		modalStatus = 0;
		$f().unload();
		jQuery("#stage a").text(" ");
	}
}
jQuery(document).ready(function(){
	jQuery("#modal-focus").click(function(){  
		closeModal();
	});
	jQuery(document).keypress(function(e){  
		if(e.keyCode==27 & modalStatus==1){
			closeModal();  
		}  
	}); 
});

function flashModal(){ 
	$f().unload();
	jQuery("#stage a").text(" ");
	jQuery("#player-overview-modal").fadeOut("normal");
	jQuery("#player-isntitution-modal").fadeOut("normal");
	jQuery("#player-publisher-modal").fadeOut("normal");
	jQuery("#request-modal").fadeOut("normal");
	jQuery("#login-modal").fadeOut("normal");
}
	

// PLAYER - OVERVIEW
function centerOverviewPlayer(){
	var winW = jQuery(window).width();
	var winH = jQuery(window).height();
	var modalH = jQuery("#player-overview-modal").height();
	var modalW = jQuery("#player-overview-modal").width();	
	jQuery("#player-overview-modal").css({"position": "fixed","top": winH/2-modalH/2-20, "left": winW/2-modalW/2});
}
function invokeOverviewPlayer(){ 
	centerOverviewPlayer();
	invokeFocus();
	$f().load();
	jQuery("#player-overview-modal").css({"display": "block"});
	jQuery("#player-overview-modal").fadeIn("slow");
}

// PLAYER - INSTITUTION
function centerInstitutionPlayer(){
	var winW = jQuery(window).width();
	var winH = jQuery(window).height();
	var modalH = jQuery("#player-institution-modal").height();
	var modalW = jQuery("#player-institution-modal").width();	
	jQuery("#player-institution-modal").css({"position": "fixed","top": winH/2-modalH/2-20, "left": winW/2-modalW/2});
}
function invokeInstitutionPlayer(){ 
	centerInstitutionPlayer();
	invokeFocus();
	$f().load();
	jQuery("#player-institution-modal").css({"display": "block"});
	jQuery("#player-institution-modal").fadeIn("slow");
}

// PLAYER - PUBLISHER
function centerPublisherPlayer(){
	var winW = jQuery(window).width();
	var winH = jQuery(window).height();
	var modalH = jQuery("#player-publisher-modal").height();
	var modalW = jQuery("#player-publisher-modal").width();	
	jQuery("#player-publisher-modal").css({"position": "fixed","top": winH/2-modalH/2-20, "left": winW/2-modalW/2});
}
function invokePublisherPlayer(){ 
	centerPublisherPlayer();
	invokeFocus();
	$f().load();
	jQuery("#player-publisher-modal").css({"display": "block"});
	jQuery("#player-publisher-modal").fadeIn("slow");
}


//
function switchOverviewPlayer(){ 
	$f().stop();
	$f().unload();
	jQuery("#player-institution-modal").css({"display": "none"});
	jQuery("#player-publisher-modal").css({"display": "none"});
	invokeOverviewPlayer();
}
function switchInstitutionPlayer(){ 
	$f().stop();
	$f().unload();
	jQuery("#player-publisher-modal").css({"display": "none"});
	jQuery("#player-overview-modal").css({"display": "none"});
	invokeInstitutionPlayer();
}
function switchPublisherPlayer(){ 
	$f().stop();
	$f().unload();
	jQuery("#player-overview-modal").css({"display": "none"});
	jQuery("#player-institution-modal").css({"display": "none"});
	invokePublisherPlayer();
}

// REQUEST
function centerRequest(){
	var winW = jQuery(window).width();
	var winH = jQuery(window).height();
	var modalH = jQuery("#request-modal").height();
	var modalW = jQuery("#request-modal").width();	
	jQuery("#request-modal").css({"position": "fixed","top": winH/2-modalH/2-20, "left": winW/2-modalW/2});
}
function invokeRequest(){ 
	centerRequest();
	invokeFocus();
	jQuery("#request-modal").fadeIn("slow");
}
function submitRequest(){
	jQuery("#request-modal form").submit();
}
function cancelRequest(){
	closeModal();
}

// LOGIN
function centerLogin(){
	var winW = jQuery(window).width();
	var winH = jQuery(window).height();
	var modalH = jQuery("#login-modal").height();
	var modalW = jQuery("#login-modal").width();	
	jQuery("#login-modal").css({"position": "fixed","top": winH/2-modalH/2-20, "left": winW/2-modalW/2});
}
function invokeLogin(){ 
	centerLogin();
	invokeFocus();
	jQuery("#login-modal").fadeIn("slow");
}

//
function swapOverviewPlayer(){ 
	flashModal();
	invokeOverviewPlayer();
}
function swapRequest(){ 
	flashModal();
	invokeRequest();
}

//
jQuery(document).ready(function(){
	jQuery(window).resize(function(){
		centerLogin();
		centerRequest();
		centerOverviewPlayer();
		centerPublisherPlayer();
	});
});

