//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(divid) {
	//loads popup only if it is disabled
	if (popupStatus == 0) {
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		// ie6 bug: select shows over other elements.
		// this fixes by hiding all selects before the overlays appear
		// in ie6 only
		jQuery.each(jQuery.browser, function(i, val) {
			if (i == "msie" && jQuery.browser.version.substr(0, 1) == "6")
				$("select").css("visibility", "hidden");
		});
		// end fix.
		$("#backgroundPopup").css("display", "block");
		$("#" + divid).css("display", "block");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup() {
	//disables popup only if it is enabled
	if (popupStatus == 1) {
		// ie6 bug: select shows over other elements.
		// this fixes by showing all selects before the overlays disappear
		// in ie6 only.
		jQuery.each(jQuery.browser, function(i, val) {
			if (i == "msie" && jQuery.browser.version.substr(0, 1) == "6")
				$("select").css("visibility", "visible");
		});
		// end fix.
		$("#backgroundPopup").fadeOut("fast");
		$("#popup").fadeOut("fast");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(divid) {
	//request data for centering
	window.scrollTo(0, 0);
	var windowWidth = $(window).width();
	var windowHeight = $(window).height();
	var popupHeight = $("#" + divid).height();
	var popupWidth = $("#" + divid).width();

	//centering
	$("#" + divid).css({
		"position": "absolute" //,
		//"top": windowHeight / 2 - popupHeight / 2 //,
		//"left": windowWidth / 2 - popupWidth / 2
	});
	//only need force for IE6

//	$("#backgroundPopup").css({
//		"height": 2500,
//		"width": 2500
//	});
}

function doPopup() {
	centerPopup("popup");
	loadPopup("popup");
}

function visitNewSite() {
	setCookie("new_site_alert", "1", "30");
	document.location="http://www.roskahealthcare.com";
}

$(document).ready(function () {
	//CONTROLLING EVENTS IN jQuery
	//CLOSING POPUP
	//Click the x event!
	$("#popupClose").click(function () {
		setCookie("new_site_alert", "1", "30");
		disablePopup();
	});

	if (getCookie("new_site_alert") != "1") {
		doPopup();
	}
	
	$("#newSite").mouseover(function() {
		$("#newSite").attr("src", "img/newSiteAlert/check_btn_on.jpg");
	});

	$("#newSite").mouseout(function() {
		$("#newSite").attr("src", "img/newSiteAlert/check_btn_off.jpg");
	});
	
	$("#popupCloseImg").mouseover(function() {
		$("#popupCloseImg").attr("src", "img/newSiteAlert/x_on.jpg");
	});

	$("#popupCloseImg").mouseout(function() {
		$("#popupCloseImg").attr("src", "img/newSiteAlert/x_off.jpg");
	});
});
