﻿	/***************************/
	//@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 loadedDivId='';
	var popupWindow;
	
	//loading popup with jQuery magic!
	function loadPopup(elementId,noBackGround){
		(function($) {	
			//loads popup only if it is disabled
			//alert(popupStatus);
			if(popupStatus==0){
				//if(!noBackGround){
					//centerPopup(elementId);
					$("#backgroundPopup").css({
					"opacity": "0.7"
					});
					$("#backgroundPopup").fadeIn("fast");
				//}
				$("#"+elementId).fadeIn("fast");
				popupStatus = 1;
				loadedDivId=elementId;
			}
	 	})(jQuery);
	}
	
	//disabling popup with jQuery magic.. !
	function disablePopup(elementId,noBackGround){
		(function($) {	
			//disables popup only if it is enabled
			if(popupStatus==1){
				
				if(!noBackGround){
					$("#backgroundPopup").fadeOut("fast");
				}
				document.getElementById(elementId).innerHTML='<table width="386" border="0" cellspacing="0" cellpadding="0" class="f-l" style="margin:10px;"><tr><td height="45" colspan="4" align="left" valign="bottom" class="mcac-header"><img src="images/ajax-loader.gif" alt="Loading..." title="" /></td></tr></table>';
				$("#"+elementId).fadeOut("fast");
				popupStatus = 0;
			}
		})(jQuery);
	}
	
	//centering popup
	function centerPopup(elementId){
		//request data for centering
		/*var windowWidth = document.documentElement.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		var popupHeight = $("#"+elementId).height();
		var popupWidth = $("#"+elementId).width();
		//centering
		$("#"+elementId).css({
			"position": "absolute",
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		});*/
		//only need force for IE6
		
		$("#backgroundPopup").css({
			//"height": document.body.clientHeight,
			//"width": document.body.clientWidth
		});
		
	}


	//CONTROLLING EVENTS IN jQuery //-- avoid conflict of jquery and prototype
	(function($) {
    // $ sign here is parameter, which is set to 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(){
				if(loadedDivId!=''){
					disablePopup(loadedDivId);
				}else{
					disablePopup();
				}
			});
			//Press Escape event!
			$(document).keypress(function(e){
				if(e.keyCode==27 && popupStatus==1){
					if(loadedDivId!=''){
						disablePopup(loadedDivId);
					}else{
						disablePopup();
					}
				}
			});
		});
    	
 	})(jQuery);
	
	
	function loadPopupDiv(divId,url,noBackGround){     
		if(noBackGround){
			loadPopup(divId,noBackGround);
		}else{
			loadPopup(divId);
		}
		var http = getHTTPObject(); // We create the HTTP Object
		http.open("GET", url, true);
		http.onreadystatechange = function(){
			if(http.readyState == 4){
				if(http.status==200){
					var results=http.responseText;
					document.getElementById(divId).innerHTML = results;
				}
			}
		};
		http.send(null);
	}
	
	
	//	Function POP UP Window
		var newWin = null; 
		
		function closeNewwin(){
		 if(newWin != null && !newWin.closed)
		   newWin.close();
		}
		
		function popUp(url,id, strType, strHeight, strWidth) {
		 	
			closeNewwin();
			 var strOptions="";
			 // NOTE: the 'console' IF statement used for http://kirstendavies.com/index.php?content=music
			 // eliminates both the toolbar and the statusbar from the new window so that Wimpyplayer
			 // can do it's thing with the iPod skin.
			switch(strType){
				case 'iPop':
					strOptions="height="+strHeight+",width="+strWidth;
					break;
				case 'console':
					strOptions="resizable=no,height="+strHeight+",width="+strWidth;
					break;
				case 'fixed':
					strOptions="status,height="+strHeight+",width="+strWidth;
					break;
				case 'elastic':
					strOptions="toolbar,menubar,scrollbars,"+"resizable,location,height="+strHeight+",width="+strWidth;
					break;
				default:
					strOptions="width=480,height=200,scrollbars,dependent,resizable";
					break;
			}
			
			newWin = window.open(url, 'newWin', strOptions);
			newWin.focus();
		}

	//-- close popuped up window --//
	function closeWindow(){
		popupWindow.document.close();
	}


