﻿/***************************/
//@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 SPLASH
//0 means disabled; 1 means enabled;
var splashStatus = 0;

//loading splash with jQuery magic!
function loadSplash(){
	//loads splash only if it is disabled
	if(splashStatus==0){
		$("#bgSplash").css({
			"opacity": "0.7"
		});
		$("#bgSplash").fadeIn("slow");
		$("#splash").fadeIn("slow");
		splashStatus = 1;
	}
}

//disabling splash with jQuery magic!
function disableSplash(){
	//disables splash only if it is enabled
	if(splashStatus==1){
		$("#bgSplash").fadeOut("slow");
		$("#splash").fadeOut("slow");
		splashStatus = 0;
		//disable splash for 1 day
		$.cookie('playoffs', '1', { expires: 1 });
	}
}

//disabling splash permanently with jQuery magic!
function permanentSplash(){
	//disables splash only if it is enabled
	if(splashStatus==1){
		$("#bgSplash").fadeOut("slow");
		$("#splash").fadeOut("slow");
		splashStatus = 0;
		//disable splash permanently
		$.cookie('playoffs', '1', { expires: 2000 });
	}
}

//centering splash
function centerSplash(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var splashHeight = $("#splash").height();
	var splashWidth = $("#splash").width();
	//centering
	$("#splash").css({
		"position": "absolute",
		"top": windowHeight/2-splashHeight/2,
		"left": windowWidth/2-splashWidth/2
	});
	//only need force for IE6
	
	$("#bgSplash").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING SPLASH
	//Click the button event!
	//$("#button").click(function(){
	$(document).ready(function(){
		if ($.cookie('playoffs') != '1') {
			//centering with css
			centerSplash();
			//load splash
			loadSplash();
		}
	});
				
	//CLOSING SPLASH
	//Click the x event!
	$("#splashClose").click(function(){
		disableSplash();
	});
	//Click out event!
	$("#bgSplash").click(function(){
		disableSplash();
	});
	//Skip permanently
	$("#splashSkip").click(function(){
		permanentSplash();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && splashStatus==1){
			disableSplash();
		}
	});

});