/* preload function */
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preload = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)


$(function() {
    var template_directory= $("#template_directory").val();
    $("div.project").each(function() {
        $(this).hover(function() {
            $(this).find(".project_excerpt").addClass("project_hover");
        }, function() {
            $(this).find(".project_excerpt").removeClass("project_hover");
        });
    });
    var img;
    var old;
    var lang= $("#lang").val();

    $("a#blog").hover(function() {
        img= $(this).children("img");
        old= img.attr("src");
        img.attr("src", template_directory+"/images/navbar_blog_hover.png");
    }, function() {
        img.attr("src", old);
    });
    $("a#portfolio").hover(function() {
        img= $(this).children("img");
        old= img.attr("src");
        img.attr("src", template_directory+"/images/navbar_portfolio_hover.png");
    }, function() {
        $(this).children("img").attr("src", old);
    });
    $("a#about").hover(function() {
        img= $(this).children("img");
        var link= "/images/navbar_about_";
        if(lang=="sr") link+= "sr_";
        link+= "hover.png";
        old= img.attr("src");
        img.attr("src", template_directory+link);

    }, function() {
        img.attr("src", old);
    });
    $("a#contact").hover(function() {
        img= $(this).children("img");
        var link= "/images/navbar_contact_";
        if(lang=="sr") link+= "sr_";
        link+= "hover.png";
        old= img.attr("src");
        img.attr("src", template_directory+link);
    }, function() {
        img.attr("src", old);
    });

    var old_s;
    var default_search= $("#default_search").val();
    var should_blur= true;
    $("#searchform").hover(function() {
        should_blur= false;
    }, function() {
        should_blur= true;
    });

    $("#s").focus(function() {
        $("#sidebar_search").addClass("focus");
        $("#searchsubmit").removeClass("hidden");
        old_s= $("#s").val();
        if(old_s==default_search) {
            $("#s").val("");
        }
    });
    $("#s").blur(function() {
        if(should_blur) {
            $("#searchsubmit").addClass("hidden");
            $("#sidebar_search").removeClass("focus");
            if($("#s").val()=="") $("#s").val(default_search);
        }
    })
});






