function CreatePopup(height, duration, description, lifetimemin,slideDuration) {
    // Exit if the current browser has already received the popup, or 
    // the browser is not supported (IE6).

    if (HasAlreadyReceivedPopup(description) || IsUnsupportedUserAgent())
    	return;
    var popup = jQuery("#sliding_popup")
	      	     .css({"left": "-80em"})
             	     .height(height)
		     .hide()
		     .appendTo("body");

    ShowPopup(description, lifetimemin, duration,slideDuration,popup); 
}

function ShowPopup(description, lifetimemin, duration,slideDuration,popup) {      
      /* var rightpos = jQuery('#root').outerWidth()-jQuery('#home-p7').position().left-jQuery('#sliding_popup').outerWidth();*/

	var leftOffset = (jQuery('#root').outerWidth() - jQuery('#sliding_popup').outerWidth()) / 2;
	var topOffset = (jQuery('#root').outerHeight() -jQuery('#sliding_popup').outerHeight()) / 2;
       
	/*var p1 = popup.show().animate( { "left": leftOffset}, duration);*/
	jQuery('#oscuramento').css("height",jQuery(document).height());
       var osc = jQuery("#oscuramento").show().animate({opacity:0.5},500);
	var p1 = popup.css("left",leftOffset).css("opacity","0.2").show().animate({opacity:1},500);
	ReceivedPopup(description, lifetimemin);
       p1.delay(slideDuration);
       osc.delay(slideDuration);
       ClosePopup(500);
}

function HasAlreadyReceivedPopup(description) { 
   return document.cookie.indexOf(description) > -1;
}

function ReceivedPopup(description, lifetimemin) { 
	var date = new Date(); 
	date.setTime(date.getTime() + (lifetimemin*60*1000)); 
	document.cookie = description + "=true;expires=" + date.toUTCString() + ";path=/"; 
}

function IsUnsupportedUserAgent() { 
      
      if (jQuery.browser.msie && jQuery.browser.version.split('.')[0] < 7) 
          return true;
      else
          return false;
}

function ClosePopup(duration) {
	/*jQuery("#sliding_popup").animate({ left: "200em"}, duration);*/
	jQuery("#sliding_popup").animate({ opacity: 0}, duration);
	jQuery("#oscuramento").animate({opacity:0},1000,function () {jQuery("#sliding_popup").remove();jQuery("#oscuramento").remove();});
}

function DestroyPopup(duration) {
	jQuery("#sliding_popup").remove();
       jQuery("#oscuramento").remove();
}

