// browser detection
var firefox = navigator.userAgent.indexOf("Firefox") != -1
var explorer = navigator.userAgent.indexOf("MSIE") != -1
var explorer7 = navigator.userAgent.indexOf("MSIE 7.0") != -1
var netscape = navigator.userAgent.indexOf("Netscape") != -1
var safari = navigator.userAgent.indexOf("Safari") != -1
var opera = navigator.userAgent.indexOf("Opera") != -1
var camino = navigator.userAgent.indexOf("Camino") != -1
var macintosh = navigator.platform.indexOf("Mac") != -1

// return browser's is
function whoAreYou() {
	if (firefox) { alert('firefox'); }
	if (explorer) { alert('explorer'); }
	if (opera) { alert('opera'); }
	if (netscape) { alert('netscape'); }
	if (safari) { alert('safari'); }
	if (camino) { alert('camino'); }
	/*
		if (macintosh) { alert('macintosh'); }
		else { alert('pc'); }
	*/
}

// open a popup centered in user's screen
function popCenter(page, name, width, height, scroll) {
	 var winLeft = (screen.width - width) / 2;
	 var winTop = (screen.height - height) / 2;
	 winprops = 'width=' + width + ',height=' + height + ',left=' + winLeft + ',top=' + winTop + ',scrollbars=' + scroll + ',';
	 win = window.open(page, name, winprops);
	 win.focus();
}

// rollover for .gif images (3 states: of, on, in)
function changeGifImage(which) { 
	var myImgSrc = document.getElementById(which);
	var buttonStatus = myImgSrc.src.substring(myImgSrc.src.length -6, myImgSrc.src.length -4);
	if (buttonStatus == 'of') myImgSrc.src = myImgSrc.src.substring(myImgSrc.src.length -6,0) + 'on.gif';
	else if (buttonStatus == 'in') myImgSrc.src = myImgSrc.src.substring(myImgSrc.src.length -6,0) + 'in.gif';
	else myImgSrc.src = myImgSrc.src.substring(myImgSrc.src.length -6,0) + 'of.gif';
}

// rollover for .jpg images (3 states: of, on, in)
function changeJpgImage(which) { 
	var myImgSrc = document.getElementById(which);
	var buttonStatus = myImgSrc.src.substring(myImgSrc.src.length -6, myImgSrc.src.length -4);
	if (buttonStatus == 'of') myImgSrc.src = myImgSrc.src.substring(myImgSrc.src.length -6,0) + 'on.jpg';
	else if (buttonStatus == 'in') myImgSrc.src = myImgSrc.src.substring(myImgSrc.src.length -6,0) + 'in.jpg';
	else myImgSrc.src = myImgSrc.src.substring(myImgSrc.src.length -6,0) + 'of.jpg';
}

// show & hide a layer
function layerVisibility(layerId) {
	if (document.getElementById([layerId]).style.display == "none") {
		document.getElementById([layerId]).style.display = "block";
	}
	else { document.getElementById([layerId]).style.display = "none"; }
}

// show a layer
function showLayer(layerId) {
	document.getElementById([layerId]).style.display = "block";
}

// hide a layer
function hideLayer(layerId) {
	document.getElementById([layerId]).style.display = "none";
}

// change an iframe's src
function changeFrame(frameId, url) {
	var oIframe = document.getElementById([frameId]);
	oIframe.src = url;
}

// embed a flash file
function insertFlash(name, width, height, flashvars) {
	document.write('<object width="' + width + '" height="' + height + '" id="' + name + '" align="top" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value="/resources/flash/' + name + '.swf" />\n');
	document.write('<param name="menu" value="false" />\n');
	document.write('<param name="flashvars" value="' + flashvars + '">\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="scale" value="noscale" />\n');
	document.write('<param name="salign" value="t" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	document.write('<param name="bgcolor" value="#000000" />\n');
	document.write('<embed width="' + width + '" height="' + height + '" name="' + name + '" src="/resources/flash/' + name + '.swf" flashvars="' + flashvars + '" menu="false" align="top" quality="high" scale="noscale" salign="t" wmode="transparent" bgcolor="#000000" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>\n');
}

// embed the background flash (ice) ONLY
function insertBg(name, width, height, flashvars) {
	document.write('<object width="' + width + '" height="' + height + '" id="bkg" align="top" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<param name="movie" value="/resources/flash/' + name + '.swf" />\n');
	document.write('<param name="menu" value="false" />\n');
	document.write('<param name="flashvars" value="' + flashvars + '">\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="scale" value="noscale" />\n');
	document.write('<param name="salign" value="t" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	document.write('<param name="bgcolor" value="#000000" />\n');
	document.write('<embed width="' + width + '" height="' + height + '" name="bkg" src="/resources/flash/' + name + '.swf" flashvars="' + flashvars + '" menu="false" align="top" quality="high" scale="noscale" salign="t" wmode="transparent" bgcolor="#000000" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>\n');
}

// print the page
function printMe() { window.print(); }

// navigate into the flash
function moveIt(id) { top.document.bkg.SetVariable("btnAction", id); }

// navigate through the site
var activeSection = '';
function mainNav(name, id) {
	top.changeFrame('contentFrame','/' + name + '/');
	top.hideLayer('contentLayer');
	if (activeSection != '') { 
		top.hideLayer(activeSection + 'Caps');
		top.hideLayer(activeSection + 'Shadow');
	}
	if (name != 'profile') {
		top.showLayer(name + 'Caps');
		top.showLayer(name + 'Shadow');
		activeSection = name;
	}
	else {
		top.showLayer('homeCaps');
		top.showLayer('homeShadow');
		activeSection = 'home';
	}
	moveIt(id);
	if (id != '7') {
		top.showLayer('logo');
		top.hideLayer('entrepot');
		//setTimeout("top.showLayer('contentLayer');",1000);
	}
	else {
		top.hideLayer('logo');
		top.showLayer('entrepot');
	}
}

// detect the plateform to display hidden layers
function displayContent(layerId) {
	if (macintosh) { showLayer(layerId); }
	else { Effect.Appear(layerId); }	
}

// empty textbox value on first click
function changeValueOnFirstFocus(oTxt) { if(oTxt.defaultValue == oTxt.value) { oTxt.value = ''; } }

// control flash environment sound
var action = "0";
function soundController() { 
	if (action == "0") { 
		top.document.bkg.SetVariable("flashSound", action);
		action = "1"; 
	}
	else { 
		top.document.bkg.SetVariable("flashSound", action);
		action = "0"; 
	}
}

// go to profile if not logged or caps if logged
var userStatus = false;
function statusLookup(status) { 
	if (status == "False") {
		mainNav('profile','1');
	}
	else {
		mainNav('caps','2');
	}
}
function newprofile() {
	//alert(111);
	mainNav('profile','1');
}

// show the user as if logged in
function showLoggedIn(user) {
	userStatus = 'True';
	top.document.getElementById('uc_mainNav_uc_login_ph_userNotLogged').style.display = "none";
	top.document.getElementById('divUserLoginInfo').innerHTML = user;
	top.showLayer('uc_mainNav_uc_login_ph_userLogged');
}

// detect the plateform to display hidden layers
function displayCaps(layerId,imgUrl,goldUrl) {
	if (document.getElementById(layerId).src != goldUrl) { document.getElementById(layerId).src = imgUrl; }
	if (macintosh) { showLayer(layerId); }
	else { Effect.Appear(layerId); }	
}

// rotating images on the homepage
var imgId = '0';
function showImage() {
	var tmpImgId;
	tmpImgId = eval(imgId) + 1;
	if (imgId != '16') {
		if (imgId != '0') { hideLayer('viContestFP' + imgId); }
		displayContent('viContestFP' + tmpImgId);
		imgId = tmpImgId;
	}
	else {
		hideLayer('viContestFP' + imgId);
		displayContent('viContestFP1');
		imgId = '1';
	}
	setTimeout("showImage();",5000);
}

// verify that a page is fully loaded
function loadSite() {
	if (explorer) { Event.observe(window, 'load', loadComplete); }
	else { Event.observe(window, 'load', loadComplete()); }
}
		
// initialize, setup & control the custom scrollbars
function initScrollLayers(popupId) {
	var sectionScroll = new dw_scrollObj('page_' + popupId, 'scroll_' + popupId, null);
	sectionScroll.setUpScrollbar('dragBar_' + popupId, 'track_' + popupId, 'v', 0, 0);
	
	if (window.addEventListener) 
		window.addEventListener('DOMMouseScroll', function(event) { wheel(event, popupId) }, false);
		window.onmousewheel = document.onmousewheel = function(event) { wheel(event, popupId) };
	
	if(document.addEventListener) {
		document.addEventListener("keydown", function(event) { detectEvent(event, popupId) }, true);
		document.addEventListener("keyup", function(event) { stopScrollNow(popupId) }, true);
	}
	else {
		document.attachEvent("onkeydown", function(event) { detectEvent(event, popupId) });
		document.attachEvent("onkeyup", function(event) { stopScrollNow(popupId) });
	}
}

function wheel(event, popupId) {
	var delta = 0;
	if (!event) { event = window.event; }
	if (event.wheelDelta) {
		delta = event.wheelDelta/120;
		if (window.opera) { delta = -delta; }
	} 
	else if (event.detail) { delta = -event.detail/3; }
	if (delta) { handle(delta, popupId); }
	if (event.preventDefault) {	event.preventDefault(); }
	event.returnValue = false;
}

function handle(delta, popupId) {
	if (delta > 0) { 
		origin = 'mouseWheel1';
		dw_scrollObj.initScroll('page_' + popupId, 'up', 2400, popupId);
	}
	if (delta < 0) { 
		origin = 'mouseWheel1';
		dw_scrollObj.initScroll('page_' + popupId, 'down', 2400, popupId);
	}
}

function detectEvent(e, popupId) {
	var evt = e || window.event;
	if (evt.keyCode == '38') { 
		dw_scrollObj.initScroll('page_' + popupId, 'up', null, popupId);
	}
	else if (evt.keyCode == '40') { 
		dw_scrollObj.initScroll('page_' + popupId, 'down', null, popupId);
	}
}

function stopScrollNow(popupId) {
	dw_scrollObj.stopScroll('page_' + popupId);
}