/*****************************************************
*
*	JavaScript functions for 3rdStreetWorks
*
*
*****************************************************/


function initPage(){

	// bump IE browsers to the old version of the site.
	if($.browser.msie){ document.location = 'old_html/'; }

	hideElement('#loadingPage');
	posElements();
	embedFlash();
	var divID = window.location.href.match(/(.+)#(\w+)/) ? window.location.href.replace(/(.+)#/,'') :'showHome';
	eval(divID+'()');
}

function reInitPage(){
	posElements();
	if(window.location.href.match(/(.*)#showDevelopment/)){
		posSideBar();
	}
}

function posElements(){
	posTopElements();
	posFootElements();
}

function posTopElements(){
	var browserPad = 15;
	var pad = 4;
	var browserWidth = $(window).width()  + browserPad;
	var browserHeight = $(window).height();
	var bluBlockWidth = (browserWidth - $('#topNav').width() - $('#logo').width() - $('#lotus').width() + pad);
	var topNavX = (browserWidth - $('#topNav').width());
	var dateBarWidth = browserWidth;
	
	$('#dateBar').css('width',browserWidth);
	$('#topNav').css('left', topNavX);
	$('#bluBlock').css('width', bluBlockWidth);
	$('#dateBar').css('width', dateBarWidth);
	
}

function posFootElements(){
	var browserPad = 15;
	var margin = 50;
	var browserWidth = $(window).width() + browserPad;
	var browserHeight = $(window).height() + browserPad;
	var footerY = (browserHeight-$('#footer').height());
	var footLeftY = ($('#footer').height()-margin);
	var footerHeight = browserHeight;
	var footRightY = ($('#footer').height()-margin);
	var footRightX = (browserWidth-$('#footRight').width()-margin);
	
	$('#footer').css('top', footerY);
	//$('#footer').css('height', footerHeight);
	
	$('#footLeft').css('top',footLeftY);
	$('#footRight').css('top',footRightY);
	$('#footRight').css('left',footRightX);
}

function posSideBar(){
	var browserPad = 28;
	var pad = 4;
	var margin = 50;
	var margin1 = 40;
	var margin2 = 100;
	var margin3 = 43;
	var margin4 = 4;
	var browserWidth = $(window).width() - browserPad;
	var browserHeight = $(window).height() + browserPad;;
	var sideBarHeight = (browserHeight-$('#topBanner').height()-$('#dateBar').height());
	var sideBarWidth = $('#topNav').width();
	var sideBarX = $('#topNav').css('left');
	var footLeft = ($(window).width()-$('#footRight').width()-$('#devSideBar').width()-margin2);

	$('#devSideBar').css('height', sideBarHeight);
	$('#devSideBar').css('left', sideBarX);
	$('#devSideBar').css('width', sideBarWidth);
	$('#footRight').css('left',footLeft);
	
	//$('#whiteSideBar').css('height', sideBarHeight);
	//$('#whiteSideBar').css('left', sideBarLeft-3);
}

function embedFlash(){
	var flashvars = {};
	var attributes = {};
	var params = {};
	params.menu = "false";
	params.quality = "high";
	params.wmode = "transparent";
	params.allowScriptAccess = "always";
	params.allowfullscreen = false;
	swfobject.embedSWF("images/lotus_header2.swf","lotusflower", "123", "121","9.0.0", false, flashvars, params, attributes);
}

function showSideBar(){
	posSideBar();
	$('#devSideBar').show();
	//$('#whiteSideBar').show();
}

function displayMode(element){

	hideAllElements();
	
	$('#homeNav').css('background-color','#FF9900');
	$('#designNav').css('background-color','#FF9900');
	$('#developmentNav').css('background-color','#FF9900');
	$('#videoNav').css('background-color','#FF9900');
	$('#contactusNav').css('background-color','#FF9900');
	
	if(element.match(/#(cms|ecommerce|flash|webapps|easyReader)/)){
		$('#developmentNav').css('background-color','#FFCC00');
	} else {
		$(element+'Nav').css('background-color','#FFCC00');
	}
	
	showElement(element);
	//posElements();
}

function hideElement(element){
	//$(element).fadeOut('fast');
	$(element).hide();
}

function hideAllElements(){
	hideElement('#home');
	hideElement('#design');
	hideElement('#development');
	hideElement('#video');
	hideElement('#flash');
	hideElement('#cms');
	hideElement('#ecommerce');
	hideElement('#webapps');
	hideElement('#contactus');
	hideElement('#devSideBar');
	hideElement('#whiteSideBar');
	hideElement('#easyReader');
}

function showElement(element){
	$(element).fadeIn('fast');
	//$(element).show();
}

function showHome(){
	displayMode('#home');
}

function showVideo(){
	displayMode('#video');
}

function showDesign(){
	displayMode('#design');
}

function showFlash(){
	displayMode('#flash');
	showSideBar();
}

function showECommerce(){
	displayMode('#ecommerce');
	showSideBar();
}

function showContact(){
	displayMode('#contactus');
}

function showWebApps(){
	displayMode('#webapps');
	showSideBar();
}

function showCMS(){
	displayMode('#cms');
	showSideBar();
}

function showDevelopment(){
	displayMode('#development');
	showSideBar();
}

function submitForm(val){
	//alert(val.indexOf("@",0));
	if (val == ""){
		alert ("Please fill in your e-mail address in the 'From' field");
		return false;
	} else if(val.indexOf("@",0) == -1){
		alert ("Please fill in a valid e-mail address in the 'From' field");
		return false;
	}
	
	document.mailform.submit();
	return;
}	

function numbersonly(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
		if (unicode<48||unicode>57) //if not a number
			return false //disable key press
	}
}
