// PLM Pop Up Functions
function plmLoadPopup(name)
{
	//loads popup only if it is disabled
	if ( jQuery("#bgPopup").data("state") == 0 ) {
		jQuery("#bgPopup").css({
			'position': 'fixed',
			'opacity': '0.7',
			'z-index': '9999'
		});
		jQuery("#bgPopup").fadeIn("medium");
		jQuery(name).fadeIn("medium");
		jQuery("#bgPopup").data("state",1);
	}
}

function plmLoadExitPopup(name)
{
	//loads popup only if it is disabled
	if ( jQuery("#bgPopup").data("state") == 0 ) {
		jQuery("#bgPopup").css({
			'position': 'fixed',
			'opacity': '0.7',
			'z-index': '99999'
		});

		jQuery("#bgPopup").fadeIn("medium");
		jQuery(name).fadeIn("medium");
	
		jQuery("#bgPopup").data("state",1);
	}
}

function plmDisablePopup(name)
{
	if ( jQuery("#bgPopup").data("state") == 1 ) {
		jQuery("#bgPopup").fadeOut("slow");
		jQuery(name).fadeOut("slow");
		jQuery("#bgPopup").data("state",0);
	}
}

function plmCenterPopup(name)
{
	var pos  = 'fixed';

	var top  = ((jQuery(window).height() / 2) - (jQuery(name).outerHeight() / 2));
	var left = ((jQuery(window).width() / 2) - (jQuery(name).outerWidth() / 2));

	if( top < 0 ) top = 0;
	if( left < 0 ) left = 0;

	// IE6 fix
	if( jQuery.browser.msie && parseInt(jQuery.browser.version) <= 6 ) {
		top = top + jQuery(window).scrollTop();
		pos = 'absolute';
	}

	jQuery(name).css({
        	'position' : pos,
        	'top' : top,
        	'left' : left,
		'z-index': '999999'
	});
}

// PLM Slide Functions
function plmSlideUp(pos)
{
	if( pos == 'top' ) {
		jQuery('#plm-slideup').addClass("plm-slidetop");
		var margin_top = jQuery('body').css('margin-top').replace('px', '');
		var new_margin_top = margin_top + 75;
		jQuery("body").css({
			'margin-top': new_margin_top + 'px'
		});
	} else if ( pos == 'bottom' ) {
		jQuery('#plm-slideup').addClass("plm-slidebottom");
		var margin_bot = jQuery('body').css('margin-bottom').replace('px', '');
		var new_margin_bot = margin_bot + 75;
		jQuery("body").css({
			'margin-bottom': new_margin_bot + 'px'
		});
	} else if (pos=="left") {
		jQuery('#plm-slideup').addClass("plm-slideleft");
	} else if (pos=="right") {
		jQuery('#plm-slideup').addClass("plm-slideright");
	}

	if ( pos == 'top' || pos == 'bottom' ) {
		if ( pos == 'top' ) {
			pos2 = 'up';
		} else {
			pos2 = 'down';
		}

		jQuery("#plm-slideup").show("slide", { direction: pos2 }, 'slow');
	} else {
		jQuery("#plm-slideup").show("slide", { direction: pos }, 'slow');
	}

	jQuery('#plm-slideclose').show();
}

function plmCloseBottom()
{
	jQuery('#plm-slideup').animate({
    		top: '+=100'
	}, 1000, function() {
    		jQuery(this).hide();
		jQuery('#plm-slideclose').hide();
  	});
}

function plmCloseTop()
{
	jQuery('#plm-slideup').animate({
    		top: '-=100'
	}, 1000, function() {
    		jQuery(this).hide();
		jQuery('#plm-slideclose').hide();
  	});
}

function plmCloseLeft()
{
	jQuery('#plm-slideup').animate({
    		left: '-=300'
	}, 1000, function() {
    		jQuery(this).hide();
		jQuery('#plm-slideclose').hide();
  	});
}

function plmCloseRight()
{
	jQuery('#plm-slideup').animate({
    		left: '+=300'
	}, 1000, function() {
    		jQuery(this).hide();
		jQuery('#plm-slideclose').hide();
  	});
}

function plmExitPage(pageURL)
{
	var exitPage = '<div id="plm-exit-page" style="background:#FFFFFF; width:100%; height:100%; display:block; margin-top:0px; margin-left:0px;" align="center">';
	exitPage += '<iframe src="' + pageURL + '" width="100%" height="100%" align="middle" frameborder="0"></iframe>';
	exitPage += '</div>';

	jQuery('body').html('');
	jQuery('body').css({
		'margin': '0',
		'width': '100%',
		'height': '100%',
		'overflow': 'hidden'
	});
	jQuery('body').append(exitPage);

	jQuery('#plm-exit-page').css({
		'position': 'fixed',
		'z-index': '99999',
		'width':'100%',
		'height':'100%',
		'top': '0',
		'left': '0',
		'display':'block'
	});
	
}

