$(document).ready(function(){

	/* AJAX Forms */	
	$('#contact_form').ajaxForm({  
	  target:"#contact_form .temp",   
	  beforeSubmit:function(){ 
	     $("#contact_form .msg").html("Sending...");
	  },
	   success:function(rtn) { 
	    if(rtn=="success"){
	      $("#contact_form .contact_form").hide();
	      $("#contact_form .msg").html("<p>Thank you for your note.</p>");
	      $("#contact_form .msg").fadeIn();
	    } else {
	      $("#contact_form .msg").html(  $("#contact_form .temp #content ul").html() );
	      $("#contact_form .temp").empty();
	    }
	   } 
	});
	
	$('#search_form').submit(function(){
		var num = $('#search_form #keywords').val().length;
		if (num == 0){
			$("#search_form .msg").html("Please enter a search term.");
			return false;
		}		
		if (num < 3){
			$("#search_form .msg").html("Search terms must be at least 3 characters.");
			return false;
		}
	});	
	
	/* Press Summaries Slideshow */
	var i    = 1;
	$('.press_summaries_prev, .press_summaries_next').click(function(e) {
          e.preventDefault();
         
          var type = $(this).attr('class');
          var a    = $('.press_summary');

          a.hide();
	
          if(type == 'press_summaries_prev') {
               if(i > 1) {
                    i--;
               }
          }
          if(type == 'press_summaries_next') {
	           if(i < a.length) {
	                i++;
	           }
          }
          
          $("#press_summary_" + i).show();     
     });   
     
    /* Home page */
    $(window).resize(function() {
 		 resizeHomePage();
	});     
 	resizeHomePage();
 		      
	function resizeHomePage(){
		var div = $(".home-half");
	 	var img = $(".home-half img");
	 	
	 	//reset
	 	img.removeClass();
	 	img.css("margin-top", "0px");
		
		if ( div.width()/div.height() > 2.24 ){
			 img.addClass("to-width");
			 if (img.height() > div.height()){
			 	img.css("margin-top", (div.height()-img.height())/2);
			 }
		} else {
			 img.addClass("to-height"); 
		};
	};
	
	
	/* Info template */
	$(window).resize(function() {
 		 checkLeftQuotes();
	});
	checkLeftQuotes();
	
	function checkLeftQuotes(){
		$(".left-quote").each(function(){
			if ($(window).width() < 1400){
				$(this).addClass("quote-override");
			} else {
				$(this).removeClass("quote-override");			
			}
		});
	};
	
	
	
    /* Portfolio detail page */
    $(window).resize(function() {
 		 resizePortfolioDetail();
	});
 	resizePortfolioDetail();
 		      
	function resizePortfolioDetail(){
		$("header").each(function(){
			if ($(window).width() < 960){
				$(this).addClass("header-960");
				$('.portfolio-page #container').addClass("portfolio-page-cont-overflow");
			} else {
				$(this).removeClass("header-960");
				$('.portfolio-page #container').removeClass("portfolio-page-cont-overflow");			
			}
		});
	};
	


$('#keywords').setDefaultValue();


});

