/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

var closecliks = 0;


//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	//if(confirm('Deseja obter maiores informações sobre este curso?')==false) {

		//CLEILTON 02/04/2009
                //SE O POPUP ESTIVER CARREGANDO E O USUÁRIO JÁ CLICOU UMA VEZ PARA
                //FECHAR, ENTÃO FECHA O POPUP E ZERO O CONTADOR DE CLIQUES
		if(popupStatus==1 && closecliks>=1){
			$("#backgroundPopup").fadeOut("slow");
			$("#popupContact").fadeOut("slow");
			popupStatus = 0;
			closecliks  = 0;
		}

		//SE O POPUP ESTIVER CARREGADO E USUÁRIO CLICOU UMA VEZ EM FECHAR
		//DEVE MOSTRAR A TELA DE SOLICITAÇÃO DE CONTATO
		if(popupStatus==1 && closecliks==0){
			//$("#backgroundPopup").fadeOut("slow");
			//$("#popupContact").fadeOut("slow");
			//popupStatus = 0;
			frameurl("/scripts/solicitacao_contato_cursos.asp?turma=&assunto=Fastjob+Treinamentos&codigo=Solicitação+de+Informações+de+Cursos&");
			closecliks = 1;
		}

	//}
}

//centering popup
function centerPopup(vmy){
	//request data for centering

	if (self.pageYOffset){
	    y = self.pageYOffset; 
	} 
	else if (document.documentElement && document.documentElement.scrollTop){ 
	    y = document.documentElement.scrollTop; 
	} 
	else if (document.body){
	    y = document.body.scrollTop;
	} 

        
        //alert (y);
        

        if (navigator.appName == 'Netscape') {
	   var windowWidth  = document.documentElement.clientWidth;
	   var windowHeight = document.documentElement.clientHeight;
	   //var windowHeight = y;
	} else {
	   var windowWidth  = document.body.clientWidth;
           var windowHeight = document.body.clientHeight;
           //var windowHeight = vmy;
	}

	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": (((windowHeight/2)+y)-(popupHeight/2)),
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": 1800
	});
	
}



//INICIO FUNÇÃO PARA CARREGAR PAGINA DO CURSO NA IFRAME DA DIV

function frameurl(vurl){
   //alert(vurl);
   document.getElementById('icurso').src=vurl;
   if (navigator.appName == 'Netscape') {
      document.getElementById('icurso').height=400;
   } else {
      document.getElementById('icurso').height=420;
   }   
}

//FIM FUNÇÃO PARA CARREGAR PAGINA DO CURSO NA IFRAME DA DIV


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$(".button").click(function(e){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});

	//Click out event!
	//$("#backgroundPopup").click(function(){
	//	disablePopup();
	//});

	//Press Escape event!
	//$(document).keypress(function(e){
	//	if(e.keyCode==27 && popupStatus==1){
	//		disablePopup();
	//	}
	//});

});
 

