// JavaScript Document
function PushImage(instance){
	this.instance = instance;
	this.timeoutId;
	this.elt;
}

PushImage.prototype.show = function(oElt, src){
	clearTimeout(this.timeoutId);
	if(!this.elt){
		this.elt = document.createElement('img');
		document.body.appendChild(this.elt);
	} else {
		this.elt.style.display = 'block';
	}
	var pos = Utilities_getAbsolutePosition(oElt);
	this.elt.src = src;
	this.elt.style.left = pos.left;
	this.elt.style.top = pos.top;
	this.elt.className = 'product_roll';
	this.elt.over = false;
	this.elt.owner = this;
	this.elt.onmouseover = function(){
		this.over = true;
	}
	this.elt.onmouseout = function(){
		this.over = false;
		this.owner.hide();
	}
}

PushImage.prototype._hide = function(){
	if(this.elt && !this.elt.over){
		this.elt.style.display = 'none';
	}
}
PushImage.prototype.hide = function(){
	if(this.instance){
		clearTimeout(this.timeoutId);
		this.timeoutId = setTimeout(this.instance + '._hide()', 100);
	}
}

function showImage(id, src){
	var elt = document.getElementById(id);
	if(elt)elt.src = src;
}

function pagination(id, fName, n){
	var elt = document.getElementById(id);
	var dts = elt.getElementsByTagName('dt');
	for(var i = 0; i < dts.length; i++){
		var dt = dts[i];
		if(i + 1 == n){
			dt.className = 'selected';		
			dt.innerHTML = n;
		} else {
			dt.className = '';
			dt.innerHTML = '<a href="javascript:' + fName + '(' + (i + 1) + ')">' + (i + 1) + '</a>';
		}
	}
}
function showProductImage(n){
	pagination('productImageTabs', 'showProductImage', n);
	showImage('productImage', _productImages[n - 1]);
}

function showProductTip(n){
	pagination('productTipTabs', 'showProductTip', n);
	var elt = document.getElementById('productTip');
	elt.innerHTML = _productTips[n - 1][0];
	var img = document.getElementById('productTipImage');
	if(_productTips[n - 1][1]){
		img.src = _productTips[n - 1][1];
	} else {
		img.src = '/images/spacer.gif';
	}
}

function applyPromoCode(){
	var code = document.promoCode.code.value;
    //alert(code);
	if(code){
		var url = getPageURL('/basket', 'action=applypromocode&code=' + code);
        //alert(url);
		window.location.href = url;
	}
}
