// SHOW HIDE LAYER AVAILABLE PRODUCTS
function expandContent(id) {
	if (document.getElementById(id).style.display == 'none') {
		document.getElementById(id).style.display = 'block';
		if(document.getElementById("titles_block"))document.getElementById("titles_block").style.display = 'none';
	} else {
		document.getElementById(id).style.display = 'none';
		if(document.getElementById("titles_block"))document.getElementById("titles_block").style.display = 'block';
	}
}

// TOGGLE ADVANCED SEARCH
function change() {
	if (document.getElementById("showhide").style.display == "none") {
		document.getElementById("showhide").style.display = "inline";
		document.getElementById("thetext").innerHTML = "Simple search";
	} else {
		document.getElementById("showhide").style.display = "none";
		document.getElementById("thetext").innerHTML = "Advanced search";
	}
}

// OLS: scrolling tabs
jQuery(function(){
	//Get our elements for faster access and set overlay width
	var div = jQuery('div#titles_block'),
		ul = jQuery('ul#titles'),
		ulPadding = 15;
	
	//Get menu width
	var divWidth = div.width();

	//Remove scrollbars	
	div.css({overflow: 'hidden'});
	
	//Find last image container
	var lastLi = ul.find('li:last-child');
	
	//When user move mouse over menu
	div.mousemove(function(e){
		//As text is loaded ul width increases,
		//so we recalculate it each time
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});

/**
 * Resize the product highlights so they all have the same height (stretched to the tallest)
 * Attached to the window.load event because in FF the ready event was too early.
 */
jQuery(window).load(function() {
	var tallest = 0;
	jQuery(".block_productsHighlights").each(
		function(){
			var h =jQuery(this).height();
			if(h > tallest) tallest = h;
		}
	);
	jQuery(".block_productsHighlights").height(tallest);
});


/* KaBox v 1.0.0 */
/* Jun 2009 Kahiloa Solutions et Communication */
/* Nikon Europe Project */

// FadeIn Effect

function fadeIn(objId,opacity) {
	if(document.getElementById(objId)){
		if (opacity <= 100) {
			setOpacity(objId, opacity);
			if (document.all) {
				opacity += 20;
			}			
			else {
				opacity += 10;
			}
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 50);
		}
	}
}

function setOpacity(obj, opacity) {
	if (document.all) {
		opacity = ((opacity == 100)?99.999:opacity) - 25;
	} else {
		opacity = ((opacity == 100)?99.999:opacity) - 60;
	}
	// IE 
	document.getElementById(obj).style.filter = "alpha(opacity="+opacity+")";
	// Older Safari, Konqueror
	document.getElementById(obj).style.KHTMLOpacity = opacity/50;
	// Older Firefox
	document.getElementById(obj).style.MozOpacity = opacity/50;
	// Safari, newer Firefox, CSS3
	document.getElementById(obj).style.opacity = opacity/50;
}

function overlayProductView(ImgSrc, elWidth, elHeight, elColor) {
	var KaBoxPosition = document.documentElement.scrollTop;

	// Global container
	var ImageContainer = document.createElement('div');
	ImageContainer.setAttribute('id', 'ContainerImg');
	
	if (document.all) {
		ImageContainer.style.cssText = 'background-color:'+ elColor + '; top:'+ KaBoxPosition +'px';
	} else {
		ImageContainer.setAttribute('style', 'background-color:'+ elColor + '; top:'+ KaBoxPosition +'px');
	}
	
	// Create image
	var ImgContent = document.createElement('img');
	var WindowHeight = document.documentElement.clientHeight;
	
	var x = Math.ceil((WindowHeight - elHeight) / 2);
	y = x + KaBoxPosition;
	if(y < 0) {
		y = 0;
	}	
	if (document.all) {
		ImgContent.style.cssText = 'margin-left:-'+ elWidth/2 +'px ; top:'+ y +'px;' + KaBoxPosition + 'px';
	} else {
		ImgContent.setAttribute('style', 'margin-left:-'+ elWidth/2 +'px ; top:'+ y +'px; height:'+ elHeight +'px; width:'+ elWidth +'px');
	}
	
	ImgContent.setAttribute('src', ImgSrc);
	ImgContent.setAttribute('id', 'ContainerImg2');
	ImgContent.setAttribute('width', elWidth);
	ImgContent.setAttribute('height', elHeight);	
	
	// Including elements
	document.body.appendChild(ImgContent);
	document.body.appendChild(ImageContainer);
	fadeIn('ContainerImg', 0); setOpacity('ContainerImg', 0);
	
	// Hiding body scroll bars
	document.body.style.overflow='hidden';
	
	// Removing box
	function removeBox() {
		document.body.style.overflow='visible';
		document.body.removeChild(ImageContainer);
		document.body.removeChild(ImgContent);
	}
	
	ImageContainer.onclick = removeBox;
}