$(document).ready(function() {
	
		$("#contact, .contact-link").click(function() {
			flipContact();
	    });
	
	     $("#contact").hover(
			  function () {
			    $("#contact img").attr("src","/images/right-blue.gif");
			  }, 
			  function () {
			     $("#contact img").attr("src","/images/right-arrow.gif");
			  }
			);
			
			

	
	bodyId = $("body").attr("id");
	
	switch(bodyId) {
		
	case "home":
	//begin index scripts


	   $(".blue-bar").click(function() {
		   	$(".grey-box").slideUp("fast");
		   	$(this).next(".grey-box").slideDown();
	   });
	   
	   $('#slide').cycle({fx:'fade',delay:0,speed:750,timeout:8000});

	break; // end index scripts
	
	case "resume":
	//begin resume scripts

	$(".exp-rail a").hover(
		  function () {
		  	$(".exp-rail a").removeClass("on");
		    $(this).addClass("on");
		    var name = $(this).attr("name");
		    $(".exp-cont div").hide();
		    $("."+name+"").show();
		  },
		  function () {
		    $(this).removeClass("hover");
		  }
		);

	break; // end resume scripts
	
	case "portfolio":
	//begin portfolio scripts

	  $(".grey-box a").click(function() {
		   	var showClass = $(this).attr("class");
		   	$(".portfolio-container .work").hide();
		   	$(".portfolio-container ."+showClass+"").show();
		   	$(".grey-box a").attr("id","");
		   	$(this).attr("id","on");
	   });


	break; // end portfolio scripts
	
	} //switch
	
	   $("input,textarea").click(function() {
	   		var tempVal = $(this).val();
		   	if (tempVal=="Your Email"||tempVal=="Your Name"||tempVal=="Your Message") $(this).val("");
	   });
	   
	  $("#submit-form").click(function() {
	  	submit({
          'formID' : '1322524991',
          'simple_spc' : '1322524991-1322524991',
          'q1_name' : $("#name").val(),
          'q3_email' : $("#email").val(),
          '&q4_message=' : $("#comment").val()
        });  
		$(".contact-form").html("<p>Thank you for contacting me.<br/> I will return your correspondence as soon as possible</p>");
		window.setInterval('flipContact()', 5000);
		return false;  
	  }); 	   
});

function submit(params) {

      var div = document.createElement('div');
      div.innerHTML = '<iframe height="1" width="1" style="display:hidden"></iframe>';
      document.body.appendChild(div);

      var iframe = div.firstChild;
      var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
      iframeDocument.open();
      iframeDocument.close();

      var form = iframeDocument.createElement('form');
      iframeDocument.body.appendChild(form);
      form.setAttribute('action', 'http://www.jotform.com/submit.php');
      form.setAttribute('method', 'POST');

      for (param in params) {
        var field = iframeDocument.createElement('input');
        field.setAttribute('type', 'hidden');
        field.setAttribute('name', param);
        field.setAttribute('value', params[param]);
        form.appendChild(field);
      }
      form.submit();
    }
    
function flipContact() {
   		if( $(".contact-form").is(":visible")){
		   $("#contact img").attr("src","/images/right-blue.gif");
			   $(".contact-form").slideUp("fast");	   	
		       $("#contact").attr("style","");
		}
		else{
		   $("#contact img").attr("src","/images/down-arrow.gif");
			   $(".contact-form").slideDown("fast");	   	
		       $("#contact").attr("style","color:#669999");
		}
}
