$(function(){

	// sredi tabele
	$("table").each(function(){
		if ($(this).width() > 500) $(this).wrap('<div class="table_wrapper"></div>').after('<div class="table_fog"></div>')
	})
	$("table tr:even").addClass("par")
	$("table tr:odd").addClass("nepar")
	$(".table_wrapper").each(function(){
		var ww = $(this).width();
		var tw = $("table", this).width()
		var th = $(this)		
		
		th.hover(function(){
			$(".table_fog", this).fadeOut("fast", function() { th.css({ "width" : ww }).animate({ "width" : tw }, "fast") })
		}, function() {
			th.animate({ "width" : ww }, "fast", "", function(){ $(".table_fog", this).fadeIn("fast") })
		})
	})

	// animated jump to
  $('a[href*=#]').click(function() {
		$(this).blur();
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
		  var $target = $(this.hash);
		  $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
		  if ($target.length) {
				var targetOffset = $target.offset().top - 30;
				$('html,body').animate({scrollTop: targetOffset}, 1000);
				return false;
		  }
		}
  });

	// rel="external" otvori u novom prozoru
	$('a[rel="external"]').click(function() {
     window.open($(this).attr('href'));
     return false;
   });

	// tooltipovi
	$("*[title]").tooltip({
	    //bodyHandler: function() { 
			//	return 'bla';
	    //}, 
	    track: true,
	    delay: 0,
	    showURL: false,
	    showBody: " - "
	    //opacity: 0.85
	});
	
	// pronađi aktivan link
	var location_array = window.location.href.split('/')
	var location = '/'+ location_array[location_array.length - 1]
	
	$('ul#nav li a').each(function(){
		if ($(this).attr('href') == location) {
			$(this).parent().addClass('current');
		}
	})
	
	// prettyPhoto
	$("ul.album li a").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'dark_rounded'
	});
		
});
