// JavaScript Document


$(document).ready(function(){
	$('#hnav').autosprites({
		offset: '99px',
		activeState: true,
		activeSprites: true
	});
});


(function($){
		  $.fn.autosprites=function(settings){settings=$.extend({offset:'100%',orientation:'horizontal',over:{opacity:'show'},overSpeed:500,out:{opacity:'hide'},outSpeed:1000,activeState:false,activeClass:'active',activeSprites:false},settings);function rempx(string){return Number(string.substr(0,string.length-2));}
		  
function addpx(number){return number+'px';}
$(this).each(function(){var backgroundImage=$(this).css('background-image');
$(this).css('zIndex',100).find('a').css('zIndex',99);var totalPositionOffset=0;
$(this).children().each(function(){var positionOffset='-'+addpx(totalPositionOffset);var baseOffset='0px';if(settings.activeState&&$(this).hasClass(settings.activeClass)){baseOffset='-'+addpx(rempx(settings.offset));if(settings.activeSprites)
baseOffset='-'+addpx(rempx(settings.offset)*1);}

var position=settings.orientation=='horizontal'?positionOffset+' '+baseOffset:baseOffset+' '+positionOffset;var offsetPosition=settings.orientation=='horizontal'?positionOffset+' -'+settings.offset:'-'+settings.offset+' '+positionOffset;

$(this).css({backgroundImage:backgroundImage,backgroundPosition:position});var width=$(this).css('width');var height=$(this).css('height');var hover=$('<div>&nbsp;</div>').css({cursor:'hand',zIndex:1,position:'absolute',top:0,left:0,width:width,height:height,backgroundImage:backgroundImage,backgroundPosition:offsetPosition}).hide();
$(this).prepend(hover);$(this).hover(function(){
$(this).find('div').stop(true,true).animate(settings.over,settings.overSpeed),
{queue:false, duration:800 };},function(){$(this).find('div').stop(true,true).animate(settings.out,settings.outSpeed),{queue:false, duration:800 };});totalPositionOffset+=settings.orientation=='horizontal'?rempx(width):rempx(height);});});}})(jQuery);


//NAV

$(document).ready(function() {
	//settings
	var opacity = 0.5, toOpacity = 0.9, duration = 250;
	//set opacity ASAP and events
	$('.opacity').css('opacity',opacity).hover(function() {
			$(this).fadeTo(duration,toOpacity);
		}, function() {
			$(this).fadeTo(duration,opacity);
		}
	);
});

//OPACITY


//EKSTERNI LINKOVI
	
	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";   
 }   
}   
window.onload = externalLinks;

