	//Products Navigation functions
	var clipLeft = 0;
	var clipWidth = 712;
	var clipBottom = 89;
	var leftper = 0;
	var lyrwidth = 0;
	var time,amount,theTime,theHeight,DHTML;

	function init()	{	
		DHTML = (document.getElementById || document.all || document.layers)
		
		if (!DHTML) return;
		
		var x = new getObj('nav_prod_th');

		lyrwidth = x.obj.offsetWidth;

		var clipstring = 'rect('+0+'px,'+clipWidth+'px,'+89+'px,'+clipLeft+'px)';
		x.style.clip = clipstring;
		
		adjustScrollProduct();
	}
	
	function adjustScrollProduct() {
		var url = parent.location.href;
		
		var prdPos = 0;
		if (noReset){
			if(url.indexOf('&productpos')>= 0) {
				prdPos = parseInt(url.slice(url.indexOf('&productpos')+12,url.length));
				if(isNaN(prdPos))
					prdPos = 0;
			}
		}
		thelayer = new getObj("nav_prod_th");
		clipWidth = clipWidth+prdPos;
		clipLeft = clipLeft+prdPos;
		leftper = -prdPos;
		clipstring = 'rect('+0+'px,'+clipWidth+'px,'+89+'px,'+clipLeft+'px)';	
		thelayer.style.clip = clipstring;
		thelayer.style.left = leftper + 'px';
		thelayer.style.right = clipWidth + 'px';
	}

	function scrollayer(layername,amt,tim) {
		if (!DHTML) return;
		thelayer = new getObj(layername);
		if (!thelayer) return;
		amount = amt;
		theTime = tim;
		realscroll();
	}

	function realscroll() {
		if (!DHTML) return;
		clipLeft += amount;
		clipWidth += amount;
		leftper -= amount;

		if (clipLeft < 0 )//|| clipLeft > lyrwidth)
		{
			clipLeft -= amount;
			clipWidth -= amount;
			leftper += amount;
			return;
		}
		if (clipWidth > lyrwidth + 10)
		{	
			clipLeft -= amount;
			clipWidth -= amount;
			leftper += amount;
			return;
		}
		

		clipstring = 'rect('+0+'px,'+clipWidth+'px,'+89+'px,'+clipLeft+'px)';
		thelayer.style.clip = clipstring;
		thelayer.style.left = leftper + 'px';
		thelayer.style.right = clipWidth + 'px';
		time = setTimeout('realscroll()',theTime);
	}
	
	function stopScroll() {
		if (time) clearTimeout(time);
	}

	function getObj(name) {
		if (document.getElementById)
		{
			this.obj = document.getElementById(name);
			this.style = document.getElementById(name).style;
		}
		else if (document.all)
		{
			this.obj = document.all[name];
			this.style = document.all[name].style;
		}
		else if (document.layers)
		{
		 	this.obj = document.layers[name];
		 	this.style = document.layers[name];
		}
	}

	//Personalized functions to filter / list products and subcategories

	function listProducts() {
		var url = parent.location.href;
		if(url.indexOf('&productpos'))
	  		var prdId = url.slice(url.indexOf('productid')+10,url.indexOf('&productpos'));
		else
			var prdId = url.slice(url.indexOf('productid')+10,url.length);

		document.getElementById("nav_prod_th").style.width = visibleCount() * 68 + "px";
		document.getElementById('nav_prod').style.width = '706px';
		document.getElementById("prod_content").innerHTML = "";
		
		var action = document.getElementById("pageProdClick").value;
		
		for(i = 0; i < arrProductShot.length; i++){
			if (String(arrProductShot[i].product_id) == String(prdId) && arrProductShot[i].product_shot.indexOf('prod_th_h_') == -1)
				 arrProductShot[i].product_shot = arrProductShot[i].product_shot.replace('prod_th_','prod_th_h_');
			
			if (arrProductShot[i].display)
				document.getElementById("prod_content").innerHTML += "<li><a href=\"javascript:getUrlProduct('" + action + "?productid=" + arrProductShot[i].product_id + "')\" onMouseOver=\"toolTip('" + arrProductShot[i].product_name + "','" + arrProductShot[i].description + "',this,'2')\"><img src=\"images/illustrations/" + arrProductShot[i].product_shot + "\" width=\"68\" alt=\"\" /></a></li>";
		}
		
		if (visibleCount() > 0){

	                  document.getElementById('nav_arrow_l').innerHTML = "<a href=\"javascript:void(0);\" onmouseover=\"scrollayer('nav_prod_th',-10,100);\" onmouseout=\"stopScroll();\"><img src=\"images/illustrations/arrow_l.gif\" alt=\"\" title=\"\" /></a>";
	
        	          document.getElementById('nav_arrow_r').innerHTML = "<a href=\"javascript:void(0);\" onmouseover=\"scrollayer('nav_prod_th',10,100);\" onmouseout=\"stopScroll();\"><img src=\"images/illustrations/arrow_r.gif\" alt=\"\" title=\"\" /></a>";

	        } else {

	                  document.getElementById('nav_arrow_l').innerHTML = "";
	
        	          document.getElementById('nav_arrow_r').innerHTML = "";

        	}
	
		init();
		noReset = false;
	}
	
	function getProducts(selectedCategory, selectedSubcategory){
		//reset scroll
		clipLeft = 0;
		clipWidth = 712;
		clipBottom = 89;
		leftper = 0;
		lyrwidth = 0;

		//reset categories and products
		if (!noReset){
			for ( var prod = 0; prod < arrProductShot.length; prod++) 
				arrProductShot[prod].display = false;
		}
			
		for ( var cat = 1; cat <= arrCategory.length; cat++ ){
			var arrSubcategory = eval("arrSubcategory" + String(parseInt(cat)-1));
			for (var i = 0; i < arrSubcategory.length; i++)
				arrSubcategory[i].selected = false;
		}

		//set up selected subcategory
		var selectedCount = 0;
		for ( var cat = 1; cat <= arrCategory.length; cat++ ){
			if ( String(arrCategory[cat-1].id) == String(selectedCategory) ){
				arrCategory[cat-1].selectedSubcategory = selectedSubcategory;
			}
			
			if (String(arrCategory[cat-1].selectedSubcategory) != "null")
				selectedCount += 1;
		}

		//filter products according to the selection
		if ( selectedCount != 0 ){
			for ( var prod = 0; prod < arrProductShot.length; prod++) {
				var matchCount = 0;
				for ( var cat = 0; cat < arrCategory.length; cat++ ){
					if ( String(arrProductShot[prod].subcategories).indexOf(String("," + arrCategory[cat].selectedSubcategory) + ",") >= 0)
						matchCount += 1;
				}
				if ( matchCount == selectedCount )
					arrProductShot[prod].display = true;
			}
		}
		
		//set up enabled subcategories according to filtered products
		for (var i = 0; i < arrSubcategory0.length; i++){
			arrSubcategory0[i].selected = !hasProductByFilter(arrSubcategory0[i].id, arrCategory[1].selectedSubcategory, arrCategory[2].selectedSubcategory);
			if ( arrCategory[0].selectedSubcategory == arrSubcategory0[i].id )
				arrSubcategory0[i].selected = true;
		}

		for (var i = 0; i < arrSubcategory1.length; i++){
			arrSubcategory1[i].selected = !hasProductByFilter(arrCategory[0].selectedSubcategory, arrSubcategory1[i].id, arrCategory[2].selectedSubcategory);
			if ( arrCategory[1].selectedSubcategory == arrSubcategory1[i].id )
				arrSubcategory1[i].selected = true;
		}

		for (var i = 0; i < arrSubcategory2.length; i++){
			arrSubcategory2[i].selected = !hasProductByFilter(arrCategory[0].selectedSubcategory, arrCategory[1].selectedSubcategory, arrSubcategory2[i].id);
			if ( arrCategory[2].selectedSubcategory == arrSubcategory2[i].id )
				arrSubcategory2[i].selected = true;
		}

		//just print
		for ( var cat = 1; cat <= arrCategory.length; cat++ ){
			var elementId = document.getElementById("nav_section_" + cat);
			var elementId_txt = document.getElementById("nav_section_" + cat + "_txt");
			var elementId_cat = document.getElementById("nav_section_" + cat + "_cat");
			var elementId_box = document.getElementById("nav_section_" + cat + "_box");
			var elementReset = document.getElementById("box_" + cat + "_resetLink");
			var arrSubcategory = eval("arrSubcategory" + String(parseInt(cat)-1));
			var enclose_begin_cat = "<li class=\"prod_cat\">";
			var enclose_begin_box = "<li>";
			var enclose_end = "</li>";
			var content_cat = "";
			var content_box = "";
			
			for (var i = 0; i < arrSubcategory.length; i++){
				if ( arrSubcategory[i].selected == false ){
					content_box += enclose_begin_cat + "<a href=\"javascript:getProducts('" + cat + "', '" + arrSubcategory[i].id + "');\">" + arrSubcategory[i].description + " &raquo;</a>" + enclose_end;
					content_cat += enclose_begin_box + "<a href=\"javascript:getProducts('" + cat + "', '" + arrSubcategory[i].id + "');\">" + arrSubcategory[i].description + " </a>" + enclose_end;
				} else {
					content_box += enclose_begin_cat + "<span style='padding-left:20px;'>" + arrSubcategory[i].description + " &raquo;</span>" + enclose_end;
					content_cat += enclose_begin_box + "<span class='disabled_sub_cat'>" + arrSubcategory[i].description + " </span>" + enclose_end;
				}
				if ( arrSubcategory[i].id == arrCategory[cat-1].selectedSubcategory ){
					if (elementReset) elementReset.style.visibility = "visible";
					if (elementId) {
						elementId.style.backgroundColor = '#8375C4';
						elementId.style.backgroundImage = 'url(images/illustrations/close_nav_section.gif)';
					}
					if (elementId_txt) elementId_txt.innerHTML = arrSubcategory[i].description;
				}
			}
			
			if (elementId_cat) elementId_cat.innerHTML = content_cat;
			if (elementId_box) elementId_box.innerHTML = content_box;
		}
		
		listProducts();
	}
	
	function hasProductByFilter(subcategory_id0, subcategory_id1, subcategory_id2) {
		var totalMatch = 0;
		if (String(subcategory_id0) != "null") totalMatch += 1;
		if (String(subcategory_id1) != "null") totalMatch += 1;
		if (String(subcategory_id2) != "null") totalMatch += 1;
		
		for ( var prod = 0; prod < arrProductShot.length; prod++) {
			var matchCount = 0;
			for ( var cat = 1; cat <= 3; cat++ ){
				if ( String(arrProductShot[prod].subcategories).indexOf("," + eval("subcategory_id" + String(parseInt(cat) - 1)) + ",") >= 0){
					matchCount += 1;
				}
			}
			
			if ( matchCount == totalMatch ) {
				return true;
			}
		}
	}
	
	function resetCategory(category_id){
		var elementReset = document.getElementById("box_" + category_id + "_resetLink");
		var nav_section = document.getElementById("nav_section_" + category_id);
		var nav_section_txt = document.getElementById("nav_section_" + category_id + "_txt");
		
		arrCategory[category_id-1].selectedSubcategory = null;
		if (elementReset) elementReset.style.visibility = "hidden";
		if (nav_section) {
			nav_section.style.backgroundColor = '';
			nav_section.style.backgroundImage = '';
		}
		if (nav_section_txt) nav_section_txt.innerHTML = arrCategory[category_id-1].description;

		getProducts();
	}
	
	function visibleCount(){
		var count = 0;
		for ( var prod = 0; prod < arrProductShot.length; prod++) 
			if ( arrProductShot[prod].display )	
				count += 1;
		
		return(count);
	}
	
	
	function getUrlProduct(string) {
			thelayer = new getObj("nav_prod_th");
			posX = thelayer.style.left;
			if (posX.indexOf('-') >= 0)
				posX = posX.substring(posX.indexOf('-')+1, posX.length);
			if (posX.indexOf('px'))
				posX = posX.substring(0, posX.indexOf('px'));
			var url = string + "&productpos=" + posX;

			window.location.href = url;
	}

	function toggleProd(id,state,mgTop){
		if(state == 'show'){
			document.getElementById(id).style.display = 'block'
			document.getElementById('nav_cat').style.left = "186px";
			document.getElementById('nav_cat').style.marginTop = mgTop;
		} else {
			document.getElementById(id).style.display = 'none'
		}
	}

	function addEvent(obj, evType, fn){
		if (obj.addEventListener){
			obj.addEventListener(evType, fn, true);
			return true;
		} else if (obj.attachEvent){
			var r = obj.attachEvent("on"+evType, fn);
			return r;
		} else {
			return false;
		}
	}
