$(document).ready(function() {
	/* Tabs */
	var aboutHeight = $("div#about").height();
	var portfolioHeight = $("div#portfolio").height();
	var socialHeight = $("div#social").height();
	var sluzbyHeight = $("div#sluzby").height();
	var kontaktHeight = $("div#kontakt").height();
	var referenceHeight = $("div#reference").height();
	$("div.content").height(0);
	
	var current = "about";
	$("div#" + current).height( eval(current+"Height") );
	
	$("a.tablink").click( function() {
		$("a.tablink").removeClass("selected");
		$(this).addClass("selected");
		$("div#" + current).animate({ height: 0 }, 500, function() { $(this).hide(); });
		var toShow = $(this).attr("rel");
		if( toShow == "contact" ) toAdd = 30;
		else toAdd = 0;
		$("div#" + toShow).show().animate({ height: eval(toShow+"Height") + toAdd }, 500);
		current = toShow;
		return false;
	});
  	
	/* Portfolio */
	$("a.break").click( function() { return false; });
	$("a[rel='lightbox']").colorbox();
	$("#slider").scrollable({ size: 1, clickable: false, keyboard: false });	
	
	/* Social Networks */
	$('#socialnetworks ul li').hover(
		function() {
			$(this).animate({
			    left: '-=10'
			  }, 200, function() {
			    // Animation complete.
			  });
		},
		function() {
			$(this).animate({
			    left: '+=10'
			  }, 200, function() {
			    // Animation complete.
			  });
		}
	);
	
	/* Contact Form */
	$('.required').hide();
	$("#sendform").click( function() {
		$('.required').hide();  
	    var name = $("input#contact_name").val();  
	    if (name == "") {  
	      $("label#name_error").show();  
	      $("input#contact_name").focus();  
	      return false;  
	    }
        
	    var email = $("input#contact_email").val();
      var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;  
	    if(reg.test(email) == false || email == "") {
	      $("label#email_error").show();  
	      $("input#contact_email").focus();  
	      return false;      
      }
       
	    var message = $("textarea#contact_message").val();  
	    if (message == "") {  
	      $("label#message_error").show();  
	      $("textarea#contact_message").focus();  
	      return false;  
	    }
	    
	    var dataString = 'name='+ name + '&email=' + email + '&message=' + message;
		
		/* Note: To enable this AJAX form, make sure this is on the same path as the included mail.php, then
		         simply uncomment this area here, and remove the area indicated below. If you have questions
		         don't hessitate to e-mail me: hello -at- cricketlachica.com. */
		         
		$.ajax({
		    type: "POST",
		    url: "mail.php",
		    data: dataString,
		    success: function() {
		      $('#contactform form').html("<div id='message'></div>");
		      $('#message').html("<h2>E-mail odeslán!</h2>")
		      .append("<p>Děkujeme Vám za Vaši zprávu. Budeme Vás kontaktovat během několika dnů.</p>")
		      .hide()
		      .fadeIn(1500);
		    }
		});
		
		
		/* 
		$('#contactform form').html("<div id='message'></div>");
		      $('#message').html("<h2>E-mail odeslán!</h2>")
		      .append("<p>Děkujeme Vám za Vaši zprávu. Budeme Vás kontaktovat během několika dnů.</p>")
		      .hide()
		      .fadeIn(1500);
		*/
		
		return false;
	});
	
	$("#themes a").click( function() {
		$("body").removeClass();
		$("body").addClass( $(this).attr("rel") );
		return false;
	});
});
