
	$(function() {
	
		/* open/close top menu dropdowns */ 
		$('#top-menu li').hover(
			function() { $(this).addClass('hover'); },
			function() { $(this).removeClass('hover'); }
		);
		
		/* disable top menu links with dropdowns */
		$('#top-menu a.not').click(function() { return false; });
			
		/* text in footer form */
		$('#newsletter-form input')
			.focus(function() { if($(this).val() == 'Upišite svoj e-mail') $(this).val(''); })
			.blur (function() { if($(this).val() == '') $(this).val('Upišite svoj e-mail'); });
			
		/* open in new window */
		$('#top a,.external a,.pdfLink,.pdf').attr('target','_blank');
		
		/* left scrollable box on homepage*/
		$("div.scrollable").scrollable({ item:'a', size: 2, clickable: false }).circular().mousewheel().autoscroll({ interval: 10000 });
		
		/* right scrollable box on homepage */
		window.api = $("#articles-scrollable").scrollable({ size: 1, clickable: false }).circular().navigator({ navi: '.nav', naviItem: 'a' }).mousewheel().autoscroll({ interval: 10000, api: true });
		$('#articles-scrollable .pausePage').live('click',function() { api.stop(); $(this).removeClass('pausePage').addClass('playPage'); return false; });
		$('#articles-scrollable .playPage').live('click',function() { api.play(); $(this).removeClass('playPage').addClass('pausePage'); return false; });
					
		/* gallery */
		$('.boxm > a').filter(function (index) { return ((index + 1) % 4 == 0); }).addClass('mlast');
		if($(".overlay-gallery").length) { 
			$(".overlay-gallery a").overlay({ 
				onBeforeLoad: function() { $('#top-menu .form').css('z-index','0'); }, 
				onClose: function() { $('#top-menu .form').css('z-index','100000'); }, 
				target: '#gallery', 
				expose: '#445566', 
				top: '15%' 
			})
			.gallery(); 
		}
		if($(".th").length) { 
			$(".th").overlay({ 
				onBeforeLoad: function() { $('#top-menu .form').css('z-index','0'); }, 
				onClose: function() { $('#top-menu .form').css('z-index','100000'); }, 
				target: '#gallery', 
				expose: '#456', 
				top: '15%' 
			})
			.gallery(); 
		}
		
		/* job form */
		$('button.xpandbtn1').click(function() { $(this).parent('p').siblings('.xpand1template:hidden:first').slideDown(); });
		$('button.xpandbtn2').click(function() { $(this).parent('p').siblings('.xpand2template:hidden:first').slideDown(); });
		$('button.xpandbtn3').click(function() { $(this).parent('p').siblings('.xpand3template:hidden:first').slideDown(); });
		
		/* embedded gallery */		
		if($("div.scrollable-pagegallery").length) {
			$("div.scrollable-pagegallery").scrollable({ item:'a', size: 4, clickable: false }).circular().mousewheel();
			$("div.scrollable-pagegallery a").overlay({ 
				onBeforeLoad: function() { $('#top-menu .form').css('z-index','0'); }, 
				onClose: function() { $('#top-menu .form').css('z-index','100000'); }, 
				target: '#gallery', 
				expose: '#456', 
				top: '15%' 
			})
			.gallery({
				template: '<strong>${title}</strong>'
			}); 
		}
		
		/* make odd rows grey */
		$('.caltable tr:even').addClass('odd');
		
		/* show working times on hover */
		$(".radno_vrijeme").click(function() { return false; }).tooltip({ tip: '.tooltip', position: 'top right', offset: [10,-10], lazy: true, delay: 0 });
		
		/* open these links in overlay */
		$('.arhiva a').overlay({ 
			onBeforeLoad: function() { $('#top-menu .form').css('z-index','0'); }, 
			onClose: function() { $('#top-menu .form').css('z-index','100000'); }, 
			expose: '#456', 
			top: 'center' 
		});
		
		$('a.aktualno').overlay({ 
			onBeforeLoad: function() { $('#top-menu .form').css('z-index','0'); }, 
			onClose: function() { $('#top-menu .form').css('z-index','100000'); }, 
			expose: '#456', 
			top: 'center' 
		});
			
		/* magazin arhiva */
		//$('.magazinscroll').scrollable({items:'.arhiva',item:'li',size:3,prev:'.gore',next:'.dole'}).mousewheel().circular();
		//$('.gore,.dole').click(function() { return false; });
		
		$('.aside .box .arhiva').width(102 * $('.aside .box .arhiva > li').length);
		
		/* video player */
		$("a.video[rel]").overlay({
			/*effect: 'apple',		*/
			expose: '#456',	
			top: 'center',			
			onBeforeLoad: function() { $('#top-menu .form').css('z-index','0'); },
			onLoad: function() { this.getOverlay().find("a.player").flowplayer(0).load(); },
			onClose: function() { $('#top-menu .form').css('z-index','100000'); $f().unload(); }
		});				
	
		$("a.player").flowplayer({
			src: "http://releases.flowplayer.org/swf/flowplayer-3.1.5.swf", 
			wmode: 'opaque'
		}); 
		
		$('.caltable td strong').each(function() {
			var isti = $(this).text().split(' - ');
			if(isti[0] == isti[1]) $(this).text(isti[0]);
		});
		
		$('.arhiva-years > a:first').addClass('active');
		$('.arhiva-months > div:first').show();
		$('.arhiva-years > a').click(function() {
			$('.arhiva-months > div').hide();
			$('.arhiva-months > div.arhiva-year-' + $(this).text()).show();
			$('.arhiva-years > a').removeClass('active');
			$(this).addClass('active');
			return false; 
		});
				
	});
