$(document).ready(function(){
	$.preLoadImages("images/nav_cont_over.png","images/nav_cotid_over.png","images/nav_links_over.png","images/nav_next_over.png","images/nav_perfil_over.png","images/nav_prev_over.png","images/nav_proj_over.png");

	$('.imgover').hover(
		function () { if (!$(this).parent().hasClass('sel')) { $(this).attr('src',$(this).attr('src').substr(0,$(this).attr('src').length-4)+'_over.png'); } },
		function () { if (!$(this).parent().hasClass('sel')) { $(this).attr('src',$(this).attr('src').replace('_over','')); } }
	);
	if ($('.sel img').length>0) {
		$('.sel img').attr('src',$('.sel img').attr('src').substr(0,$('.sel img').attr('src').length-4)+'_over.png');
	}
	$('.midia').hover(
		function () { 
			$(this).children(":first-child").height($(this).height());
			$(this).children(":first-child").width($(this).width());
			$(this).children(":first-child").css('background','#ccc');
			$(this).children(":first-child").show();
		},
		function () { $(this).children(":first-child").hide(); }
	);
	$('.midia').click(
		function () { 
			if ($(this).attr('id').substr(0,1)==='b') {
				window.location = PATH_TO_SELF+'blog#'+$(this).attr('id').substr(1);
			} else {
				window.location = PATH_TO_SELF+'portfolio/'+$(this).attr('id').substr(1);
			}
		}
	);
});

$(window).load(function(){
	$.each($(".midia_det:not(#midia_main) :first-child"), function() {
		if ($(this).width()==0) {
			$(this).parent().width(520);
		} else {
			$(this).parent().width($(this).width());
		}
    });
});

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = 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)
