	var visiblePage = 'home';
	var showFolio = '';
	var folioBox = '';
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	
	$(document).ready(function() {
		if((version >= 5.5) && (version < 7.0) && (document.body.filters)) {
			fixIEPng();
		}
		$("#wrap").fadeIn(700);
		$("#home").click( function () { togglePage('home'); } );
		$("#about").click( function () { togglePage('about'); } );
		$("#faq").click( function () { togglePage('faq'); } );
		$("#service").click( function () { togglePage('service'); } );
		$("#port").click( function () { togglePage('port'); } );
		$("#contact").click( function () { togglePage('contact'); } );
		$("a.contact").click( function () { togglePage('contact'); } );
		$("#projectms").hover( function () { $("#greyms").fadeOut(250); }, function () { $("#greyms").fadeIn(250); } );
		$("#projectmsw").hover( function () { $("#greymsw").fadeOut(500); }, function () { $("#greymsw").fadeIn(500); } );
		$("#projectrz").hover( function () { $("#greyrz").fadeOut(500); }, function () { $("#greyrz").fadeIn(500); } );
		$("#projectaw").hover( function () { $("#greyaw").fadeOut(500); }, function () { $("#greyaw").fadeIn(500); } );
		$("#projectwi").hover( function () { $("#greywi").fadeOut(500); }, function () { $("#greywi").fadeIn(500); } );
		$("#projectms").click( function () { showBox('ms'); } );
		$("#projectmsw").click( function () { showBox('msw'); } );
		$("#projectrz").click( function () { showBox('rz'); } );
		$("#projectaw").click( function () { showBox('aw'); } );
		$("#projectwi").click( function () { showBox('wi'); } );
		$("#overlay").click( function () { hideBox(); } );
		$("a[class='closebox']").click( function () { hideBox(); } );
		$("a.newWin").click( function () { newWin($(this).attr("href")); return false; } );

		$("#send").click( function () {
			if(checkContactForm() === true) {
				var xdata = 'contact=true';
				xdata += '&name=' + $("input[name='cname']").val();
				xdata += '&email=' + $("input[name='cemail']").val();
				xdata += '&phone=' + $("input[name='cphone']").val();
				xdata += '&company=' + $("input[name='ccompany']").val();
				xdata += '&url=' + $("input[name='curl']").val();
				xdata += '&media=' + $("select[name='media']").val();
				xdata += '&timeline=' + $("select[name='timeline']").val();
				xdata += '&budget=' + $("select[name='budget']").val();
				xdata += '&message=' + $("textarea[name='message']").val();
				$("#contactTable").fadeOut(400);
				$.ajax({
					type: "POST",
					url: "/",
					data: xdata,
					success: function(msg){
						$("#thanks").fadeIn();
						document.forms.contactForm.reset();
					}
				});
			}
		});
	});
	
	function togglePage( page ) {
		if(page != visiblePage) {
			if((page != 'home') && (visiblePage != '')) {
				$("div.hline").fadeIn(500);
			} else if (page == 'home') {
				$("div.hline").fadeOut(500);
			}
			setHeight = ($("#" + page + "Content").height() + 0);
			$("#body").animate( { height: setHeight + 'px'}, 500 );
			if(visiblePage != '') {
				$("#" + visiblePage + "Content").fadeOut(500);
			}
			showContent( page );
		} else if((showFolio != '') && (visiblePage == 'home')) {
			showBox( showFolio );			
		}
		$("#" + page).blur();
	}
	
	function showContent( page ) {
		if(visiblePage != '') {
			$("#" + visiblePage + "Content").hide();
		}
		if(showFolio != '') {
			$("#" + page + "Content").fadeIn("fast");
			setTimeout('showBox("' + showFolio + '");', 1500);
			
			showFolio = '';
		} else {
			$("#" + page + "Content").fadeIn("fast");
		}
		visiblePage = page;
	}
	
	function fixIEPng() {
		$("#headLeft").css({ background: "none", marginTop: "27px", filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/_img/home_head_left.png', sizingMethod='image');" });
		$("#headSplit").css({ background: "none", filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/_img/home_head_split.png', sizingMethod='image');" });
		$("#headRight").css({ background: "none", filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/_img/home_head_right.png', sizingMethod='image');" });
		$(".previewLaunch").css({ background: "none", filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/_img/preview_over.png', sizingMethod='image');" });
	}
	
	function checkContactForm() {
		var err = '';
		if($("input[name='cname']").val() == '') {
			err = 'a contact name.';
		} else if($("input[name='cemail']").val() == '') {
			err = 'a contact email address.';
		} else if($("textarea[name='message']").val() == '') {
			err = 'your message.';
		}
		if(err != '') {
			alert('Please enter ' + err);
			return false;
		}
		return true;
	}

	function showBox( page ) {
		folioBox = page;
		$( '#overlay' ).fadeIn(250);
		center( page );
		return false;
	}

	function hideBox() {
		$( '#hidden' + folioBox ).fadeOut(500);
		$( '#overlay' ).fadeOut(500);
		return false;
	}

	function center( page ) {
		var element = $( '#hidden' + page );
		var w = element.width();
		var h = element.height();
		var winW = document.documentElement.clientWidth;
		var winH = document.documentElement.clientHeight;
		var posX = Math.round((winW / 2) - (w / 2));
		var posY = Math.round((winH / 2) -  (h / 2));
		if(posY < h) {
			posY = 75;
		}
		posY = (posY + document.documentElement.scrollTop);
		tH = ($('#wrap').height() + 200);
		$( '#overlay' ).height( tH );
		element.css({ top: posY + "px", left: posX + "px" });
		element.fadeIn(1000);
	}
	
	function newWin(url) {
		window.open(url);
	}

	
	