// JavaScript Document


function adjustments(elem) {
	var windowH = $(window).height();
	var divH = $(elem).outerHeight();
	var newMarginTop;
	
	if(windowH > divH) {
		newMarginTop = (windowH - divH)/2;
		$(elem).css('margin-top',newMarginTop);
	}
}


function getPage(div, req, after) {
	var xmlhttp;
	
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		alert("Your browser does not support AJAX!");
	}
	
	document.getElementById(div).innerHTML = '<img src="../images/ajaxLoader.gif" width="100" height="100" border="0" alt="Loading" />';

	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4) {
			document.getElementById(div).innerHTML=xmlhttp.responseText;
			$('#'+div).jScrollPaneRemove();
			$('#'+div).jScrollPane({
				scrollbarWidth:12
		 	});
		}
	}
	xmlhttp.open("GET",req,true);
	xmlhttp.send(null);
	
	if(after) {
		alert("123");
	}
}

function setRightImage(img,alt) {
	document.getElementById("rightMedia").innerHTML = '<img src="../images/'+img+'" width="312" height="360" border="0" alt="'+alt+'" />';
	$('#rightMedia').jScrollPaneRemove();
	$('#rightMedia').jScrollPane({
		scrollbarWidth:12
	});
}

jQuery.preloadImages = function(){
	for(var i = 0; i<arguments.length; i++){
		jQuery("<img>").attr("src", arguments[i]);
	}
}

$(document).ready(function(){
	var page = $('body').attr('class');
	
	adjustments('#'+page);
	$(window).resize(function(){
		adjustments('#'+page);
	});
	
	$('.navText').live('mouseover',function(){
		$(this).attr('src',"/images/topNav/"+$(this).attr('name')+"_over.png");
	});
	$('.navText').live('mouseout',function(){
		$(this).attr('src',"/images/topNav/"+$(this).attr('name')+".png");
	});
	
	if(page == "site") {
		$('#midContent, #rightMedia').jScrollPane({
			scrollbarWidth:12,
			wheelSpeed: 36
		 });
	}
	else {
		$('#'+page).css("display", "none");
		$('#'+page).fadeIn(1500)
		$('#enterButton').live('click',function(){
			if($.browser.msie && jQuery.browser.version.substr(0,1) <= "6") {
				$('#contact').show();
				alert("Sorry. Your version of Internet Explorer is too old.\nPlease update or use a different browser.");
				window.open('http://www.microsoft.com/windows/internet-explorer/default.aspx','IEWindow');
			}
			else {
				window.location = "./pages/home.php";
			}
		});
	}

$.preloadImages("/images/topNav/ajaxLoader.gif",
					"/images/topNav/contactAlyssa_over.png",
					"/images/topNav/credits_over.png",
					"/images/topNav/home_over.png",
					"/images/topNav/rates_over.png",
					"/images/topNav/resume_over.png");
});
