/*
 * Accessories Portal Content Popups
 * By Ronald Jusuf
 * Hothouse 2008
 * Last Modified 23 July 2008
 */
 
function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	o = document.getElementById(objectId);
	oLeft = o.offsetLeft;            // Get left position from the parent object
	/*while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent;    // Get parent object reference
		oLeft += oParent.offsetLeft; // Add parent left position
		o = oParent;
	}*/
	return oLeft;
}

function adjust() {
	var position = "";

	if (navigator.appName == "Microsoft Internet Explorer"){
		position = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
	} else {
		position = window.pageYOffset;
	}
	
	winInnerHeight = (document.documentElement.clientHeight - $('#gallery_popup').height())/2;
	
	var viewableArea = $(window).width();
	var topPopup = Math.floor(winInnerHeight + position);
	/* var leftPopup = Math.floor(getAbsoluteLeft('wide'));*/
	var leftPopup = (viewableArea - 709)/2;

	$('#gallery_popup').css({left: leftPopup+"px", top: topPopup+"px"});	
}

function enlargeImage(popupTitle, imgSrc, altText) {
	
	var titleBar = popupTitle;
	var imgSource = imgSrc;
	var altTxt = altText;
	
	$('.gp_main_image img').hide(); //give it a 'wait loading' period
	
	adjust();
	
	var position = "";
	var winInnerHeight ="";
	
	if (navigator.appName == "Microsoft Internet Explorer"){
		position = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		winInnerHeight = (document.documentElement.clientHeight - $('#gallery_popup').height())/2;
	} else {
		position = window.pageYOffset;
		winInnerHeight = (window.innerHeight - $('#gallery_popup').height())/2;
	}
	
	var viewableArea = $(window).width();
	var topPopup = Math.floor(winInnerHeight + position);
	/* var leftPopup = Math.floor(getAbsoluteLeft('wide'));*/
	var leftPopup = (viewableArea - 709)/2;	
	var blackOverLayYPos = 768 + topPopup;
	
	$('.black_overlay').bgiframe();
	
	$('.gp_header_title').html(popupTitle);
	$('.gp_main_image img').attr("src",imgSource);
	$('.gp_main_image img').attr("alt", altTxt);
	$('.black_overlay').css({height: blackOverLayYPos+"px"});
	$('.black_overlay').fadeIn(900);
	$('#gallery_popup').css({left: leftPopup+"px", top: topPopup+"px"});
	$('#gallery_popup').fadeIn(900);
}

function closePopup() {
	$('.black_overlay').fadeOut("slow");
	$('.gallery_popup').fadeOut("slow");
}

function fadePopup() {
	$("#picturePopup").fadeIn("600");
} 

