/* KaBox v 1.0.0 */
/* Jun 2009 Kahiloa Solutions et Communication */
/* Nikon Europe Project 
UDAPTE: 2009-10-26
*/

// FadeIn Effect

var currentURL = location.pathname;
var productTourAnalyticsURL = currentURL.replace(/^\/(\w{5})\/.*\/(.*)$/g,"$1/product_tour/$2");

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 YouTubeProductTourViewer(videoId){
	var url = "http://www.youtube.com/v/" + videoId + "?fs=1&amp;hl=en_US&amp;rel=0&amp;autoplay=1&amp;hd=1";
	ProductTourViewer(url,'700', '419', 'white');

}

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 Appelet
	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('classid', 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000');
	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');

	var embedMovie = document.createElement('embed');
	embedMovie.setAttribute('src', FlashSrc);
	embedMovie.setAttribute('type', 'application/x-shockwave-flash');
	embedMovie.setAttribute('allowscriptaccess', 'always');
	embedMovie.setAttribute('allowfullscreen', 'true');	
	embedMovie.setAttribute('width', elWidth);
	embedMovie.setAttribute('height', elHeight);
	// Including elements
	// FlashContent.appendChild(embedMovie);
	FlashContent.appendChild(paraMovie);
	FlashContent.appendChild(paraWmode);
	FlashContent.appendChild(paraQuality);

	var FlashContent2 = document.createElement('div');

	var FlashContent3 = document.createElement('div');

	if (document.all) {
		FlashContent2.style.cssText = 'position:relative';
		FlashContent3.style.cssText = 'left:'+ elWidth/2 +'px ; top:'+ y +'px;' + KaBoxPosition + 'px; position:absolute;z-index:100';
	}
	else {
		FlashContent2.setAttribute('style', 'position:relative');
		FlashContent3.setAttribute('style', 'left:'+ elWidth/2 +'px ; top:'+ y +'px; height:'+ elHeight +'px; width:'+ elWidth +'px; position:absolute;z-index:100');
	}

	FlashContent3.innerHTML = '<object type="application/x-shockwave-flash" data="'+FlashSrc+'" width="'+elWidth+'" height="'+elHeight+'"><param name="movie" value="'+FlashSrc+'"/><param value="high" name="quality"/><param value="transparent" name="wmode"/></object>';
//	FlashContent2.appendChild(FlashContent3);	

	document.body.appendChild(FlashContainer);
	document.body.appendChild(FlashContent3);
	
	fadeIn('ContainerFlash', 0); setOpacity('ContainerFlash', 0);

	// Send Analytics Data (Open Product Tour)
	_gaq.push(['_trackPageview', productTourAnalyticsURL]);

	
	// Hiding body scroll bars
	document.body.style.overflow='hidden';
	
	// Removing box
	function removeBox() {
		document.body.style.overflow='visible';
		document.body.removeChild(FlashContainer);
		document.body.removeChild(FlashContent3);
	}
	
	FlashContainer.onclick = removeBox;


}
