$(document).ready(function(){
	$(".arrow").css({margin: 0});
	$(".left_arrow_contaier").hover(leftArrowOver,arrowOut);
	$(".right_arrow_contaier").hover(rightArrowOver,arrowOut);
	
	if($.browser.msie){
		$("img").preloadit({onComplete: function(){
			$(document).pngFix();			
		}});
	}
	$("#bottom_nav").find("a").hover(bottomNavOver, bottomNavOut).each(function(){
		// go through all links and look for current one and set its state
		var $t = $(this);
		
		if(window.location.href.search($t.attr("href")) != -1){
			$t.unbind("mouseout").mouseover();
		}
	});
		
	$window = $(window);
	$main = $("#main");	
	$body = $("body");
	
	$("input").focus(function(){$(this).select();});	
	$("textarea").focus(function(){$(this).select();});	
	$(window).resize(function(){
		var top = ($(this).height() - 710)/2;
		top = (top >= 0)?top:0;
		$main.css({marginTop: top});
		$body.css({backgroundPosition: "center "+top+"px"});
	});
	$(window).resize();	
	
	$(".formSubmit").click(function(){
		$(this).parents("form").submit();
		return false;
	});	
	$("input").keypress(function(e){
		if(e.keyCode === 13){
			$(this).parents("form").submit();
		}
	});
	
	$("#contactForm").submit(contacFormSubmit);
	
});

function contacFormSubmit(){
	var $t = $(this);
	$t.unbind('submit').submit(function(){return false;});;
	$.ajax({
		url: "jax/contactSubmit.php",
		data: $t.serialize(),
		type: "POST",
		success: function(resp){
			$t.unbind('submit').submit(contacFormSubmit);
			alert("Contact submission recieved");
		}			
	});		

	return false;
}

function leftArrowOver(){
	$(this).find("img.arrow").animate({marginRight: 20}, 100, "linear");
}

function arrowOut(){
	$(this).find("img.arrow").animate({marginLeft: 0, marginRight: 0}, 100, "linear");
}

function rightArrowOver(){
	$(this).find("img.arrow").animate({marginLeft: 20}, 100, "linear");
}

function bottomNavOver(){	
	var $t = $(this);
	 
	$t.prev("a").children(".right_inside_shadow").show();
	$t.children(".left_inside_shadow_lighter, .right_inside_shadow_lighter").show();
	
	// if this is the first or last element, show end cap
	if($t.hasClass("first_link")){
		$t.siblings(".left_inside_shadow:first").show();
	}else if($t.hasClass("last_link")){
		$t.siblings(".right_inside_shadow:last").show();
	}
	
	$t.next("a").children(".left_inside_shadow").show();
}

function bottomNavOut(){
	$t = $(this);
	
	$t.prev("a").children(".right_inside_shadow").hide();
	$t.children(".left_inside_shadow_lighter, .right_inside_shadow_lighter").hide();
	
	// if this is the first or last element, show end cap
	if($t.hasClass("first_link")){
		$t.siblings(".left_inside_shadow:first").hide();
	}else if($t.hasClass("last_link")){
		$t.siblings(".right_inside_shadow:last").hide();
	}
	
	$t.next("a").children(".left_inside_shadow").hide();
}
