
var oMainSlider;
var oMainScroller;

function fPopUp(sHref, nMode){
	var winPopup;
	switch(nMode){
		case 1: // Coupon
			winPopup = window.open(sHref, 'winPopup' + nMode, 'toolbar=no, status=no, menubar=no, scrollbars=yes, movable=yes, resizable=no, width=770, height=540');
			break;
		default:
			winPopup = window.open(sHref, 'winPopup' + nMode, 'toolbar=no, status=no, menubar=no, scrollbars=yes, movable=yes, width=820, height=550');
			break;
	}
}

function fImagePopup(sPath){
	winPopup = window.open('/magazine/ImagePopup.asp?txtImagePath=' + sPath, 'winPopup', 'toolbar=no, status=no, menubar=no, scrollbars=no, movable=yes, resizable=yes, width=300, height=300');
}

function fFitWindowSize(oContainer){
	window.resizeTo(oContainer.offsetWidth + 20, oContainer.offsetHeight + 85);
}

function fCenterWindow(oWindow){
	var nY = new Number((window.screen.availHeight - oWindow.document.body.offsetHeight) / 2 - 200);
	var nX = new Number((window.screen.availWidth - oWindow.document.body.offsetWidth) / 2);
	oWindow.moveTo(nX, nY);
}

var fAlignLayoutDiv = function(sContainerL, sContainerR, nOffset){
	var oLeft = $(sContainerL);
	var oRight = $(sContainerR);
	if(oLeft && oRight){
		var oLeftSize = oLeft.getSize();
		var oRightSize = oRight.getSize();
		if(oLeftSize.size.y >= (oRightSize.size.y - nOffset)){
			oRight.setStyle('height', oLeftSize.size.y + nOffset);
		}else{
			oLeft.setStyle('height', oRightSize.size.y - nOffset);
		}
	}
}

function fSwitch(oElement){
	if(oElement.style.display == 'none'){
		oElement.style.display = 'block';
	}else{
		oElement.style.display = 'none';
	}
}

function fCheckEmail(sEmail){
	var reFilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (reFilter.test(sEmail)){
		return true;
	}else{
		return false;
	}
}

var fSetCookie = function(sCookieName, sValue){
	new Ajax('/Info.asp', {
		method: 'post',
		data: {
			txtActionID: 1,
			txtCookieName: sCookieName,
			txtCookieValue: sValue
		}
	}).request();
}

var fRemoveCookie = function(sCookieName){
	new Ajax('/Info.asp', {
		method: 'post',
		data: {
			txtActionID: 2,
			txtCookieName: sCookieName
		}
	}).request();
}

var fSwitchMusic = function(oSource, sMute, sPlay){
	/*if(oSource.getProperty('isPlaying') == '0'){
		oSource.setProperty('isPlaying', '1');
		oSource.setStyle('backgroundImage', 'url(' + sMute + ')');
		fSetCookie('whitecity_soundImage', '1');
		soundManager.play('MainTrack');
	}else{
		oSource.setProperty('isPlaying', '0');
		oSource.setStyle('backgroundImage', 'url(' + sPlay + ')');
		fSetCookie('whitecity_soundImage', '0');
		soundManager.stop('MainTrack');
	}*/
	
}

var fInitSlider = function(nOffset){
	var oContainer;
	var sContainer;
	var oWrapper = $('divContentWrapper');
	
	if($('divHpContentIsland')){
		sContainer = 'divHpContentIsland';
	}else{
		sContainer = 'divContentIsland';
	}
	oContainer = $(sContainer);
	
	if(oContainer){
		$('divMainSliderKnob').setStyle('display', 'block');
		var oContainerSize = oContainer.getSize();
		var oWrapperSize = oWrapper.getSize();
		//alert(oWrapperSize.size.y);
		if(oWrapperSize.size.y > oContainerSize.size.y){
			oMainScroller = new Fx.Scroll(sContainer, {
				wait: false,
				duration: 1000,
				transition: Fx.Transitions.Quad.easeOut
			});
			oMainSlider = new Slider($('divMainSliderIsland'), $('divMainSliderKnob'), {
				steps: 200,
				mode: 'vertical', 
				onChange: function(nStep){
					var nHeight = oWrapperSize.size.y - oContainerSize.size.y + 20;
					oMainScroller.scrollTo(0, nStep * (nHeight / 200));
				}
			}).set(0);
		}else{
			$('divMainSliderKnob').setStyle('display', 'none');
		}
	}
}

window.addEvent('load', function(){
	fAlignLayoutDiv('divNavIsland', 'divContentIsland', 0);
	if($('divMusic')){
		switch(location.pathname.toLowerCase()){
			case '/projects.asp':
				var nTop = $('divNavIsland').getTop() + 121;
				break;
			default:
				var nTop = $('divNavIsland').getTop() + $('divNavIsland').getSize().size.y - 21;
				break;
		}
		$('divMusic').setStyles({
			'top':  nTop + 'px',
			'left': $('divNavIsland').getLeft()
		});
	}
});

window.addEvent('domready', function(){
	var aNav = ['navHp', 'navProfile', 'navProjects', 'navLinks', 'navAccolades', 'navContact', 'navMap'];
	var sLang;
	
	switch(location.pathname.toLowerCase()){
		case '/':
		case '/default.asp':
			/*if($('divMusic')){
				if($('divMusic').getProperty('isPlaying') == '1'){
					$('divMusic').setStyle('backgroundImage', 'url(/img/stop_g.gif)');
				}else{
					$('divMusic').setStyle('backgroundImage', 'url(/img/play_g.gif)');
				}
			}*/
				
			if($('divNavIsland')){
				sLang = $('divCurLang').innerText;
				$('divNavIsland').setStyle('background', '#005893');
				for(var nIndex = 1; nIndex < aNav.length; nIndex++){
					$('div' + aNav[nIndex]).setStyle('background', 'url(/img/' + sLang + '/' + aNav[nIndex] + '_hp.gif)');
				}
			}
			break;
		default:
			/*if($('divMusic')){
				if($('divMusic').getProperty('isPlaying') == '1'){
					$('divMusic').setStyle('backgroundImage', 'url(/img/stop_b.gif)');
				}else{
					$('divMusic').setStyle('backgroundImage', 'url(/img/play_b.gif)');
				}
			}*/
			
			if($('divNavIsland')){
				sLang = $('divCurLang').innerText;
				$('divNavIsland').setStyle('background', '#767B7F');
				for(var nIndex = 0; nIndex < aNav.length; nIndex++){
					$('div' + aNav[nIndex]).setStyle('background', 'url(/img/' + sLang + '/' + aNav[nIndex] + '.gif)');
				}
			}
			switch(location.pathname.toLowerCase()){
				case '/about.asp':
					//$('divNavProfile').setStyle('background', 'url(/img/' + sLang + '/navProfile_on.gif)');
					break;
				case '/projects.asp':
					$('divNavProjects').setStyle('background', 'url(/img/' + sLang + '/navProjects_on.gif)');
					break;
				case '/links.asp':
					$('divNavLinks').setStyle('background', 'url(/img/' + sLang + '/navLinks_on.gif)');
					break;
				case '/accolades.asp':
					$('divNavAccolades').setStyle('background', 'url(/img/' + sLang + '/navAccolades_on.gif)');
					break;
				case '/contact.asp':
					$('divNavContact').setStyle('background', 'url(/img/' + sLang + '/navContact_on.gif)');
					break;
			}
			break;
	};
});

