/* KaBox v 1.0.0 */
/* Jun 2009 Kahiloa Solutions et Communication */
/* Nikon Europe Project 
UDAPTE: 2009-10-26
*/

// FadeIn Effect

function fadeIn(objId,opacity) {
	if(document.getElementById(objId)){
		//obj = document.getElementById(objId);
		//alert(obj);
		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 ProductTourViewer(FlashSrc, elWidth, elHeight, elColor) {
	
	var KaBoxPosition = window.pageYOffset || document.documentElement.scrollTop;

	// Global container
	var FlashContainer = document.createElement('div');
	FlashContainer.setAttribute('id', 'ContainerFlash');
	
	if (document.all) {
		FlashContainer.style.cssText = 'background-color:'+ elColor + '; top:'+ KaBoxPosition +'px';
	}
	
	else {
		FlashContainer.setAttribute('style', 'background-color:'+ elColor + '; top:'+ KaBoxPosition +'px');
	}
	
	// Create Applet
	var FlashContent = document.createElement('object');
	
	var WindowHeight = document.documentElement.clientHeight;
	
	var x = Math.ceil((WindowHeight - elHeight) / 2);
	y = x + KaBoxPosition;
		if(y < 0) {
			y = 0;
		}		

	if (document.all) {
		FlashContent.style.cssText = 'margin-left:-'+ elWidth/2 +'px ; top:'+ y +'px;' + KaBoxPosition + 'px';
	}
	else {
		FlashContent.setAttribute('style', 'margin-left:-'+ elWidth/2 +'px ; top:'+ y +'px; height:'+ elHeight +'px; width:'+ elWidth +'px');
	}	
	
	FlashContent.setAttribute('type', 'application/x-shockwave-flash');
	FlashContent.setAttribute('data', FlashSrc);
	FlashContent.setAttribute('id', 'ContainerFlash2');
	FlashContent.setAttribute('width', elWidth);
	FlashContent.setAttribute('height', elHeight);
		
	// Create params
	var paraMovie = document.createElement('param');
	paraMovie.setAttribute('name', 'movie');
	paraMovie.setAttribute('value', FlashSrc);

	var paraWmode = document.createElement('param');
	paraWmode.setAttribute('name', 'wmode');
	paraWmode.setAttribute('value', 'transparent');
	
	var paraQuality = document.createElement('param');
	paraQuality.setAttribute('name', 'quality');
	paraQuality.setAttribute('value', 'high');

	// Including elements
	FlashContent.appendChild(paraMovie);
	FlashContent.appendChild(paraWmode);
	FlashContent.appendChild(paraQuality);

	document.body.appendChild(FlashContainer);
	
	// If IE...
	if (document.all && !window.opera)
	{
		
		var flashHTML = '<object type="application/x-shockwave-flash" width="' + elWidth + 
						'" height="' + elHeight + '" data="' + FlashSrc + '" id="ContainerFlash2">' + 
						'<param name="movie" value="' + FlashSrc + '" /></object>';
		
		FlashContainer.innerHTML = flashHTML;

		if (document.all) {
			ContainerFlash2.style.cssText = 'margin-left:-'+ elWidth/2 +'px ; top:'+ y +'px;' + KaBoxPosition + 'px';
		}
		else {
			ContainerFlash2.style = 'margin-left:-'+ elWidth/2 +'px ; top:'+ y +'px; height:'+ elHeight +'px; width:'+ elWidth +'px';
		}
	}
	// Any other browser...
	else
	{
		document.body.appendChild(FlashContent);
	}

	fadeIn('ContainerFlash', 0); setOpacity('ContainerFlash', 0);

	
	// Hiding body scroll bars
	document.body.style.overflow='hidden';
	
	// Removing box
	function removeBox() {
		document.body.style.overflow='visible';
		document.body.removeChild(FlashContainer);
		
		// If IE...
		if (document.all && !window.opera)
		{
			FlashContainer.innerHTML = "";
		}
		// Any other browser...
		else 
		{
			document.body.removeChild(FlashContent);
		}
	}

	FlashContainer.onclick = removeBox;

}