/* slider demo: http://www.aldenta.com/examples/script.aculo.us/slider-scrollbar.html */

var fadeOutDetails = 0.2;

/* Adapted from the functions posted on QuirksMode. */
function viewportDimension() {
	var vpWidth = self.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);
	var vpHeight = self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
	return { width: vpWidth, height: vpHeight };
}

function inlinePopupDisplay(winId,elemPos) {
	// Define container objects
	var winObj = $("specs_popup");
	//var scrollObj = $("specs_popup_scrollbar");
	var selectedPopup = $(winId);
	var viewportDims = viewportDimension(); // The Screen

	// Define content objects
	var header = winObj.getElementsBySelector("h2");
	var specs_header = selectedPopup.getElementsBySelector(".specs_header");
	var copy = $("specs_scrollarea");
	var specs_copy = selectedPopup.getElementsBySelector(".specs_copy");

	// hide scrollbar (we'll redisplay it if necessary)
	//scrollObj.style.visibility = "hidden";

	// Populate content
	header[0].innerHTML = specs_header[0].innerHTML;
	copy.innerHTML = "<div id=\"specs_popup_copy_height\">"+specs_copy[0].innerHTML+"</div>";

	// Position popup
	var winPos = Position.cumulativeOffset(elemPos);
	winPos[1] += 15;
	var pagePos = Position.page(elemPos);
	if ((viewportDims.height - pagePos[1]) < 140) winPos[1] -= 250;
	winObj.style.left = ""+winPos[0]+"px";
	winObj.style.top = ""+winPos[1]+"px";

	// Position scroll bar and display the scrollbar (if necessary)
	copy.scrollTop = 0; // resets any previous scrolling
	new Effect.Appear(winObj, {	duration: fadeOutDetails, afterFinish: function() {
		
		/* Do not display Script.aculo.us scrollbar in Safari
		if (navigator.appVersion.indexOf("Safari") > 0) {
			copy.style.width = "292px";
			copy.style.overflow = "auto"; */
		/* Display the scrollbar for other browsers, but only if the copy is longer than the copy window 
		} else if ($("specs_popup_copy_height").getHeight() > copy.getHeight()) {
			scrollObj.style.left = ""+(winPos[0]+301)+"px";
			scrollObj.style.top = ""+(winPos[1]+44)+"px";
			specs_slider.setValue(0);
			scrollObj.style.visibility = "visible";
		}*/
	} });
}

function inlinePopupHide() {
	new Effect.Fade("specs_popup", { duration: fadeOutDetails });
	$("specs_popup_scrollbar").style.visibility = "hidden";
}

var specs_slider = null;

function initSpecsPopup() {
	selectSpecs("summary");
	specs_slider = new Control.Slider('specs_popup_scrollbar_handle', 'specs_popup_scrollbar_track', {
		axis: 'vertical',
		onSlide: function(v) { scrollVertical(v, $('specs_scrollarea'), specs_slider);  },
		onChange: function(v) { scrollVertical(v, $('specs_scrollarea'), specs_slider); }
	});
}