﻿/***************************/
//@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;
function showlayer(num) {
	
	var i=1;
	for(i=1;i<=3;i++) {
		if(i==num) {
			document.getElementById('l'+i).style.display="block";
		}
		else {
			document.getElementById('l'+i).style.display="none";
		}
	}
} 

function lib_bwsrcheck(){ //Browsercheck (needed)

	this.ver=navigator.appVersion

	this.agent=navigator.userAgent

	this.dom=document.getElementById?1:0

	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0

	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 

	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;

	this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;

	this.ie8=(this.ver.indexOf("MSIE 8")>-1 && this.dom && !this.opera5)?1:0;

	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;

	this.ie=this.ie4||this.ie5||this.ie6||this.ie7||this.ie8

	this.mac=this.agent.indexOf("Mac")>-1

	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;

	this.ns4=(document.layers && !this.dom)?1:0;

	this.bwsr=(this.ie8 || this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)

	return this

}

var bwsr=new lib_bwsrcheck();
var dnum = 1;
function findPos(){
  if(bwsr.ns4){   //Netscape 4
    var x = document.layers.layerMenu.pageX
    var y = document.layers.layerMenu.pageY
  }else{ //other browsers
    var x=0; var y=0; var el,temp
   // alert("seprator"+obj_menu);
    el = bwsr.ie4?document.all["rssicon"]:document.getElementById("rssicon");
	
    if(el != null) {
	    if(el.offsetParent){
	      temp = el
	      while(temp.offsetParent){ //Looping parent elements to get the offset of them as well
	        temp=temp.offsetParent; 
	        x+=temp.offsetLeft
	        y+=temp.offsetTop;
	      }
	    }
	
	  }  
	    x+=el.offsetLeft
	    y+=el.offsetTop
    
  }

  //Returning the x and y as an array

  return [x,y]
}


var popupStatus = 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(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	
	var scroll_top = (bwsr.ie) ? document.documentElement.scrollTop : window.pageYOffset;
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	
	//alert(popupHeight);alert(windowHeight);
	
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": ((windowHeight-popupHeight)/2)+scroll_top+50,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"min-height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {
	
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//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();
		}
	});

});

function popup(num) {
	var wd;
	dnum = num;
	if(num == 3) {
		wd = '650px';
	}
	else {
		wd = '500px';
	}
	
	$("#popupContact").css({
				"min-height": "150px",
				"width": wd
			});
			/*
			$('#contactArea').html("Loading...");
			$('#contactArea').load(php_self,{call:'ajax_load_plzreg'}, function() {
				// $('#uploader').html($('#uploader1').html());
			});
			*/
			//centering with css
			centerPopup();
			//load popup
			loadPopup();
			showlayer(num);
			return false;
}

