/**
* @fileoverview ebiz.js: A module used for client specific functionality
*
* This module defines a single symbol named "Venda.ebiz"
* all ebiz utility functions are stored as properties of this namespace
* functions that are spacific this site shoudl be added to this file only.
*/

//Declare namespace for ebiz
Venda.namespace("Ebiz");

/**
 * example function below
 * ebiz.myFunctionname = function(param1, param2) {
 *	..... Place function code here ....
 * }; 
 */

 
$(document).ready(function() {
	if(($(".stepindicators").length) > 0){
		$("#checkout h1").css("margin-bottom","40px");
	}
});


/* ----- Attribute Swatch Function : support up to 2 attributes (ie. colour and size) -----*/

Venda.namespace("Ebiz.AttributeSwatch");
Venda.Ebiz.AttributeSwatch.ListAttributes = new Array();
Venda.Ebiz.AttributeSwatch.filters = new Array();
Venda.Ebiz.AttributeSwatch.existingAttributes = new Array();
Venda.Ebiz.AttributeSwatch.availAttributes = new Array();
Venda.Ebiz.AttributeSwatch.defaultprice = "";
Venda.Ebiz.AttributeSwatch.defaultwasprice = "";
Venda.Ebiz.AttributeSwatch.noswatch = "/content/ebiz/thace5/resources/images/noswatch.gif";

Venda.Ebiz.AttributeSwatch.initListAttributes = function(attrColumn, attrName) {
	for (var eachKey in product.attributeValues) {
		if (typeof product.attributeValues[eachKey] != "function") {
			this.addToListAttributes(attrColumn,product.attributeValues[eachKey].values[attrColumn]);		
		}
	}
	Venda.Ebiz.AttributeSwatch.displayListAttributes(attrColumn, attrName);
	if(this.attrNum==1){Venda.Ebiz.AttributeSwatch.checkAvailOneAttributes(attrColumn, attrName);}
};

Venda.Ebiz.AttributeSwatch.addToListAttributes = function(attrColumn, attrValue) {
	if (!this.isExistInListAttributes(attrColumn,attrValue)) {
		if (!this.ListAttributes[attrColumn]) {
			this.ListAttributes[attrColumn] = new Array();
		}
		this.ListAttributes[attrColumn].push(attrValue);

	}
};

Venda.Ebiz.AttributeSwatch.isExistInListAttributes = function(attrColumn, attrValue) {
	var found = false;
	if (this.ListAttributes[attrColumn]) {
		for (var eachValue in this.ListAttributes[attrColumn]) {
			if (this.ListAttributes[attrColumn][eachValue] == attrValue) { 			
				found = true; 
				break; 
			}
		}
	}
	return found;
};

Venda.Ebiz.AttributeSwatch.createListAttributes=function(attrColumn,attrName,ddObj){
	this.ListAttributes[attrColumn] = new Array();
	for(i=0; i < ddObj.options.length ; i++){
		this.ListAttributes[attrColumn].push(ddObj.options[i].value);
	}
	Venda.Ebiz.AttributeSwatch.displayListAttributes(attrColumn, attrName);
	if(this.attrNum==1){Venda.Ebiz.AttributeSwatch.checkAvailOneAttributes(attrColumn, attrName);}
}

Venda.Ebiz.AttributeSwatch.displayListAttributes = function (attrColumn, attrName){
	var str = "<ul class=attribute_"+attrColumn+">";
	var chkString = "";
	for(var i=0; i < this.ListAttributes[attrColumn].length; i++){
		// if att=color use image for swatch
		if (attrName.toLowerCase() == "colour" || attrName.toLowerCase() == "color") {
			if (!Venda.Ebiz.ProductDetail.allImages[this.ListAttributes[attrColumn][i]] ||  Venda.Ebiz.ProductDetail.allImages[this.ListAttributes[attrColumn][i]].setswatch == "") {

			str += "<li class=\"swatch\"><a class=available id='swatch"+this.ListAttributes[attrColumn][i]+"' onmouseover=\"Venda.Ebiz.AttributeSwatch.showTooltipMessage('swatch"+this.ListAttributes[attrColumn][i]+"');\" onmouseout=\"Venda.Ebiz.AttributeSwatch.hideTooltipMessage();\" onmouseup=\"Venda.Ebiz.AttributeSwatch.hideTooltipMessage();\" onclick=\"Venda.Ebiz.AttributeSwatch.actionSet('"+attrColumn+"','"+this.ListAttributes[attrColumn][i]+"'); Venda.Ebiz.AttributeSwatch.changePrice('attr-sellprice','attr-wasprice'); Venda.Ebiz.ProductDetail.changeSet('"+this.ListAttributes[attrColumn][i]+"'); return false;\"><span class=\"swatchattribute\">"+this.ListAttributes[attrColumn][i]+"</span></a></li>";					
			} else {
				// has swatch image
				str += "<li class=\"swatch\"><a class=available id='swatch"+this.ListAttributes[attrColumn][i]+"' title=\""+this.ListAttributes[attrColumn][i]+"\" onmouseover=\"Venda.Ebiz.AttributeSwatch.showTooltipMessage('swatch"+this.ListAttributes[attrColumn][i]+"');\" onmouseout=\"Venda.Ebiz.AttributeSwatch.hideTooltipMessage();\" onmouseup=\"Venda.Ebiz.AttributeSwatch.hideTooltipMessage();\" onclick=\"Venda.Ebiz.AttributeSwatch.actionSet('"+attrColumn+"','"+this.ListAttributes[attrColumn][i]+"'); Venda.Ebiz.AttributeSwatch.changePrice('attr-sellprice','attr-wasprice'); Venda.Ebiz.ProductDetail.changeSet('"+this.ListAttributes[attrColumn][i]+"'); return false;\"><img class=\"swatchimage\" src=\""+Venda.Ebiz.ProductDetail.allImages[this.ListAttributes[attrColumn][i]].setswatch+"\" alt=\""+this.ListAttributes[attrColumn][i]+"\"></a></li>";
			}

		} else {
			str += "<li><a class=available id='swatch"+this.ListAttributes[attrColumn][i]+"' onmouseover=\"Venda.Ebiz.AttributeSwatch.showTooltipMessage('swatch"+this.ListAttributes[attrColumn][i]+"');\" onmouseout=\"Venda.Ebiz.AttributeSwatch.hideTooltipMessage();\" onmouseup=\"Venda.Ebiz.AttributeSwatch.hideTooltipMessage();\" onclick=\"Venda.Ebiz.AttributeSwatch.actionSet('"+attrColumn+"','"+this.ListAttributes[attrColumn][i]+"'); Venda.Ebiz.AttributeSwatch.changePrice('attr-sellprice','attr-wasprice'); return false;\">"+this.ListAttributes[attrColumn][i]+"</a></li>";		
		}
	}
	str = str + "</ul>";
	document.getElementById("productdetail-"+attrColumn).innerHTML = str;
};


Venda.Ebiz.AttributeSwatch.addFilter = function(attrColumn,attrValue) {
	var filterString="";
	this.filters[attrColumn] = attrValue;
	// clear background alert message
	document.getElementById("alertmessage").className = "normal";
	// update alert message
	Venda.Ebiz.AttributeSwatch.updateMessage();
};

Venda.Ebiz.AttributeSwatch.updateMessage = function(){
	if(this.attrNum==1){
		if(this.filters["att1"]!=""){
			document.getElementById("alertmessage").innerHTML = this.filters['att1'];
		}
	}else{
		if(this.filters["att1"]=="" || this.filters["att1"]==undefined){
			document.getElementById("alertmessage").innerHTML = "<span class=sizeselected>" + this.attrDisplayName[1] + "</span> "+ this.filters['att2'] + " - Please select a " + this.attrDisplayName[0] + ".";
		}else if(this.filters["att2"]=="" || this.filters["att2"]==undefined){
			document.getElementById("alertmessage").innerHTML = this.filters['att1'] + " - Please select a " + this.attrDisplayName[1] + ".";
		}
		if((this.filters["att1"]!="") && (this.filters["att2"]!="") && (this.filters["att1"]!=undefined) && (this.filters["att2"]!=undefined)){
			document.getElementById("alertmessage").innerHTML = this.filters["att1"]+", <span class=sizeselected>" + this.attrDisplayName[1] +"</span> " + this.filters["att2"];
		}
	}
};

Venda.Ebiz.AttributeSwatch.validateAttributes = function(){
	var isSelected = true;
	if(this.attrNum==1){
		if(this.filters["att1"]==undefined || this.filters["att1"]==""){
			document.getElementById("alertmessage").className = "warning";
			isSelected = false;
		}
	}else{
		if(this.filters["att1"]==undefined || this.filters["att2"]==undefined || this.filters["att1"]=="" || this.filters["att2"]==""){
			document.getElementById("alertmessage").className = "warning";
			isSelected = false;
		}
	}
	return isSelected;
};

// Check if attribute exist and has onhand
Venda.Ebiz.AttributeSwatch.checkAvailAttributes = function(attrColumn,attrValue) {
	this.existingAttributes = new Array();
	this.availAttributes = new Array();
	var attrColumnSelect="";
	switch(attrColumn){
		case "att1": attrColumn="att2";attrColumnSelect="att1";break;
		case "att2": attrColumn="att1";attrColumnSelect="att2";break;
	}
	a=0;	
	var str="<ul class=attribute_"+attrColumn+">";
	for (var eachAttrSet in product.attributeValues) {
		if(product.attributeValues[eachAttrSet].values[attrColumnSelect]==attrValue && (product.attributeValues[eachAttrSet].data["atronhand"]>0)){
			this.existingAttributes[a]=product.attributeValues[eachAttrSet].values[attrColumn]; 
			a++;
		}
	}
	this.updateListAttributes(attrColumn);
};

Venda.Ebiz.AttributeSwatch.checkAvailOneAttributes = function(attrColumn, attrName) {
	this.existingAttributes = new Array();
	this.availAttributes = new Array();
	a=0;	
	var str="<ul class=attribute_"+attrColumn+">";
	for (var eachAttrSet in product.attributeValues) {
		if(product.attributeValues[eachAttrSet].data["atronhand"]>0){
			this.existingAttributes[a]=product.attributeValues[eachAttrSet].values[attrColumn]; 
			a++;
		}
	}
	this.updateListAttributes(attrColumn);
};

Venda.Ebiz.AttributeSwatch.updateListAttributes = function(attrColumn) {
	//compare existingAttributes with the full range
	for(i=0; i < this.ListAttributes[attrColumn].length; i++){
		// if there is no any existingAttributes (ie. all out of stock)
		if(this.existingAttributes.length==0){this.availAttributes[i] = false;}
		for(j=0; j < this.existingAttributes.length; j++){			
			if(this.ListAttributes[attrColumn][i]==this.existingAttributes[j]){	
				this.availAttributes[i] = this.existingAttributes[j];
				break;
			}else{
				this.availAttributes[i] = false;
			} 
		}

		if(this.availAttributes[i] !== false){
			if(this.ListAttributes[attrColumn][i]==this.filters[attrColumn]){
				document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).className="selected";
			}else{
				document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).className="available";
			}
		}else{
			document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).className="notavail";
			if(this.attrNum==1){
				// if has only one attr - unclickable out of stock attribute
				document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).attributes["onclick"].value="";
				document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).style.cursor="default";
			}
			if(this.ListAttributes[attrColumn][i]==this.filters[attrColumn]){
				// clear if no combination
				this.filters[attrColumn]="";
				Venda.Ebiz.AttributeSwatch.addFilter(attrColumn,"");
				document.form.elements[attrColumn].value = "";
			}
		}
	}
};


// Highlight selected option
Venda.Ebiz.AttributeSwatch.highlightSelection = function(attrColumn,id){
	for(i=0; i < this.ListAttributes[attrColumn].length; i++){
		if(this.ListAttributes[attrColumn][i] == id){
			document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).className = "selected";

		}else{
			if(document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).className != "notavail"){
				document.getElementById("swatch"+this.ListAttributes[attrColumn][i]).className = "available";
			}
		}
	}
};

Venda.Ebiz.AttributeSwatch.changePrice = function(id, wasid){
	var price = "";
	var wasprice = "";

	if (this.attrNum == 1) {
		for (var eachAttrSet in product.attributeValues) {
			if(product.attributeValues[eachAttrSet].values["att1"]==this.filters["att1"]){
				price = product.attributeValues[eachAttrSet].data["atrsell"];
				wasprice = product.attributeValues[eachAttrSet].data["atrwas"];	
			}
		}	
	} else 	if (this.attrNum == 2) {
		for (var eachAttrSet in product.attributeValues) {
			if(product.attributeValues[eachAttrSet].values["att1"]==this.filters["att1"] && product.attributeValues[eachAttrSet].values["att2"]==this.filters["att2"]){
				price = product.attributeValues[eachAttrSet].data["atrsell"];
				wasprice = product.attributeValues[eachAttrSet].data["atrwas"];	
			}
		}		
	}

	if (price == "") { price = this.defaultprice;}
	if (wasprice == "") { wasprice = this.defaultwasprice; }
	if (price != "") {
		document.getElementById(id).innerHTML = product.labels['currsym'] + price;
	}
	if (wasprice!="" && parseFloat(wasprice)>parseFloat(price)) {	
		document.getElementById(wasid).innerHTML = product.labels['currsym'] + wasprice;	
	}else{
		document.getElementById(wasid).innerHTML = "";
	}
};

Venda.Ebiz.AttributeSwatch.actionSet = function(attrColumn,attrValue){
	document.form.elements[attrColumn].value = attrValue;
	this.addFilter(attrColumn,attrValue);
	this.highlightSelection(attrColumn,attrValue);
	// do checkAvailAttributes only if has more than one attributes
	if(this.attrNum>1){this.checkAvailAttributes(attrColumn,attrValue)}
};







/* ----- Swatch Function : change image and sideview image -----*/

Venda.namespace("Ebiz.ProductDetail");

Venda.Ebiz.ProductDetail.allImages = new Array();
Venda.Ebiz.ProductDetail.config = {
	objDropdown: null,
	objDefaultImage: null,
	objMediumArea: null,
	objLinkArea: null,	
	objSwatchArea: null,
	objSideviewArea: null,
	objProduct: null,
	swatchTitle: "",
	sideviewTitle: "",
	mediumTitle: "",
	viewLargeTitle: "",
	viewLargeText: "",
	loadingHeader: "",
	loadingImage: "",	
	popupHeader: "",
	imageware: ""
};
Venda.Ebiz.ProductDetail.init = function(settings) {
	for (var eachProp in settings) {
		this.config[eachProp] = settings[eachProp];
	}
};
Venda.Ebiz.ProductDetail.loadImage = function(attValue, imgSources) {
	this.allImages[attValue] = imgSources;
};
Venda.Ebiz.ProductDetail.isClickable = function(dataChecking) {

	var able = false;
	if (dataChecking instanceof Array) {
		for (var i = 0; i < dataChecking.length; i++) {
			if (dataChecking[i] != "") {
				able = true;
			}
		}
	}
	return able;
}
Venda.Ebiz.ProductDetail.displaySwatch = function() {	

	var allSwatch = "";

	for (var eachData in this.allImages) {		
		if (this.isClickable(this.allImages[eachData].settsideview) && eachData != "" && this.allImages[eachData].setswatch != "") {
			allSwatch = allSwatch + "<a href=\"#\" onclick=\"Venda.Ebiz.ProductDetail.changeSet('"+eachData+"'); return false;\" title=\""+this.config["swatchTitle"]+" - "+eachData+"\"><img src=\""+this.allImages[eachData].setswatch+"\" alt=\" "+eachData+"\"></a>";
			
		} else if(eachData!="" && this.allImages[eachData].setswatch) {
			allSwatch = allSwatch + "<img src=\""+this.allImages[eachData].setswatch+"\">";		
		}
	}
	
	this.config["objSwatchArea"].innerHTML = allSwatch;
};

Venda.Ebiz.ProductDetail.getImageTag = function(mappingData) {
	var imgTag = "";
	if ((mappingData.imgSource=="")&&(mappingData.noImage !="")) {
		mappingData.imgSource = mappingData.noImage;
	}
	if (mappingData.imgSource!="") {
		imgTag = "<img src=\""+mappingData.imgSource+"\" alt=\""+mappingData.alt+"\">";
	}
	
	if (mappingData.imgChange) {
		imgTag = "<a href=\""+mappingData.imgChange+"\" onclick=\"Venda.Ebiz.ProductDetail.changeMainImage({attValue: '"+mappingData.attValue+"', no: "+mappingData.currentImage+"}); Venda.Ebiz.ProductDetail.changeViewLargeLink({attValue: '"+mappingData.attValue+"', no: "+mappingData.currentImage+"}); Venda.Ebiz.ProductDetail.highlightSideview(this); return false;\" title=\""+mappingData.imgTitle+"\">"+ imgTag + "</a>";
		
	} 		

	if (mappingData.imgPopup) {
		if(!Venda.Ebiz.AttributeSwatch.pdxtImageware){
			// not use image ware
			imgTag = "<a href=\""+mappingData.imgPopup+"\" onclick=\"Venda.Ebiz.ProductDetail.doPopup('"+mappingData.attValue+"',this.href, "+mappingData.currentImage+"); return false;\" title=\""+mappingData.imgTitle+"\">"+ imgTag + "</a>";
		}else{
			// use image ware
			imgTag = this.config["imagewareLink"] + imgTag + "</a>";
		}
	} 			
	
	return imgTag;
};

Venda.Ebiz.ProductDetail.highlightSideview = function (obj){
	$("#productdetail-sideview a").removeClass("selected");
	obj.className = "selected";	
};

Venda.Ebiz.ProductDetail.changeMainImage = function(mappingData) {
	
	var attValue = mappingData.attValue;
	var imgSource = (mappingData.no)? this.allImages[attValue].setmsideview[mappingData.no-1] : this.allImages[attValue].setmedium;
	var imgPopup = (mappingData.no)? this.allImages[attValue].setlsideview[mappingData.no-1] : this.allImages[attValue].setlarge;
	var mainImage = this.getImageTag({
																		noImage: this.config["noImage"]["medium"],
																		imgSource: imgSource,
																		imgPopup: imgPopup,
																		attValue: attValue,
																		alt: "Main image - " + attValue,
																		imgTitle: this.config["mediumsTitle"],
																		currentImage: 0																		
														});	

	this.config["objMediumArea"].innerHTML = "<span></span>" + mainImage;	
	YAHOO.util.Event.addListener(["zoom_img2"],"click", Venda.Widget.Lightbox.showImageware);
};

Venda.Ebiz.ProductDetail.changeViewLargeLink= function(mappingData) {
	var attValue = mappingData.attValue;
	var imgPopup = (mappingData.no)? this.allImages[attValue].setlsideview[mappingData.no-1] : this.allImages[attValue].setlarge;	
	var viewLarge = "";
	if (imgPopup !="") {
		viewLarge = "<div class=\"enlarge\"><a href=\""+imgPopup+"\" onclick=\"Venda.Ebiz.ProductDetail.doPopup('"+attValue+"',this.href, 0); return false;\" title=\""+this.config["viewLargeTitle"]+"\"><img src=\""+ this.config["viewLargeText"] + "\" alt=\""+this.config["viewLargeTitle"]+"\"></a></div>";
	} 
	if(this.config["objLinkArea"]!=null){
		this.config["objLinkArea"].innerHTML = viewLarge;		
	}
};

Venda.Ebiz.ProductDetail.changeSideviewSet = function(attValue) {
	var allSideview = "";
	var n = 0;
	for (var i = 0; i < this.allImages[attValue].settsideview.length; i++) {
		n++;
		if (this.allImages[attValue].settsideview[i] !="") {
			if (this.allImages[attValue].setmsideview[i] !="") {
				allSideview = allSideview + this.getImageTag({
										currentImage: n,
										imgSource: this.allImages[attValue].settsideview[i],
										imgChange: this.allImages[attValue].setmsideview[i],																				
										attValue: attValue,
										alt: "Alternative views - " +attValue,
										imgTitle: this.config["sideviewTitle"]
						});
			} else {
				allSideview = allSideview + this.getImageTag({
										currentImage: n,
										imgSource: this.allImages[attValue].settsideview[i],
										imgChange: "",
										attValue: attValue,
										alt: attValue,
										imgTitle: this.config["sideviewTitle"]																																						
						});				
			}

		}
	}
	this.config["objSideviewArea"].innerHTML = allSideview;
	this.showSideviewImage();
};

Venda.Ebiz.ProductDetail.changeSet = function(attValue) {
	if (this.allImages[attValue]) {
		this.changeMainImage({attValue:attValue});
		// if not tick imageware then use script to change link
		if(!Venda.Ebiz.AttributeSwatch.pdxtImageware){this.changeViewLargeLink({attValue:attValue});}	
		this.changeSideviewSet(attValue);
		
		
	}
};
Venda.Ebiz.ProductDetail.changePopup = function(number,objLink) {
//	$(
	$("#enlargedpopup").attr({src:objLink.href});
	$("#page-popup a").removeClass("selected");
	$(objLink).addClass("selected");	
};

Venda.Ebiz.ProductDetail.loadingPanel = new YAHOO.widget.Panel("loading_panel",  
														{ 
															width:"240px", 
															fixedcenter:true, 
															close:false, 
															draggable:false, 
															zindex:3,
															modal:true,
															visible:false															
														} 
													);	

Venda.Ebiz.ProductDetail.enlargePanel = new YAHOO.widget.Panel("enlarge_panel",  
														{ 
															fade: 0.24,															
															fixedcenter:true,
															draggable: true,
															zindex:4,
															modal:true,
															visible:false															
														} 
													);	


Venda.Ebiz.ProductDetail.createPopupPage = function(attValue,number) {
	var newData = new Array();
	var max = 0;
	var minusNumber = 0;


	if (this.allImages[attValue].setlarge != "") {
		newData[max] = this.allImages[attValue].setlarge;
		max++;
	} else {
		minusNumber = 1;
	}

	for (var i = 0; i < this.allImages[attValue].setlsideview.length; i++) {
		if (this.allImages[attValue].setlsideview[i] != "") {
			newData[max] = this.allImages[attValue].setlsideview[i];
			max++;
		}
	}
	var pageNumber = "";

	if (max > 1) {
		pageNumber = pageNumber + "<div id=\"page-popup\">";
		for (var i = 0; i < max; i++) {
			if (i == (number - minusNumber)) {
				pageNumber = pageNumber + "<a href=\""+newData[i]+"\" onclick=\"Venda.Ebiz.ProductDetail.changePopup("+i+",this); return false;\" class=\"selected\">"+(i+1)+"</a>";			
			} else {
				pageNumber = pageNumber + "<a href=\""+newData[i]+"\" onclick=\"Venda.Ebiz.ProductDetail.changePopup("+i+",this); return false;\">"+(i+1)+"</a>";
			}			
		}
		pageNumber = pageNumber + "</div>";
	}
	return pageNumber;
};
Venda.Ebiz.ProductDetail.setWidthPanel = function (panel, objImage) {
	document.getElementById("tag-invtname").style.display = "inline";
	var widthValue = (objImage.width > (document.getElementById("tag-invtname").offsetWidth + 100)) ? objImage.width + 50: document.getElementById("tag-invtname").offsetWidth + 130;
	panel.cfg.setProperty("width", widthValue + "px");
	document.getElementById("tag-invtname").style.display = "none";			
};
Venda.Ebiz.ProductDetail.doPopup = function(attValue,sLink,number) {
//	var pageNumber = this.createPopupPage(attValue,number);
	var pageNumber = "";	
	
	

	Venda.Ebiz.ProductDetail.loadingPanel.setHeader('<div class="tl"></div><span>'+Venda.Ebiz.ProductDetail.config.loadingHeader+'</span><div class="tr"></div>');
	Venda.Ebiz.ProductDetail.loadingPanel.setBody('<img src="'+Venda.Ebiz.ProductDetail.config.loadingImage+'" />');														
	Venda.Ebiz.ProductDetail.loadingPanel.render(document.body);
	Venda.Ebiz.ProductDetail.loadingPanel.show();

	Venda.Ebiz.ProductDetail.enlargePanel.setHeader('<div class="tl"></div><span>'+Venda.Ebiz.ProductDetail.config.popupHeader+'</span><div class="tr"></div>');		
	Venda.Ebiz.ProductDetail.enlargePanel.setBody( "<div id=\"enlarged\"><img src=\""+sLink+"\" id=\"enlargedpopup\" name=\"enlargedpopup\" onload=\"Venda.Ebiz.ProductDetail.setWidthPanel(Venda.Ebiz.ProductDetail.enlargePanel, this);Venda.Ebiz.ProductDetail.loadingPanel.hide();Venda.Ebiz.ProductDetail.enlargePanel.show();\">"+pageNumber+"</div><a href=\"#\" onClick=\"Venda.Ebiz.ProductDetail.enlargePanel.hide();\">Close</a>");
	Venda.Ebiz.ProductDetail.enlargePanel.render(document.body);	
};

Venda.Ebiz.ProductDetail.preloadImage = function(imgSource) {
	if (imgSource != "") {
		new Image().src = imgSource;
	}
};

Venda.Ebiz.ProductDetail.preloadAllImage = function() {
	for (var eachAttrValue in this.allImages) {
		var allImageData = this.allImages[eachAttrValue];
		
		this.preloadImage(allImageData.setswatch);
		this.preloadImage(allImageData.setmedium);
		this.preloadImage(allImageData.setlarge);
		for (var eachImage in allImageData.settsideview) {
			this.preloadImage(allImageData.settsideview[eachImage]);			
		}
		for (var eachImage in allImageData.setmsideview) {
			this.preloadImage(allImageData.setmsideview[eachImage]);			
		}
		for (var eachImage in allImageData.setlsideview) {
			this.preloadImage(allImageData.setlsideview[eachImage]);			
		}		
	}
};

/* display sideview header if exist */
Venda.Ebiz.ProductDetail.showSideviewImage = function(){
	if(this.config["objSideviewArea"].innerHTML!=""){
		document.getElementById("sideviewheader").innerHTML = "<img src=\""+this.config["sideviewHeader"]+"\" alt=\"Alternative View\">";
		document.getElementById("sideviewheader").className = "";
	}else{
		document.getElementById("sideviewheader").innerHTML = "";
		document.getElementById("sideviewheader").className = "hide";
	}
};

/* Show tooltip for unavailable options */
Venda.Ebiz.AttributeSwatch.showTooltipMessage = function (id){
	if(document.getElementById(id).className=="notavail"){
		document.getElementById("swatchUnavailTooltip").className = "show";
		var posLeft = document.getElementById(id).offsetLeft-(document.getElementById("swatchUnavailTooltip").offsetWidth/2)+(document.getElementById(id).offsetWidth/2);
		var posTop = document.getElementById(id).offsetTop-document.getElementById("swatchUnavailTooltip").offsetHeight-document.getElementById("swatchUnavailTooltipArrow").offsetHeight;
		document.getElementById("swatchUnavailTooltip").style.left = posLeft+"px";
		document.getElementById("swatchUnavailTooltip").style.top = posTop+"px";
	}
}

Venda.Ebiz.AttributeSwatch.hideTooltipMessage = function (){
	document.getElementById("swatchUnavailTooltip").className = "hide";
}


/**
 * @fileoverview Venda.Ebiz.LightBox - Create an inpage popup using an iframe.
 *
 * The information displayed in a div element which is retrieved using AJAX. This information can
 * be a flash movie or a static image.
 * 
 * @requires /venda-support/js/external/yui/build/yahoo-dom-event/yahoo-dom-event.js  
 * @requires /venda-support/js/external/yui/build/dragdrop/dragdrop-min.js
 * @requires /venda-support/js/external/yui/build/container/container-min.js
 * @requires /venda-support/js/external/yui/build/connection/connection-min.js
 * @requires /venda-support/js/ajax.js
 * @requires /venda-support/js/external/swfobject.js
 * @requries resources/css/external/yui/container-skin.css
 * @author Aron San <asan@venda.com>
 */

//create LightBox namespace
Venda.namespace('Ebiz.Lightbox');

/**
 * Stub function is used to support JSDoc.
 * @class Venda.Ebiz.Lightbox
 * @constructor
 */
Venda.Ebiz.Lightbox = function(){
this.create = function(zoomHook, largeImgHook, settingstags) {
	this.settingstags = settingstags;
	this.zoomHook = zoomHook;
	this.largeImgHook = largeImgHook;
	//register listener for objects in 'ids' array
	YAHOO.util.Event.addListener(this.zoomHook,     "click", Venda.Ebiz.Lightbox.showImageware,this.settingstags);
	YAHOO.util.Event.addListener(this.largeImgHook, "click", Venda.Ebiz.Lightbox.showLargeImg,this.settingstags);

	//window onload events
	YAHOO.util.Event.addListener(window, "load", Venda.Ebiz.Lightbox.loadingPanel,this.settingstags);

};

};

/**
 * Temporary container to hold lightbox content - used to get lightbox content dimensions before displaying
 */
Venda.Ebiz.Lightbox.tempContainer = 'tempLightbox';

/**
 * Create a new lightbox object
 * @param {array} 	zoomHook specify which anchors will trigger a flash lightbox
 * @param {array} 	largeImgHook specify which anchors will trigger a image lightbox
 * @param {object} 	settings set settings for lightbox:
 *		- panel settings - draggable:boolean, modal:boolean, fixedCenter: boolean, fade: duration (in a whole or decimial number) 
 * 		- flash settings - flSource:string (url), flContainer:element which will hold the flash, flWidth:String, flHeight:String, flVer:Int , flBgColour:String (hexadecimal)
 * @tags {object} 	tags pass venda tags into js functions (invtname:string, redirect:string, loadmessage:string)
 */	


/**
 * Render flash movie using a flash detection script
 * @param {string} redirectTo a URL to redirect the user to if flash has not been detected successfully
 * @param {string} targetElem a target HTML element for the flash to be placed in
 */
Venda.Ebiz.Lightbox.renderFlash = function(objSettings) {
	var flSettings = objSettings;	
	var flParams = { wmode: 'opaque', bgcolor: flSettings.flBgColour };
	var flVars = { width: flSettings.flWidth, height: flSettings.flHeight, loop: false, quality: 'autohigh'};
	var flAttributes = { id: flSettings.flId }
	swfobject.embedSWF(flSettings.flSource, flSettings.flContainer, flSettings.flWidth, flSettings.flHeight, flSettings.flVer, false, flVars, flParams, flAttributes);	
};

/**
 * Show flash movie
 * A flash movie is displayed in a lightbox where the source of the movie is retrieved using AJAX 
 * @param {event} e used to suppress default link behaviour
 */
Venda.Ebiz.Lightbox.showImageware = function(e,objSettings) {

	YAHOO.util.Event.preventDefault(e); 	// suppress default link behaviour
	Venda.Ebiz.Lightbox.wait.show();
	ajaxFunction(this.href + '&layout=lightbox', Venda.Ebiz.Lightbox.tempContainer, undefined, function() {
		Venda.Ebiz.Lightbox.renderFlash(objSettings);
		Venda.Ebiz.Lightbox.popupContent = document.getElementById(Venda.Ebiz.Lightbox.tempContainer).innerHTML;
		
		//clear content of tempLightbox so that initial positioning of lightbox is not affected
		document.getElementById(Venda.Ebiz.Lightbox.tempContainer).innerHTML = "";
		//calling popupInvtContent() more than onces removes panel settings e.g. draggable 
		if (!Venda.Ebiz.Lightbox.imagePanel) {
			Venda.Ebiz.Lightbox.popupInvtContent(objSettings);
		} else {
	
			Venda.Ebiz.Lightbox.imagePanel.setHeader('<div class="tl"></div><span>'+ objSettings.invtname +'</span><div class="tr"></div>');
			Venda.Ebiz.Lightbox.imagePanel.setBody('<div class="lightBoxContent" class="lightBoxContentExtra">'+Venda.Ebiz.Lightbox.popupContent+'</div>');
		}
			
		//set dimensions - this is required for the lightbox header to appear correctly on IE
		var lightBoxElem = document.getElementById('lightboxcontent_panel');
		Venda.Ebiz.Lightbox.setContentDimensions(lightBoxElem);
		Venda.Ebiz.Lightbox.wait.hide();
		Venda.Ebiz.Lightbox.imagePanel.show();
		YAHOO.util.Event.addListener('closelightbox', 'click', Venda.Ebiz.Lightbox.lightboxHide, Venda.Ebiz.Lightbox.imagePanel, true);
	});
};

/**
 * Show image in lightbox
 * A image is displayed in a lightbox where the source of the image is retrieved using AJAX 
 * @param {event} e used to suppress default link behaviour
 */
Venda.Ebiz.Lightbox.showLargeImg = function(e,objSettings) {
	YAHOO.util.Event.preventDefault(e); // suppress default link behaviour
	Venda.Ebiz.Lightbox.wait.show();
	
	ajaxFunction(this.href + '&layout=lightbox', Venda.Ebiz.Lightbox.tempContainer, undefined, function () {
		var tempLb = document.getElementById(Venda.Ebiz.Lightbox.tempContainer);
		Venda.Ebiz.Lightbox.popupContent = tempLb.innerHTML;
		//clear content of tempLightbox so that initial positioning of lightbox is not affected
		tempLb.innerHTML = "";
		
		//calling popupInvtContent() more than onces removes panel settings e.g. draggable 
		if (!Venda.Ebiz.Lightbox.imagePanel) {
			Venda.Ebiz.Lightbox.popupInvtContent(objSettings);
		} else {
			Venda.Ebiz.Lightbox.imagePanel.setHeader('<div class="tl"></div><span>'+ objSettings.invtname +'</span><div class="tr"></div>');
			Venda.Ebiz.Lightbox.imagePanel.setBody('<div class="lightBoxContent" class="lightBoxContentExtra">'+Venda.Ebiz.Lightbox.popupContent+'</div>');
		}
	
		//set dimensions - this is required for the lightbox header to appear correctly on IE
		var lightBoxElem = document.getElementById('lightboxcontent_panel');
		Venda.Ebiz.Lightbox.setContentDimensions(lightBoxElem);
	
		Venda.Ebiz.Lightbox.wait.hide();
		Venda.Ebiz.Lightbox.imagePanel.show();
		YAHOO.util.Event.addListener('closelightbox', 'click', Venda.Ebiz.Lightbox.lightboxHide, Venda.Ebiz.Lightbox.imagePanel, true);
	});
};

/**
 * Initialise lightbox loading panel
 * Creates a div container which will display a loading message 
 */
Venda.Ebiz.Lightbox.loadingPanel = function (e,objSetting) {
	waitPanel = new YAHOO.widget.Panel("wait_panel", { fixedcenter: true, close: false, draggable: false, modal: true, visible: false, effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration: objSetting.fade} } );  
	waitPanel.setHeader('<div class="tl"></div><span>'+objSetting.loadmessage+'</span><div class="tr"></div>');
	waitPanel.setBody('<span id="loadPanelImg" class="loadPanelImgExtra"></span>');
	waitPanel.render(document.body);
	Venda.Ebiz.Lightbox.wait = waitPanel; //assign so it can be used within the namespace
}

/**
 * Initialise lightbox panel
 * Creates div containers which will display the lightbox contents and renders the lightbox
 */
Venda.Ebiz.Lightbox.popupInvtContent = function(objSettings) {
	var panelSettings = objSettings;
	//create lightbox_holder - this needs to be a direct decendent of the body tag for modal option to work in IE
	var lightboxDiv = document.createElement("div");
	lightboxDiv.setAttribute('id','lightbox_holder');
	document.body.appendChild(lightboxDiv);
	
	// Instantiate a Panel from script
	var imagePanel = new YAHOO.widget.Panel("lightboxcontent_panel", { draggable: panelSettings.drag, modal: panelSettings.modal, fixedcenter: panelSettings.fixedCenter, constraintoviewport:true, visible: false, close: true,  effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration: objSettings.fade} } );
	imagePanel.setHeader('<div class="tl"></div><span>'+ objSettings.invtname +'</span><div class="tr"></div>');
	imagePanel.setBody('<div class="lightBoxContent" class="lightBoxContentExtra">'+Venda.Ebiz.Lightbox.popupContent+'</div>');
	imagePanel.render("lightbox_holder");
	imagePanel.hideEvent.subscribe(Venda.Ebiz.Lightbox.cleanUp);
		
	Venda.Ebiz.Lightbox.imagePanel = imagePanel; //assign so it can be used within the namespace
};

/**
 * Get content dimensions and set CSS style width and height properties accordingly
 * @param {String} lightBoxId	the id of element to get dimensions from
 * @returns {object} dimensions containing width and height
 */
Venda.Ebiz.Lightbox.setContentDimensions = function(lightBoxId) {
	var dimensions = { cWidth: lightBoxId.offsetWidth, cHeight: lightBoxId.offsetHeight }	
	lightBoxId.style.width = dimensions.cWidth;
	lightBoxId.style.height = dimensions.cHeight;
	return dimensions;
}

/**
 * Hide lightbox popup and clean up
 */
Venda.Ebiz.Lightbox.lightboxHide = function(e) {
	YAHOO.util.Event.preventDefault(e); // suppress default link behaviour
	Venda.Ebiz.Lightbox.imagePanel.hide();
	Venda.Ebiz.Lightbox.cleanUp();
};

/**
 * Clean up
 * Remove eventListener and other clean up tasks
 */
Venda.Ebiz.Lightbox.cleanUp = function() {
	YAHOO.util.Event.removeListener('closelightbox', 'click');
	/*remove to aviod js error due to there is no setting params passed for earch object*/
	// hide flash - issue with swfobject detection script
	//var iw = document.getElementById(Venda.Ebiz.Lightbox.settings.flId);
	//if (iw){ iw.style.visibility = 'hidden'; }
};


// NEXT / PREVIOUS 
Venda.namespace('Ebiz.BKList'); 

Venda.Ebiz.BKList = function(){}; 

Venda.Ebiz.BKList.jq = jQuery; 

Venda.Ebiz.BKList.init = function(bklist) { 
this.bklist = bklist; 
}; 

Venda.Ebiz.BKList.jq(document).ready(function() { 
var bklist = Venda.Ebiz.BKList.bklist || Venda.Platform.getUrlParam
(document.location.href, "bklist") || ""; 
if (bklist != "") { 
// change value dropdown 


// change link prev/next page 
Venda.Ebiz.BKList.jq("#buttonsbklist a#previousInvt").attr("href", function() { 
return Venda.Ebiz.BKList.jq(this).attr("href") + "&bklist=" + bklist; 
}); 
Venda.Ebiz.BKList.jq("#buttonsbklist a#nextInvt").attr("href", function() { 
return Venda.Ebiz.BKList.jq(this).attr("href") + "&bklist=" + bklist; 
}); 


} 
});