var veilObj;
var commonPopUpClass;
var standardPopUp;

$(document).ready(function(){
	veilObj = $('#Veil');
	commonPopUpClass = $('.commonPopUpClass');
	standardPopUp = $('.standardPopUp');
	veilObj.animate({opacity:0.5}, 0);
	
	$("*[popUpOpenBtn='true']").click(popUpAction);
	$("*[popUpCloseBtn='true']").click(popUpAction);
	$("*[closePopUp='true']").click(popUpAction);
	
	//$("*[closePopUp='true']").click(closePopUp_Func);
});

function popUpAction(IDString, options)
{
	if(IDString.length > 0){
		var popUpID = '#' + IDString;
		var popUpObj = $(popUpID);
	}
	else{
		var popUpID = $(this).attr('popUpID');
		customAlert_ID = $(this).attr('customAlertID');
		
		var popUpObj = $(popUpID);
		
		if(customAlert_ID){
			alert("Custom Alerts are required");
			//getCustomAlertContent(popUpObj, customAlert_ID);
		}
	}
	
	//init reDirection variable
	var reDirect = "";
	//check for existance of redirect in function options
	if (options != null && options.hasOwnProperty("redirect")){
		reDirect = options.redirect;
	}
	/*if(popUpObj.attr('redirect') != "undefined"){
		reDirect = popUpObj.attr('redirect');
	}
	if(reDirect.length > 0){
		popUp_Obj.attr('redirect', reDirect);
	}*/
	
	if(popUpObj.css("display") == 'block')
	{
		popUpObj.fadeOut(300, function(){
			//Add extra function to run after the popUp closes
			if(reDirect != "" || reDirect.length != 0){
				hideOverlay();
				//alert(reDirect);
				location.href = reDirect;
			}
			hideOverlay();
		});
	}
	else
	{
		showOverlay();
		popUpObj.fadeIn(300, function(){
			//Add extra function to run after the popUp closes
		});
	}
}

function closePopUp_Func()
{
	var thisObj = $(this);
	
	hideOverlay();
	commonPopUpClass.fadeOut(200);
}

function showOverlay(complete){
	$('.standardPopUp').show(0);
	$('#Veil').fadeIn(0);
}
function hideOverlay(complete){
	$('.standardPopUp').hide(0);
	$('#Veil').fadeOut(0);
}
