﻿/***************************/
//@Author: salim qureshi
//@website: whoawee.com
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
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");
		$("#mainContainer").fadeIn("slow");
		//document.getElementById('articlesMain').style.display = "block"
		popupStatus = 1;
		//getArticleList("cat1","list","0");
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		//$("#readArticle").fadeOut("slow");
		//$("#articlesMain").fadeOut("slow");
		$("#mainContainer").fadeOut("slow");
		//$("#submitArticle").fadeOut("slow");
		//$("#contactAdmin").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#mainContainer").height();
	var popupWidth = $("#mainContainer").width();
	//centering
	$("#mainContainer").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
//******************************************************************************

//Under Construction
function loadPopup_uc(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#underconst").fadeIn("slow");
		popupStatus = 1;		
	}
}
function disablePopup_uc(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#underconst").fadeOut("slow");
		popupStatus = 0;
	}
}
function centerPopup_uc(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#underconst").height();
	var popupWidth = $("#underconst").width();
	//centering
	$("#underconst").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
//******************************************************************************************
function comingsoon() {
	centerPopup_uc();
	loadPopup_uc();
}
//disable all divs
function disabledivs() {
	document.getElementById('wrapper').style.display = "none" 
	//document.getElementById('footer').style.display = "none"
	//document.getElementById('contactAdmin').style.display = "none"
	//document.getElementById('submitArticleResult').style.display = "none"
	//document.getElementById('mailToadminRes').style.display = "none"
	//document.getElementById('submitArticle').style.display = "none"
}
//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	//LOADING POPUP
	//Click the regbtn button event!
	$("#button").click(function(){
		//centering with css
		//document.getElementById('submitRegResult').style.display = "none" 
		$("#wrapper").fadeIn("slow");
		document.getElementById('submitRegResult').style.display = "none" 
		centerPopup();
		//document.getElementById('wrapper').style.display = "block" 
		//load popup
		loadPopup();
	});

	//CLOSING POPUP
	//Click the x event!
	$("#mainContainerClose").click(function(){
		disablePopup();
		$("#wrapper").fadeIn("slow");
		//document.getElementById('wrapper').style.display = "none" 
	});
	$("#mainContainerClose1").click(function(){
		disablePopup();
		$("#submitRegResult").fadeIn("slow");
		//document.getElementById('submitRegResult').style.display = "none" 
	});
//***********************************************
//Under Construction
	$("#underconstClose").click(function(){
		disablePopup_uc();
	});
//***********************************************
	//Click out event!
	/*
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	*/
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	
	//Click on submitarticle Btn.
	$("#submitanc").click(function(e){
		document.getElementById('wrapper').style.display = "none"
		document.getElementById('submitRegResult').style.display = "none"
		$("#submitRegResult").fadeIn("slow");
	});
	//Click on send article Btn.
	$("#mailToadminBtn").click(function(e){
		document.getElementById('contactAdmin').style.display = "none"
		$("#mailToadminRes").fadeIn("slow");
	});
});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Click the read more link
function readmore(pmag_id,start) {
	document.getElementById('submitArticle').style.display = "none" 
	document.getElementById('articlesMain').style.display = "none"		
	$("#readArticle").fadeIn("slow");
	getArticleList(pmag_id,'read',start);
}
//Click the Back Button.
function backToList(catid,start) {
	document.getElementById('submitArticle').style.display = "none" 
	document.getElementById('readArticle').style.display = "none"
	$("#articlesMain").fadeIn("slow");
	getArticleList(catid,'list',start);
}
//Click on previous Btn.
function prevBtn(catid,type,start) {
	getArticleList(catid,'list',start);
}
function nextBtn(catid,type,start) {
	//alert(catid+" - "+type+" - "+start);
	getArticleList(catid,'list',start);
}
function numbtn(catid,type,start) {
	$("#articlesMain").fadeIn("slow");
	getArticleList(catid,'list',start);
}
