$(document).ready(function(){
  //vars
  var commentValue = $("#comment").val();
	var authorValue = $("#author").val();
	var emailValue = $("#email").val();
	var urlValue = $("#url").val();
  var menu = $("#menu");
  
  
  //CUFON
  if (typeof Cufon != "undefined"){
    //menu
    Cufon.replace('#menu > li.menu-item > a', {
      textShadow: '#fff 0 1px 1px',
      letterSpacing: '0.2px',
      fontSize: '20px'
    });
    Cufon.replace('#footer h4', {
      textShadow: '#fff 0 1px 1px',
      letterSpacing: '0.8px'
    });
    Cufon.replace('#splash h1', {
      textShadow: '#d7d7d7 0 2px 1px',
      letterSpacing: '0.8px'
    });
    Cufon.replace('#services h3, #footer h4', {
      textShadow: '#fff 0 1px 1px',
      letterSpacing: '0.8px'
    });
    Cufon.replace('h2, h3, h4, h5, h6', {
      letterSpacing: '0.8px',
      hover: true
    });
    //fix IE´s
    Cufon.now();
  }
  
  
  //TOGGLE
  $(".toggle a").click(function(){
    if($(this).hasClass("active"))
      $(this).removeClass("active");
    else
      $(this).addClass("active");
    $(this).parent().next(".toggle_content").slideToggle();
    
    return false;
  });
  
  
  //GALLERY
  var galleryItems = $("#main.gallery .item a");
  var rollImages = $("#main.gallery span.rollover");
  
  if(galleryItems.length > 0){
    //rollover items
    rollImages.css({"display": "none"});
    galleryItems.mouseover(function(){
      var item = $(this).find(".rollover");
      var n = item.queue("fx");
      if(n==0){
        item.fadeIn();
       }
    });
    galleryItems.mouseleave(function(){
      $(this).find(".rollover").fadeOut();
    });
    //popup
    $("a[rel^='prettyPhoto']").prettyPhoto({
      theme: 'light_square',
      show_title: false,
      overlay_gallery: false
    });
  }
  
  
  //SEARCH BAR
  var searchValue = $("#s").val();
	$("#s").focus(function () {
		if($(this).val() == searchValue)
			$(this).val("");
	});	
	$("#s").blur(function () {
		if($(this).val() == "")
			$(this).val(searchValue);
	});
  
  
  //LAST TWEET
  if (typeof twitter != "undefined"){
    var username= twitter; // set user name
    var format='json'; // set format, you really don't have an option on this one
    var url='http://api.twitter.com/1/statuses/user_timeline/'+username+'.'+format+'?callback=?';     // make the url

    $.getJSON(url,function(tweet){ // get the tweets
      $("#twitter a").html(tweet[0].text); // get the first tweet in the response and place it inside the div
      $("#twitter span span").html(tweet[0].created_at.slice(0, 16)); // get the first tweet in the response and place it inside the div
    });
  }

  //COMMENTS ON POST
	$("#commentform #comment").focus(function () {
		if($(this).val() == commentValue)
			$(this).val("");
	});	
	$("#commentform #comment").blur(function () {
		if($(this).val() == "")
			$(this).val(commentValue);
	});
	$("#commentform #author").focus(function () {
		if($(this).val() == authorValue)
			$(this).val("");
	});	
	$("#commentform #author").blur(function () {
		if($(this).val() == "")
			$(this).val(authorValue);
	});
	$("#commentform #email").focus(function () {
		if($(this).val() == emailValue)
			$(this).val("");
	});	
	$("#commentform #email").blur(function () {
		if($(this).val() == "")
			$(this).val(emailValue);
	});
	$("#commentform #url").focus(function () {
		if($(this).val() == urlValue)
			$(this).val("");
	});	
	$("#commentform #url").blur(function () {
		if($(this).val() == "")
			$(this).val(urlValue);
	});
  //if user don't fill the required fields
	$("#commentform #submit").click(function(){
    if($("#comment").val() == "" || $("#author").val() == "" || $("#email").val() == "" || $("#comment").val() == "Write your message here..." || $("#author").val() == "Name" || $("#email").val() == "Email"){
    //highlight wrong fields
    if($("#comment").val() == "" || $("#comment").val() == "Write your message here...")
      $("#comment").addClass('error');
    if($("#author").val() == "" || $("#author").val() == "Name")
      $("#author").addClass('error');
    if($("#email").val() == "" || $("#email").val() == "Email")
      $("#email").addClass('error');
    
    return false;
		}
  });
  
  //PRELOAD IMAGES FROM GALLERY
  $("#main.gallery .item, .post_image").preloadify({
        imagedelay: 300,
        mode: 'sequency'
    });
});


//SHOWCASE SLIDERS
var slider = $('.slider').advancedSlider({width:786, height:377, slideshowControls:false, timerAnimation:false, slideshowDelay: 2000, slideProperties:{
      0:{effectType:'fade', horizontalSlices:'5', verticalSlices:'3', slideStartPosition:'bottom'},
      1:{effectType:'fade', horizontalSlices:'5', verticalSlices:'3'}
    }
  });
$("#splash_left").click(function(){slider.previousSlide()});
$("#splash_right").click(function(){slider.nextSlide()});

$("#menu").superfish({
    animation: {opacity: 'show',height: 'show'},
    speed:  400,
    delay:  100,
    dropShadows: false,
    autoArrows: false,
    disableHI: true
  });
