



var selectedProdPic = null;
var nrProdPics = 0;

var toProdPic;
var effectIsRunning = false;

jsRules.addRule("#product_thumbs a",function(){
	var pic_id = this.id.replace("thmb_","");
	var related_el = document.getElementById("pic_"+pic_id);
	if (related_el){
		this.relatedEl = related_el;
		this.relatedEl.normalPos = nrProdPics++;
		if (whi.has_class(this,'selected_prod_thumb')){
			selectedProdPic = this.relatedEl;
			selectedProdPic.style.zIndex = 50;
		}else{
			this.relatedEl.style.zIndex = nrProdPics++;
			this.relatedEl.style.display = "none";
		}

		whi.events.addEvent(this,'click',function(e){
			if (this.relatedEl != selectedProdPic){
				toProdPic = this.relatedEl;

				switchProdImg();
			}
		});
	}
});

function switchProdImg(){
	selectedProdPic.style.zIndex = selectedProdPic.normalPos;
	selectedProdPic.style.display = "none";

	toProdPic.style.zIndex = 50;
	toProdPic.style.display = "";

	selectedProdPic = toProdPic;
}




var selectedTabHeader = null;
var selectedTabContent = null;

jsRules.addRule("#tab_header a",function(){
	if (whi.has_class(this,'selected_tab')){
		var tab_id = this.id.replace("tab_","");

		selectedTabHeader = this;
		selectedTabContent = document.getElementById("tab_content_"+tab_id);
	}
	whi.events.addEvent(this,'click',function(e){
		if (this != selectedTabHeader){
			var a;
			var tab_id = this.id.replace("tab_","");
			if (a = document.getElementById("tab_content_"+tab_id)){
				whi.remove_class(selectedTabHeader,'selected_tab');
				whi.remove_class(selectedTabContent,'selected_tab_value');

				selectedTabHeader = this;
				selectedTabContent = a;

				whi.add_class(selectedTabHeader,'selected_tab');
				whi.add_class(selectedTabContent,'selected_tab_value');
			}
		}
	});
});





var prodPicLeft = null;
var prodPicRight = null;
var prodThumbs = null;
var prodInit = false;
var prodNrPics = 0;
var prodPicSize = 77;

function InitProdPics(){
	try{
		prodPicLeft = document.getElementById("prod_pic_left");
		prodPicRight = document.getElementById("prod_pic_right");
		prodThumbs = document.getElementById("thumb_abs");
		prodNrPics = parseInt(document.getElementById("nr_pics").value) || 0;
	
		if (prodPicLeft && prodPicRight && prodThumbs){
			prodInit = true;
		}
		checkDisabledArrows(0,4);
	}catch(e){}
}

function scrollPicImgsLeft(e){
	if (!prodInit) return;
	var lft = parseInt(whi.getStyle(prodThumbs,'left')) || 0;
	var fpic = -(lft / prodPicSize);
	if (fpic>0){
		prodThumbs.style.left = (lft+77)+"px";
		fpic--;
	}
	checkDisabledArrows(fpic,fpic+4);
}

function scrollPicImgsRight(e){
	if (!prodInit) return;
	var lft = parseInt(whi.getStyle(prodThumbs,'left')) || 0;
	var lpic = -(lft / prodPicSize)+4;
	if (lpic<prodNrPics){
		prodThumbs.style.left = (lft-77)+"px";
		lpic++;
	}
	checkDisabledArrows(lpic-4,lpic);
}

function checkDisabledArrows(fpic, lpic){
	if (lpic == prodNrPics){
		whi.add_class(prodPicRight,'diabled_arrow');
	}else{
		whi.remove_class(prodPicRight,'diabled_arrow');
	}
	if (fpic == 0){
		whi.add_class(prodPicLeft,'diabled_arrow');
	}else{
		whi.remove_class(prodPicLeft,'diabled_arrow');
	}

}

jsRules.addRule("#product_thumbs a.prod_pic_left",function(){
	whi.events.addEvent(this,'click',scrollPicImgsLeft);
});
jsRules.addRule("#product_thumbs a.prod_pic_right",function(){
	whi.events.addEvent(this,'click',scrollPicImgsRight);
});

whi.events.addEvent(window,'DOMContentLoaded',InitProdPics);






