﻿/***************************/
//@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 SpBanner
//0 means disabled; 1 means enabled;
var spBannerStatus = 0;

//loading SpBanner with jQuery magic!
function loadSpBanner(){
	//loads SpBanner only if it is disabled
	if(spBannerStatus==0){
		jQuery("#spBannerBackground").css({
			"opacity": "0.5"
		});
		jQuery("#spBannerBackground").fadeIn("slow");
		jQuery("#spBannerContent").fadeIn("slow");
		spBannerStatus = 1;
	}
}

//disabling SpBanner with jQuery magic!
function disableSpBanner(){
	//disables SpBanner only if it is enabled
	if(spBannerStatus==1){
		jQuery("#spBannerBackground").fadeOut("slow");
		jQuery("#spBannerContent").fadeOut("slow");
		spBannerStatus = 0;
	}
}

//centering SpBanner
function centerSpBanner(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var bannerHeight = jQuery("#spBannerContent").height();
	var bannerWidth = jQuery("#spBannerContent").width();
	//centering
	jQuery("#spBannerContent").css({
		"position": "absolute",
		"top": windowHeight/2-bannerHeight/2,
		"left": windowWidth/2-bannerWidth/2
	});
	//only need force for IE6
	
	jQuery("#spBannerBackground").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
jQuery(document).ready(function(){
	
	//LOADING SpBanner
	//Click the button event!
	jQuery("#spBannerButton").click(function(){
		//centering with css
		centerSpBanner();
		//load SpBanner
		loadSpBanner();
	});
				
	//CLOSING SpBanner
	//Click the x event!
	jQuery("#spBannerContentClose").click(function(){
		disableSpBanner();
	});
	//Click the image event!
	jQuery("#spBannerContentArea").click(function(){
		disableSpBanner();
	});
	//Click out event!
	jQuery("#spBannerBackground").click(function(){
		disableSpBanner();
	});
});
