//Popup Tool Tip
var mouseX;
var mouseY;
function InitMousePosition()
{
	Event.observe(document, "mousemove", GetMousePosition, false); 
}

function GetMousePosition(e)
{
	mouseX = Event.pointerX(e);
    mouseY = Event.pointerY(e);
}

function ShowToolTip(name, className, msg)
{
	var id = "toolTip" + name;
	var popup = $(id);
	if(popup == null)
	{
		popup = document.createElement("div");
		popup.setAttribute("id", id);
		document.body.appendChild(popup);
	}
	popup.className = className;
	popup.innerHTML = msg;
	popup.style.position = "absolute";
	popup.style.left = (mouseX + 10) + "px";
	popup.style.top = (mouseY + 10) + "px";
	Element.show(popup);
}

function HideToolTip(name)
{
	var id = "toolTip" + name;
	var popup = $(id);
	Element.hide(popup);
}

function ShowPopup(id, className, pid)
{
	var popup = $(id);
	if(popup != null)
	{
		//Move popup to body element so that position is correct
		if(popup.parentNode != document.body)
		{
			popup.parentNode.removeChild(popup);
			document.body.appendChild(popup);
		}
		
		var frameshopLink = $("aIneligibleForFramingFrameshopLink");
		frameshopLink.setAttribute("href", "Frameshop2.aspx?pid=" + pid);
	
		popup.className = className;
		popup.style.position = "absolute";
		popup.style.left = (mouseX + 10) + "px";
		popup.style.top = (mouseY + 10) + "px";
		Element.show(popup);
	}
}

function HidePopup(id)
{
	var popup = $(id);
	Element.hide(popup);
}

//Filmstrip
function FilmstripShowView(showId)
{
	FilmstripShowView2(showId, true);
}

function FilmstripShowView2(showId, clearPager)
{	
	//Clear interval
	if(clearPager && filmstripInterval != null)
	{
		window.clearInterval(filmstripInterval);
	}
	
	//Get object to show, do nothing if visible
	var showObj = $(showId);
	if(Element.visible(showObj))
		return ;
		
	//Hide all elements in parent
	var parent = showObj.parentNode;
	for(i=0; i<parent.childNodes.length; i++)
	{
		if(parent.childNodes[i] != showObj && Element.visible(parent.childNodes[i]))
			Effect.Fade(parent.childNodes[i], { duration:0.25, from:1.0, to:0.0 });		
	}	
	
	//Show showObj
	if(!Element.visible(showObj))
		Effect.Appear(showObj, { duration:0.50, from:0.0, to:1.0 });
}

var filmstripInterval = null;
function FilmstripSetInterval(parentId, delay)
{
	filmstripInterval = window.setInterval("FilmstripShowNext('" + parentId + "')", delay);
}

function FilmstripShowNext(parentId)
{	
	//Find object to show
	var parent = $(parentId);
	var showObj = null;
	for(i=0; i<parent.childNodes.length; i++)
	{
		//Get next object after the first visible object
		//Get the first object if the last objet is the visible one
		if(Element.visible(parent.childNodes[i]))
		{
			if(i<parent.childNodes.length - 1)
				showObj = parent.childNodes[i+1];
			else
				showObj = parent.childNodes[0];
		}
		
		//Use first obj if no object found
		if(showObj == null)
			showObj = parent.childNodes[0];
	}
	
	//Show object
	FilmstripShowView2(showObj.id, false);
}

//ProductConfig
//Define ProductConfigHelper class
function ProductConfigHelper(pcPID, pcProductConfigurationType, pcCanvasBarType, pcCanvasStretchType, pcCanvasFinishType, pcCanvasMaterialType, pcCanvasPaintedSideColor, pcPlaqueBoardType, pcPlaqueColorType, pcCroppingOptions)
{
	this.pid = pcPID;
	this.productConfigurationType = pcProductConfigurationType;
	this.canvasBarType = pcCanvasBarType;
	this.canvasStretchType = pcCanvasStretchType;
	this.canvasFinishType = pcCanvasFinishType;
	this.canvasMaterialType = pcCanvasMaterialType;
	this.canvasPaintedSideColor = pcCanvasPaintedSideColor;
	this.plaqueBoardType = pcPlaqueBoardType;
	this.plaqueColorType = pcPlaqueColorType;
	this.croppingOptions = pcCroppingOptions;
}
ProductConfigHelper.prototype.toQueryString = function()
{
	//Make sure all properties are not null
	if(this.pid == null) this.pid = -1;
	if(this.productConfigurationType == null) this.productConfigurationType = -1;
	if(this.canvasBarType == null) this.canvasBarType = -1;
	if(this.canvasStretchType == null) this.canvasStretchType = -1;
	if(this.canvasFinishType == null) this.canvasFinishType = -1;
	if(this.canvasMaterialType == null) this.canvasMaterialType = -1;
	if(this.canvasPaintedSideColor == null || this.canvasPaintedSideColor == "") this.canvasPaintedSideColor = "none";
	if(this.plaqueBoardType == null) this.plaqueBoardType = -1;
	if(this.plaqueColorType == null) this.plaqueColorType = -1;
	if(this.croppingOptions == null) this.croppingOptions = -1;
	
	//Build querystring
	var qs =	"pid=" + this.pid + "&" +
				"c=" + this.productConfigurationType + "&" +
				"cb=" + this.canvasBarType + "&" +
				"cs=" + this.canvasStretchType + "&" +
				"cf=" + this.canvasFinishType + "&" +
				"cm=" + this.canvasMaterialType + "&" +
				"cp=" + this.canvasPaintedSideColor + "&" +
				"pb=" + this.plaqueBoardType + "&" +
				"pc=" + this.plaqueColorType + "&" +
				"co=" + this.croppingOptions;
	return qs;
}
