/**
*	WHV Promo Ads
*	@author: Ramil Jugao
*	@date:	October 1, 2008
*	@description:	Displays a promo ad overlay by replacing the original body content 
*		of the web page via DOM manipulation.
*		Promo ad will direct user to the promo site or continue displaying the site
*/



var paRedirectURL = null;						// redirects in current page, if any, goes here
//var paPromoURL = "http://www.warnervideo.com?adid=brandsitespromo";	// URL of the promo site or page
var paPromoURL = "http://whv.warnerbros.com/WHVPORTAL/Portal/homepage.jsp?adid=brandsitespromo";
var paBodyContent = null;						// temporary container for original body content
var paTitle = document.title;						// [temp] 
var imgPath = "/all/us/js/whvpromoad/images/";
var hideNoThanksBtn  = null;
/**
*  Store and replace the original body content before images are displayed
*/
Event.observe(document, 'dom:loaded', function () {
  	// store the original content of the body
	paBodyContent = document.body.innerHTML;

  	// remove the body content
  	document.body.innerHTML = "";
   
  	// add the overlay content
	document.body.appendChild(createOverlayObj());
});


/**
*	Build the overlay object with the promo graphic and skip (ie 'No Thanks') button
*/
function createOverlayObj() {

   	// create overlay div
	var overlay = new Element('div', {align: 'center'});
	
	// create container
	var overlayContent = new Element('div').setStyle({
		padding: '50px 0 400px 0',
		backgroundColor: '#000'
	});

	// insert promoad image
	var header = new Element('img', {src: '/all/us/js/whvpromoad/images/whv_promoad.jpg', width: '1000', height:'364'}).setStyle({ cursor: 'pointer'	});
	// add functionality to button to visit the store
	header.observe('click', function () {
		loadPromoSite();
	});
	// wrap the header in a div
	var headerContainer = new Element('div').setStyle({paddingTop: '50px'}).insert(header);
	overlayContent.insert(headerContainer);
	
	if (hideNoThanksBtn  == undefined || hideNoThanksBtn  == null || hideNoThanksBtn  != true ) {
		// insert promo ad button
		var btn = new Element('img', {id: 'whv_promoad_btn', src:'/all/us/js/whvpromoad/images/btn_nothanks.jpg', width: '204', height:'25'}).setStyle({ cursor: 'pointer' });
		// add functionality to button to show the original body content
		btn.observe('click', function () {
			showOriginalBodyContent();
		});
		btn.observe('mouseover', function () {
			this.src = '/all/us/js/whvpromoad/images/btn_nothanks_over.jpg';
		});	
		btn.observe('mouseout', function () {
			this.src = '/all/us/js/whvpromoad/images/btn_nothanks.jpg';
		});	

		// wrap the button in a div
		var btnContainer = new Element('div').setStyle({paddingTop: '50px'}).insert(btn);
		overlayContent.insert(btnContainer);
	}
	
	// add container to overlay div
	overlay.update(overlayContent);

	return overlay;
}



/**
*       Replace the overlay with the original body content
*	or do a redirect
*/
function showOriginalBodyContent() {
	if (paRedirectURL == null || paRedirectURL == undefined) {
		document.body.innerHTML = paBodyContent;
	} else {
		location.replace(paRedirectURL);
	}
}


/**
*       Launch the promo site/page
*	
*/
function loadPromoSite() {
	location.href = paPromoURL + "&adtitle=" + paTitle;
}
