﻿$(document).ready(function(){
			
	//position
	pos();
	
	//apply effects to text inputs
	$(".input").bind("mouseover", function(){
		$(this).addClass("input_over");
	}).bind("mouseout", function(){
		$(this).removeClass("input_over");
	}).bind("focus", function(){
		$(this).addClass("input_focus");
	}).bind("blur", function(){
		$(this).removeClass("input_focus");
	});
	
	//smooth scrolling (only if not ie6)
	if(!($.browser.msie && $.browser.version<7)){
		
		$('a[href*=#]').click(function() {
			
		 	var $target = $(this.hash);
		 	$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
			
			 	var targetOffset = $target.offset().top;
			 	$('html,body').animate({scrollTop: targetOffset}, 1000);
				return false;
			}
			
		});
	}
	
	//apply generic tooltip
	$('.portfolio img').tooltip({ 
	    delay: 0,
	    track: true, 
	    showURL: false, 
	    bodyHandler: function() { 
	        return $("<img/>").attr("src", this.src); 
	    } 
	});

});


//submit contact form
function submit_form(){
	$("#contact_send").attr("disabled",true);
	var error = false;
	var post_data = "comments=" + escape($("#contact_comments").val());
	var fields =new Array("company","fname","lname", "phone", "email");
	for(i in fields){
		if($("#contact_" + fields[i]).val()==""){
			if(!error){
				$("#contact_"+ fields[i]).focus();
			}
			error = true;
			$("#contact_" + fields[i]).addClass("input_error");
		} else {
			$("#contact_" + fields[i]).removeClass("input_error");
			post_data += "&" + fields[i] + "=" + escape($("#contact_" + fields[i]).val());
		}
	}
	if(error){
		$("#contact_send").attr("disabled",false);
		$("#contact_error").html("please fill in all required fields");
	} else{
		$("#contact_error").html(" ");
		
		$.ajax({
	   type: "POST",
	   url: "send.asp",
	   data: post_data,
	   success: function(msg){
	     	if(msg=="sent"){
	     		$("#section_contact_thanks").fadeIn('slow');
	     		$("#section_contact_form").hide();
	     		//adjust position
	     		posHeight("contact_thanks");
	     		//reset form
	     		document.contactForm.reset();
	     	} else {
	     		alert("sorry, there was an error sending the request. please try again.\n\n" + msg);
	     		
	     	}
	     	$("#contact_send").attr("disabled",false);
	   }
	 });

	}	
	return false;
}

function pos(){
	
	//adjust nav / content
	h = $(window).height();
	w = $(window).width();
	$("#yms_nav").css("left", ((w-920)/2) + "px");
	$("#yms_nav").css("margin-top", ((h-550)/2) + "px").show();
	
	$("#yms_content").css("margin-left", (((w-920)/2) + 500) + "px").show();
	
	//adjust contact form
	posHeight("contact_form");
	
	//adjust about
	posHeight("about");

}

function posHeight(s){
	h = $(window).height();
	sH = $("#section_" + s).css("padding-top", 0).height();
	if(sH<h)
		$("#section_" + s).css("padding-top", ((h-sH)/2)-20 + "px");
}

window.onresize = pos;