preLoadImgs()

if (document.getElementsByTagName && document.createElement){
	document.write('<link rel=\"stylesheet\" type=\"text/css\" href=\"css/javascript.css\" />');
	}
	
var sctColor = new Array();
	
	sctColor[0] = '#03264c';
	sctColor[1] = '#082808';
	sctColor[2] = '#200909';
	sctColor[3] = '#3a4654';

	
$(document).ready(function(){
	loginLink();
	//initWindows();
	
	$('#header_logo').bind('click', function(){
		pageChange('#03264c','index.html');
	});
	
	var currentSelectedTbl = 0;
	var currentCtrl = 0;
	var pagingTbls = new Array();
	var pagingCtrls = new Array();
	
	$('.content_tbl').each(function(i){
		pagingTbls[i] = $(this);
		if ( i == 0 ){
			$(this).fadeIn('slow');
		}
	});
	
	$('.pageCtrlLink').each(function(i){
		pagingCtrls[i] = $(this);
		if(i == 0){
			$(this).css({ color: "#ffffff", background: "#666666" });
		}
		$(this).bind('click', function(){
			$(pagingCtrls[currentCtrl]).css({ color: "", background: "" });
			$(this).css({ color: "#ffffff", background: "#666666" });
			$(pagingTbls[currentSelectedTbl]).fadeOut('fast', function(){
				$(pagingTbls[i]).fadeIn('fast');
			});
			currentSelectedTbl = i;
			currentCtrl = i;
			return false;
		});
	});
	
});

function initSectionIndex(){
	$('#body_container/*').hide();
	slideOpen();
	pageOpen();
}


function slideOpen(){
	if($('body').attr('id')=='index'){
		$('#template_header').SlideInRight('slow','easeout');
		$('#template_footer').SlideInLeft('slow', function(){
			$('#headerNav, #footerNav').fadeIn('slow');
		},'easeout');
	}
}

function pageOpen(){
	setTimeout(function(){
		$('#body_container').slideToggle('slow', function(){
			$('#template_navBar').SlideInDown('slow', function(){
				$('#body_container/*').fadeIn('slow');
			},'bounceout');
		},'easein');
	},800);
}

function initWindows(){
	$('.footerNavLink,.headerNavLink[@id = "langWindow"]').click(function(){
		var window = eval($(this).attr('id'));
		createWindow(window);
		$(window).Draggable({handle: '.appWindowHeader',containment: 'document', zIndex: 1000, opacity: 0.7});
		$(window).find('img.appWindowBarCloseBtn').click( function(){
			removeWindow(window)
		});
		return false;
	});
}

function loginLink(){
	$('#loginWindow').click(function(){
		var destination = getDestination(this);
		var newColor = '#03264c';
		pageChange(newColor,destination);
		return false;
	});
}

function pageChange(newColor,destination){
	$('.appWindow, #popWindow, #sifmaContestImg').fadeOut('fast');
	$('body').animate({backgroundColor: newColor},500,function(){
		$('#template_navBar').SlideOutDown('fast',function(){
			$('#body_container/*').fadeOut('fast');
			$('#body_container').slideToggle('slow',function(){
				window.location = destination;
				
			});
		});
	});
}

function initWindowLinks(obj){
	$(obj).find('a').click(function(){
		var newColor = getSecColor(this);
		var destination = getDestination(this);
		removeWindow(obj);
		pageChange(newColor,destination);
		return false;
	});
}

function removeWindow(obj){
	$(obj).fadeOut('slow',function(){
		$(obj).remove();
	});
}

function createWindow(obj){
	$('body').append($(obj).fadeIn('slow'));
}

function getSecId(obj){
	var secId = $(obj).attr('id').substring(3,4);
	return secId;
}

function getDestination(obj){
	var destination = $(obj).attr('href');
	return destination;
}

function getSecColor(obj){
	var secColor = sctColor[getSecId(obj)-1];
	return secColor;
}

function changePage(obj,secId){
	var destination = $(obj).attr('href');
	var newColor =  sctColor[secId];
	pageChange(newColor,destination);
	return false;
}

function preLoadImgs(){
	var i = 0;
	imgObj = new Image();
	var imgs = new Array();
	imgs[0] = 'images/htmlBack.png';
	imgs[1] = 'images/home.jpg';
	imgs[2] = 'images/aboutVm.jpg';
	imgs[3] = 'images/solutions.jpg';
	imgs[4] = 'images/products.jpg';
	imgs[5] = 'images/contact.jpg';
	imgs[6] = 'images/careers.jpg';
	
	imgs[7] = 'images/containerBack_blue.jpg';
	imgs[8] = 'images/containerBack_DkBlue.jpg';
	imgs[9] = 'images/containerBack_gold.jpg';
	imgs[10] = 'images/containerBack_grey.jpg';
	imgs[11] = 'images/containerBack_tan.jpg';
	imgs[12] = 'images/aboutContainerBack.jpg';
	
	imgs[13] = 'images/appBarBack.jpg';
	imgs[14] = 'images/appBarCloseBtn.jpg';
	imgs[15] = 'images/appWindowBodyBack.gif';
	
	imgCount = imgs.length -1;
	
	for(i=0; i<=imgCount; i++) {
		imgObj.src=imgs[i];
	}
}

function innitContentPaging(){
	var selected = 0;
	var tblNum = $(".content_tbl").length;
}

function initPopWindow(obj){
	$('.popWindowCtrlImg').bind('mouseover', function(){
		popToggle();
	});
}

function popToggle(){
	$('.popWindowContent').slideToggle();
}

var options = {target:'#formMessages',beforeSubmit:validate};

		function showRequest(formData, jqForm, options) { 
    		var queryString = $.param(formData); 
    		alert('About to submit: \n\n' + queryString);
    		return true; 
			} 
		function showResponse(responseText, statusText)  { 
    		alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + '\n\nThe output div should have already been updated with the responseText.'); 
			}
			
function validate(formData, jqForm, options){
	var form = jqForm[0];
	var reg = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	$('#formMessages').empty();
	$('input.formTxtBox').css('background-color','')
	for (var i=0; i < formData.length; i++) {
		if (!formData[i].value) {
				$(form[i]).css('background-color','yellow');
				$('#formMessages').append('<div class="errorMessage">' + form[i].title + ' is a required field.</div>');
			return false;
		} 
	}
	if (!reg.test(form.email.value)){
		$(form.email).css('background-color','yellow');
		$('#formMessages').append('<div class="errorMessage">Please enter a valid email address.</div>');
		return false;
	}
	if (form.email.value != form.emailConfirm.value){
		$(form.emailConfirm).css('background-color','yellow');
		$(form.email).css('background-color','yellow');
		$('#formMessages').append('<div class="errorMessage">Email address does not match</div>');
		return false;
	}
	
	$('#contestForm').fadeOut('slow');
	
}

function sectionClick(linkObj){
	$('#body_container').animate({backgroundImage: 'none' },1000);
	$('.content_tbl:visible,.sectionImg,.pageTitle,#pagingCtrls,.contentLayoutBody_tblCell/h3').fadeOut('fast', function(){
		window.location = getDestination(linkObj);
	});
	return false;
}

function initSection(){
	$('.pageTitle,#pagingCtrls,h3').hide();
	$('.pageTitle,#pagingCtrls,h3').fadeIn('slow');
	setTimeout(function(){
	$('.sectionImg').fadeIn('slow');
	},500);
}








