function loadPopup(){
    jQuery("#backgroundPopup").css({ "opacity": "0.7" });
    jQuery("#backgroundPopup").fadeIn("slow");
	
    var id = '#popupContact';
	jQuery(id).css("position","fixed");
    jQuery(id).css("top", ( jQuery(window).height() - jQuery(id).height()) / 2 + "px");
	jQuery(id).css("left", ( jQuery(window).width() - jQuery(id).width()) / 2  + "px");
	
	jQuery(id).fadeIn("slow");
}

function disablePopup(idSelector, url){
    jQuery("#backgroundPopup").fadeOut("slow");
    jQuery("#popupContact").fadeOut("slow");
    jQuery(idSelector).attr('href', url);
}

function bindPopupEvent(idSelector, width, height){
	if (width == -1) { width = 100; }
	if (height == -1) { height = 100; }

    jQuery('div#seopage').css({'width':width, 'height':height-25});
	jQuery('#popupContact').css({'width':width, 'height':height});

	var newAnchorLink = '#popup';
	var originalUri = jQuery(idSelector).attr('href');
	
    ///load the popup
    jQuery(idSelector).click(function() {
        jQuery(idSelector).attr('href', newAnchorLink);
        loadPopup();
    });

    ///close popup scenarios
    jQuery("#popupContactClose").click(function(){ disablePopup(idSelector, originalUri); });//When Clicking the x event
    jQuery("#backgroundPopup").click(function(){ disablePopup(idSelector, originalUri); });//When Clicking out on fading background
    jQuery(document).keypress(function(e){ if(e.keyCode==27) disablePopup(idSelector, originalUri); });//When Pressing Escape event

}
