$(document).ready(function() { 

  // Homepage!
  if ($("div.Home").length > 0) {



	var imgTotal = $("#content .content img").length;
	
	if (imgTotal > 0) {

	  var imgRandom = Math.floor(Math.random()*(imgTotal));
// 	  if (imgRandom <  2) { var imgShow = 4; }
// 	  if (imgRandom == 2) { var imgShow = 3; }
// 	  if (imgRandom == 3) { var imgShow = 2; }
// 	  if (imgRandom == 4) { var imgShow = 1; }
// 	  if (imgRandom >  4) { var imgShow = 0; }
	  
	  //$("#content .content").attr("rel", imgShow);
	  //$(".content img:gt("+imgShow+")").hide();
	  //$(".content img:lt("+imgShow+")").hide();
	  //$(".content img:not(.content img:eq("+imgShow+"))").hide();
	  
	  $("#content .Home img").each(function() { 
		$(this).css({background: 'url('+$(this).attr("src")+') top left no-repeat'});
		$(this).attr("src", '/themes/pieterpennings/images/homepage-overlay.gif');
	  });
	  
	  //$(".content img:not(.content img:eq("+imgRandom+"))").hide();
	  //$(".content img:gt("+imgRandom+")").hide();
//	  $(".content img:lt("+imgRandom+")").hide();
	  $(".content img:eq("+imgRandom+")").css({visibility: 'visible'});

	  //window.setInterval(function() { fadeHomepageImages(); }, 5000);
	}
  }
  
  // Round corners for small portfolio images
  $("#images .image .imagethumb").each(function() {
	  $(this).css({background: 'url('+$("img", this).attr("src")+') top left no-repeat'});
	  $("img", this).attr("src", '/themes/pieterpennings/images/portfolio-small.gif');
  });
  
  $(".imgprevious img, .imgnext img").hover(function() {
	$(this).attr("src", $(this).attr("src").replace("-normal", "-over"));
  }, function() {
	$(this).attr("src", $(this).attr("src").replace("-over", "-normal"));
  });
  
  
  // Round corners for big portfolio images
  $("div.portfoliosingleimage img").each(function() {
	  // height: 388 vs 580
	  
	  // &amp;w=408&amp;h=615
	  // w408_h615.jpg
	  
	  if (/w(\d+)_h(\d+)\.jpg/.test( $(this).attr('src') )) {
		var dims = $(this).attr('src').match(/w(\d+)_h(\d+)\.jpg/);
	  } else {
		var dims = $(this).attr('src').match(/w=(\d+)&h=(\d+)/);
	  }
	  

	  if (dims[2] > 500) {
		$(this).css({background: 'url(' +$(this).attr("src")+ ') top center no-repeat'});
		$(this).attr("src", '/themes/pieterpennings/images/portfolio-vertical-big.gif');	  
	  } else {
		$(this).css({background: 'url(' +$(this).attr("src")+ ') top center no-repeat'});
		$(this).attr("src", '/themes/pieterpennings/images/portfolio-horizontal-big.gif');
	  }
  });
  
  $('.imgnext, .imgprevious').css({opacity: '0.2'});
  
  $("div.portfoliosingleimage img").hover(function() {
	$('.imgnext, .imgprevious').css({opacity: '1'});
  }, function() { 
	$('.imgnext, .imgprevious').css({opacity: '0.2'});
  });
  $('.imgnext, .imgprevious').hover(function() {
	$(this).css({opacity: '1'});
  }, function() {
	$(this).css({opacity: '0.2'});
  });
  
  
  $(".newsarticlelist img").each(function() { 
	$(this).css({background: 'url(' +$(this).attr("src")+ ') top center no-repeat'});
	$(this).attr("src", '/themes/pieterpennings/images/opdrachten-small.gif');	    
  });

//$('div.menu div a').css({display: 'none' });

/*
  $.sifr({ path: "/themes/pieterpennings/", version: 3, save: true });  
  $("div.menu a").sifr({ font: "gothic3", cursor: 'hand', hoverColor: '#000000' });
  $(".gallerylist a").sifr({ font: "gothic3", cursor: 'hand', hoverColor: '#000000' });
  $(".gallerylist .active").sifr({ font: "gothic3", color: '#000000' });
*/
});

/*
function fadeHomepageImages() {
	var imgMax = 4;
	var imgMin = 0;
	var imgCurrent = parseInt($("#content .content").attr("rel"));

	// if we're not showing the top image, fade in that direction now
	if (imgCurrent < imgMax) {
	  $(".content img:eq("+(imgCurrent+1)+")").fadeIn();
	  $("#content .content").attr("rel", (imgCurrent+1));
	} else {
	  $(".content img:gt("+imgMin+")").fadeOut();
	  $("#content .content").attr("rel", imgMin);
	}
}
*/
