/* Display.js */

var _browser = navigator.userAgent;
var isIE = document.defaultView ? false : true;
var IEvers = isIE ? Number(_browser.substring(_browser.indexOf('MSIE ')+4,_browser.indexOf('MSIE ')+8)) : null;
var IE7 = isIE ? IEvers > 6 ? true : false : false;



function ShowBuyNowSmallOver(whoDiv) {
	whoDiv.parentNode.style.backgroundPosition = "0 -62px";
}

function ShowBuyNowSmallOut(whoDiv) {
	whoDiv.parentNode.style.backgroundPosition = "0 0";
}

function ShowMoreInfoSmallOver(whoDiv) {
	whoDiv.style.backgroundPosition = "0 -20px";
}

function ShowMoreInfoSmallOut(whoDiv) {
	whoDiv.style.backgroundPosition = "0 0";
}

function ShowBuyNowMediumOver(whoDiv) {
	whoDiv.parentNode.style.backgroundPosition = "0 -66px";
}

function ShowBuyNowMediumOut(whoDiv) {
	whoDiv.parentNode.style.backgroundPosition = "0 0";
}

function ShowBuyNowLargeOver(whoDiv) {
	whoDiv.parentNode.style.backgroundPosition = "0 -82px";
}

function ShowBuyNowLargeOut(whoDiv) {
	whoDiv.parentNode.style.backgroundPosition = "0 0";
}

function ShowMoreInfoLargeOver(whoDiv) {
	whoDiv.style.backgroundPosition = "0 -32px";
}

function ShowMoreInfoLargeOut(whoDiv) {
	whoDiv.style.backgroundPosition = "0 0";
}

function ButtonBuyNowSmallOver(whoDiv) {
	whoDiv.style.backgroundPosition = "0 -22px";
}

function ButtonBuyNowSmallOut(whoDiv) {
	whoDiv.style.backgroundPosition = "0 0";
}

function ButtonBuyNowLargeOver(whoDiv) {
	whoDiv.style.backgroundPosition = "0 -25px";
}

function ButtonBuyNowLargeOut(whoDiv) {
	whoDiv.style.backgroundPosition = "0 0";
}

function BuyNowProductOver(whoDiv) {
	whoDiv.style.backgroundPosition = "0 -40px";
}

function BuyNowProductOut(whoDiv) {
	whoDiv.style.backgroundPosition = "0 0";
}

function CheckoutContinueOver(whoDiv) {
	whoDiv.style.backgroundPosition = "0 -35px";
}

function CheckoutContinueOut(whoDiv) {
	whoDiv.style.backgroundPosition = "0 0";
}

function RemoveButtonOver(whoDiv) {
	whoDiv.style.backgroundPosition = "0 -25px";
}

function RemoveButtonOut(whoDiv) {
	whoDiv.style.backgroundPosition = "0 0";
}


/*
 * requires jQuery JavaScript Library
 */

function EqualizeCategoryCells() {
	var ARR = [];
	$('.categoryProductTitle').each( function() {
		ARR.push($(this));
	});
	
	var maxH = 0;
	var rowH = [];
	for(var i=0;i<ARR.length;i++) {
		if(ARR[i].height() > maxH) {
			maxH = ARR[i].height();
		}
		if((i+1) % 3 == 0 && i > 0) {
			rowH.push(maxH);
			maxH = 0;
		}
	}
	if(ARR.length-1 % 3 > 0) {
		rowH.push(maxH);
	}
	
	var currRow = 0;
	var setH = rowH[currRow];
	for(var i=0;i<ARR.length;i++) {
		ARR[i].height(setH);
		if((i+1) % 3 == 0 && i > 0) {
			currRow += 1;
			setH = rowH[currRow];
		}
	}
}


/* >>>>>>>>>>> PRODUCT DETAILS TABS >>>>>>>>>>>>> */

function ShowOverview() {
	var div_tab1 = document.getElementById('tab_overview');
	var div_tab2 = document.getElementById('tab_specs');
	
	var div_cont1 = document.getElementById('OverviewContent');
	var div_cont2 = document.getElementById('SpecificationsContent');
	
	div_tab1.className = 'TabSelected';
	div_tab2.className = 'TabNormal';
	
	div_cont2.style.display = 'none';
	div_cont1.style.display = 'block';
	
	var div_cont3 = document.getElementById('ProductDetailMoreHolder');
	div_cont3.style.display = 'block';
}

function ShowSpecifications() {
	var div_tab1 = document.getElementById('tab_overview');
	var div_tab2 = document.getElementById('tab_specs');
	
	var div_cont1 = document.getElementById('OverviewContent');
	var div_cont2 = document.getElementById('SpecificationsContent');
	
	div_tab1.className = 'TabNormal';
	div_tab2.className = 'TabSelected';
	
	div_cont1.style.display = 'none';
	div_cont2.style.display = 'block';
	
	var div_cont3 = document.getElementById('ProductDetailMoreHolder');
	div_cont3.style.display = 'none';
}

var productTextHeight = 0;

function SetProductText() {
	var textH = $("#OverviewContentText").height();
	var moreBtn = document.getElementById('ProductDetailMore');
	var maxH = isIE ? 180 : 185;
	if(textH > maxH) {
		if(moreBtn) {
			moreBtn.style.display = 'block';
		}
	} else {
		if(moreBtn) {
			moreBtn.style.display = 'none';
		}
	}
	
	// IE6...
	if(isIE && IEvers == 6) {
		var ARR = [];
		$('.MainPanelProduct').each( function() {
			ARR.push($(this));
		});
		
		$('.PromotionBadge').each( function() {
			for(var i=0;i<$(this).context.childNodes.length;i++) {
				if($(this).context.childNodes[i].nodeName.toUpperCase() == "IMG") {
					if($(this).context.childNodes[i].pngSet == true) {
						var pic = String($(this).context.childNodes[i].origPic);
						var imgString = "<img src='" + pic + "' border='0'>";
						$(this).html(imgString);
					}
				}
			}
		});
		
		var ARR_HTML = [];
		for(var i=0;i<ARR.length;i++) {
			ARR_HTML[i] = String(ARR[i].html());
			ARR[i].html("<p></p>");	
		}
		for(var i=0;i<ARR.length;i++) {
			ARR[i].html(ARR_HTML[i]);
		}
	}
}

function ReadMore() {
	var prodTxt = document.getElementById('OverviewContent');
	if(prodTxt) {
		var textH = $("#OverviewContentText").height();
		prodTxt.style.height = textH + 'px';
		var moreBtn = document.getElementById('ProductDetailMore');
		if(moreBtn) {
			moreBtn.style.display = 'none';
		}
	}
}


/* >>>>>>>>>>> MEMBER DETAILS TABS >>>>>>>>>>>>> */

function ShowMemberDetails() {
	var div_tab1 = document.getElementById('tab_member');
	var div_tab2 = document.getElementById('tab_orders');
	var div_tab3 = document.getElementById('tab_favourites');
	
	var div_cont1 = document.getElementById('MembershipContent');
	var div_cont2 = document.getElementById('OrdersContent');
	var div_cont3 = document.getElementById('FavouritesContent');
	
	div_tab1.className = 'TabSelected';
	div_tab2.className = 'TabWithGap';
	div_tab3.className = 'TabNormal';
	
	div_cont3.style.display = 'none';
	div_cont2.style.display = 'none';
	div_cont1.style.display = 'block';
}

function ShowCurrentOrders() {
	var div_tab1 = document.getElementById('tab_member');
	var div_tab2 = document.getElementById('tab_orders');
	var div_tab3 = document.getElementById('tab_favourites');
	
	var div_cont1 = document.getElementById('MembershipContent');
	var div_cont2 = document.getElementById('OrdersContent');
	var div_cont3 = document.getElementById('FavouritesContent');
	
	div_tab1.className = 'TabNormal';
	div_tab2.className = 'TabSelected';
	div_tab3.className = 'TabNormal';
	
	div_cont1.style.display = 'none';
	div_cont3.style.display = 'none';
	div_cont2.style.display = 'block';
}

function ShowFavourites() {
	var div_tab1 = document.getElementById('tab_member');
	var div_tab2 = document.getElementById('tab_orders');
	var div_tab3 = document.getElementById('tab_favourites');
	
	var div_cont1 = document.getElementById('MembershipContent');
	var div_cont2 = document.getElementById('OrdersContent');
	var div_cont3 = document.getElementById('FavouritesContent');
	
	div_tab1.className = 'TabWithGap';
	div_tab2.className = 'TabNormal';
	div_tab3.className = 'TabSelected';
	
	div_cont1.style.display = 'none';
	div_cont2.style.display = 'none';
	div_cont3.style.display = 'block';
}




/* >>>>>>>>>>> CONFIRM >>>>>>>>>>>>> */

function ShowVoucher() {
	var chk = document.getElementById('C_voucherCode');
	var divObj = document.getElementById('VoucherCode');
	if(chk && divObj) {
		if(chk.checked == true) {
			divObj.style.display = 'block';
		} else {
			divObj.style.display = 'none';
		}
	
	}
}

function CheckDelivery() {
	var chk = document.getElementById('AddressSame');
	var divDelivery = document.getElementById('DeliveryAddress');
	
	
	if(chk && divDelivery) {
		if(chk.checked == true) {
			divDelivery.className = 'FormDisabled';
			$("#BillingAddress input, #BillingAddress select").each( function() {
				var divID = $(this).context;
				var divIDdelivery = document.getElementById('P'+divID.id);
				if(divIDdelivery) {
					divIDdelivery.value = divID.value;
				}
			});
			$("#DeliveryAddress input, #DeliveryAddress select").each( function() {
				$(this).context.disabled = true;
			});
		} else {
			divDelivery.className = '';
			$("#DeliveryAddress input, #DeliveryAddress select").each( function() {
				$(this).context.disabled = false;
			});
		}
	}
}


/* >>>>>>>>>>>>>>> FLASH >>>>>>>>>>>>>> */

function flashLoaded(e) {
	//alert(e.success + " : " + e.id + " : " + e.ref);
	if (swfobject.hasFlashPlayerVersion("9.0.0")) {
	  // has Flash
	} else {
	  	var divObj = document.getElementById('FeaturedProductsHolder');
		if(divObj) {
			divObj.innerHTML = "";
			divObj.style.height = "250px";
			divObj.style.textAlign = "center";
			divObj.style.background = "#ffffff url('images/HomeFeaturedBack.gif') no-repeat left top";
			var HTMLstring = "<br><br><img src='images/GetFlash.gif' alt='' width='360' height='100' border='0' vspace='30'>";
			HTMLstring += "<br><a href='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' target='_blank'>Click here to get Adobe Flash Player plug-in</a>";
			divObj.innerHTML = HTMLstring;
		}
	}
}



/* >>>>>>>>>>> REFINED-BY >>>>>>>>>>>>> */

function RefinementHover(whoDiv) {
	whoDiv.className = "RefinedButtonOver";
}

function RefinementOut(whoDiv) {
	whoDiv.className = "RefinedButtonEnd";
}

