﻿/***************************/
//@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 popupStatusRSS = 0;

//loading popup with jQuery magic!
function loadRSSPopup(){
	//loads popup only if it is disabled
	if(popupStatusRSS==0){
		$("#backgroundPopupRss").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupRss").fadeIn("slow");
		$("#popupRSS").fadeIn("slow");
		
		popupStatusRSS = 1;
	}
}

//disabling popup with jQuery magic!
function disableRSSPopup(){
	//disables popup only if it is enabled
	if(popupStatusRSS==1){
		$("#backgroundPopupRss").fadeOut("slow");
		$("#popupRSS").fadeOut("slow");
		popupStatusRSS = 0;
	}
}

//centering popup
function centerRSSPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupRSS").height();
	var popupWidth = $("#popupRSS").width();
	//centering
	$("#popupRSS").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopupRss").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#rssButton").click(function(){	    
		//centering with css		
		centerRSSPopup();
		//load popup
		loadRSSPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupRSSClose").click(function(){
		disableRSSPopup();
    });

    //CLOSING POPUP
    //Click the x event!
    $("#btnSubmitRSS").click(function() {
        disableRSSPopup();
    });	
	
	//Click out event!
	$("#backgroundPopupRss").click(function(){
		disableRSSPopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatusRSS==1){
			disableRSSPopup();
		}
	});

});