// :external expression
$.expr[':'].external = function(elem,index,match) {
    var url = elem.href || elem.src,
        loc = window.location;
    return !!url.match(new RegExp('^' + loc.protocol + '//' + '(?!' + loc.hostname + ')' ));
};
//$('a:external');

// disable on submit plugin
$.fn.disableOnSubmit = function(disableList){

	if(disableList == null){var $list = 'input[type=submit],input[type=button],input[type=reset],button';}
	else{var $list = disableList;}

	// Makes sure button is enabled at start
	$(this).find($list).removeAttr('disabled');

	$(this).submit(function(){$(this).find($list).attr('disabled','disabled');});
	return this;
};

// onload common JS
$(function(){

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

	$('form').disableOnSubmit();

	// 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;
		  }
		}
  });

	// PDF ikonice
	$('a').each(function() {
		if ($(this).attr('href').match(/\.pdf$/))	$(this).addClass('pdf');
	});

	// fancybox
	$("ul.album li a[href$=.jpg]").each(function(){ $(this).attr("rel", "group") }).fancybox({
		'overlayShow'			: true,
		'imageScale' 			: true,
		'zoomSpeedIn'			: 600,
		'zoomSpeedOut'		: 400,
		'easingIn'				: 'easeOutBack',
		'easingOut'				: 'easeInSine',
		'hideOnContentClick': false
	});

	// tooltipovi
	$("*[title]").tooltip({
	    //bodyHandler: function() { 
			//	return 'bla';
	    //}, 
	    track: true,
	    delay: 0,
	    showURL: false,
	    showBody: " - "
	    //opacity: 0.85
	});
	
	$("h1").wrapInner("<span/>");
	
});