function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function externalLinks() {
   if (!document.getElementsByTagName) return;
   var anchors = document.getElementsByTagName("a");
   for (var i=0; i<anchors.length; i++) {
      var anchor = anchors[i];
      if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
         anchor.target = "_blank";
      if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "top")
         anchor.target = "_top";
   }
}
// define onload events
addLoadEvent(externalLinks);

/* gallery */
$(document).ready(function(){
	$('.gallery .nav').css('display','none'); // hides the nav initially
	$('ul.galleria').galleria({
		clickNext : false, // helper for making the image clickable. Let's not have that in this example.
		onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
			var _li = thumb.parents('li'); // fetch the thumbnail container
			_li.siblings().children('img.selected').fadeTo(500,0.3); // fade out inactive thumbnail
			thumb.fadeTo('fast',1).addClass('selected'); // fade in active thumbnail
			$('.gallery .nav').css('display','block'); // shows the nav when the image is showing
		},
		onThumb : function(thumb) { // thumbnail effects goes here
			var _li = thumb.parents('li'); // fetch the thumbnail container
			var _fadeTo = _li.is('.active') ? '1' : '0.3'; // if thumbnail is active, fade all the way.
			thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500); // fade in the thumbnail when finnished loading
			thumb.hover( // hover effects
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
			)
		}
	});
 	$('.gallery .prev a').click( function() { $.galleria.prev(); return false; } );
 	$('.gallery .next a').click( function() { $.galleria.next(); return false; } );
});
/* /gallery */
