// JavaScript Document

site={
  config:{
    preloaded_images:['glowa2.jpg', 'ok.png'],
    images_rel_path:"/"
  },
 
  preload_images:function(){
    jQuery.each(site.config.preloaded_images, function(){
      jQuery("<img>").attr('src', site.config.images_rel_path + this);      
    });
  },
  init:function(){
    this.preload_images();
  }
};
	$("document").ready(function(){
			///////////////
			// PRZYCISKI //
			///////////////
			//lookup("to jest testttt");
			
			//hovery

			$("#contact").hover(poswiec, nieswiec);
			$("#hire").hover(poswiec, nieswiec);
			$("#bio").hover(poswiec, nieswiec);
			$("#filesystem").hover(poswiec, nieswiec);
			
			//clicki
			$("#contact").bind("click", pokazdiva);
			$("#hire").bind("click", pokazdiva);
			$("#bio").bind("click", pokazdiva);
			$("#filesystem").bind("click", pokazdiva);
			$("td#title").bind("click", schowajdivy);
			//alert(losujCytat());
			  
	//////////////////////////////
	///// FORMULARZ //////////////
	//////////////////////////////
			  $(function() {
    
    $(".button").click(function() {
      // validate and process form here
      
      $('.error').hide();
  	  var name = $("input#name").val();
  		if (name == "") {
        $("label#name_error").show();
        $("input#name").focus();
        return false;
      }
  		var email = $("input#email").val();
  		if (email == "" || isValidEmailAddress(email)==false) {
        $("label#email_error").show();
        $("input#email").focus();
        return false;
      }
  		var phone = $("textarea#message").val();
  		if (phone == "") {
        $("label#message_error").show();
        $("textarea#message").focus();
        return false;		
      }
      	var capth = $("label#capth_label").text();
		//alert(capth);
		var capthfield = $("input#capth").val();
		var koncowe = lookup(capth);
  		if (capthfield!=koncowe) {
        $("label#capth_error").show();
        $("input#capth").focus();
        return false;
	}
	
	///////////////////////////
	//// WYSLIJ FORMULARZ /////
	///////////////////////////
	 // var dataString = "fromname='"+ name + "'&frommail='" + email + "'&msg='" + message + "'";
   //var dataString = "fromname='"+ name + "'&frommail='" + email + "'&msg='" + phone + "'";
   var dataString = "fromname="+ name + "&frommail=" + email + "&msg=" + phone;
  //alert (dataString);return false;
  $.ajax({
    type: "POST",
    url: "scripts/mail.php",
    data: dataString,
    success: function() {
		
		$("#contact_div").fadeOut(0)
		.html("<br><br><center><img src='images/ok.png'><br><h2>Contact Form Submitted!</h2><h3>I will reply to your message as soon as possible</h3><br><p id='hint'>(you have to refresh this site if you want to send another message)</p></center>")
		.fadeIn(500);
 
    }
  });
  return false;
  
  ///////////////////////
  // KONIEC WYSYLANIA! //
  ///////////////////////
    });
  });
			  
			  
			  
			  
			//$(".button").bind("click", walidacja());
			
			//ukryj formularze
			$(".showdiv").fadeOut(0);
			// $('.error').hide();
			
			///////////////////////
			//animacja poczatkowa//
			///////////////////////
			
			//ukryj elementy
			$("td.menuitem").css("opacity","0.0")
			.css("filter:","alpha(opacity=0)");
			$("td#title").css("opacity","0.0")
			.css("filter:","alpha(opacity=0)");
			$("td.separator").css("opacity","0.0")
			.css("filter:","alpha(opacity=0)");
			$("#head").css("opacity", "0.0")
			.css("margin-left","250")
			.css("filter:","alpha(opacity=0)");
			
			//animuj elementy
			$("#head").animate({left: "100", opacity: 1, filter: "alpha(opacity=100)"},1000, "swing");
			setTimeout(function(){$("td#title")
			.animate({opacity: 1, filter: "alpha(opacity=100)"}, 1000, "swing");},1000);
			setTimeout(function(){$("td.menuitem")
			.animate({opacity: 0.6, filter: "alpha(opacity=60)"}, 1000, "swing");},1500);
			setTimeout(function(){$("td.separator")
			.animate({opacity: 0.6, filter: "alpha(opacity=60)"}, 1000, "swing");},1500);
			
			//$(".showdiv").animate({opacity: 0.1, filter: "alpha(opacity=10)"}, 1, "swing");
			
			
	
		});	
	////////////////////////
	// FUNKCJE PRZYCISKOW //
	////////////////////////
	
	//pokaz okreslony div
	function pokazdiva(evt){
	$('.error').hide();
	var scdiva = "#" + $(this).attr("id") + "_div";
	//alert(scdiva);
	$(".showdiv").fadeOut(100);
	$("#"+this.id+"_div").fadeIn(500).animate({opacity: 1.0, filter: "alpha(opacity=100)"}, 1, "linear")
	$("label#capth_label").text(losujCytat());
	
	}
	function schowajdivy(evt){
	$(".showdiv").fadeOut(100);	
	}
	
	
	
	
	function animuj(obj){
			$("#contact_form").hide();	
		}
	
	
	function poswiec(evt){
			//$(this).css("color", "#FFFFFF");
			$(this).animate({opacity: "1.0", filter: "alpha(opacity=100)"}, 100, "swing");
		}
		
		
	function nieswiec(evt){
			//$(this).css("color", "#CCCCCC");
			$(this).animate({opacity: "0.6", filter: "alpha(opacity=60)"}, 100, "swing");
		}
		
jQuery.fn.delay = function(time,func){
	this.each(function(){
		setTimeout(func,time);
	});
	
	return this;
};

function isValidEmailAddress(emailAddress) {
2.
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
3.
return pattern.test(emailAddress);
4.
}
