$(document).ready(
    function() {
		
		
		// print popup
		$('.article-print').click(
		  function()
		  {
		  	printPopup = window.open($(this).attr('href'), $(this).attr('href'), 'status=0, toolbar=0, location=0, menubar=1, directories=0, resizable=0, scrollbars=1, height=550, width=770');
			printPopup.moveTo(10, 10);
			return false;
		  }
		);
		
		// subnav display / hide
		$subnavs = $('.subnav');
		
		if ($subnavs.length > 0) {
			$subnavs.each(
			     function()
				 {
				 	var classActive = $(this).parent().attr('class');
				 	if (-1 == classActive.indexOf('active')) {
						$(this).hide();
					} else {
						$(this).show();
					}
				 }
			);
		}
		
		// open subnav list if we're on the right page
		var pageId = $('body').attr('id');
            
		// subnavigation items sliding on click	        
        $('#nav li a').click(
		  function() {
		      $subnavList = $(this).parent().parent().find('ul');
			  
			  if (0 < $subnavList.length)
			  {
			  	if ('none' == $subnavList.css('display')) {
				  	$subnavList.slideDown(150);
				} else {
					$subnavList.slideUp(150);
				}
				
				// ovo zato da se ne slijedi HREF od linka
				return false;
			  }
		  }
		);
		
		
		// display 'pretrage' onclick
		$('#pretrage-list a').click(
		  function()
		  {
		  	
			$loadedContent = $(this).parent().find('.load-article-pretraga');
			
			if ($loadedContent.length > 0) {
				
				var display = $loadedContent.css('display');
				
				if ('none' == display) {
					$(this).css({'font-weight': 'bold', 'color' : '#555555', 'background-image': 'url(/css/img/action_stop.gif)', 'background-repeat': 'no-repeat', 'background-position': '100% 50%'});					
					$(this).attr('title', 'Kliknite da sakrijete pretragu');
					$loadedContent.slideDown('slow');
				} else {
					$(this).css({'font-weight': 'normal', 'color' : '#40A9D3', 'background-image' : 'none'});
					$(this).attr('title', 'Kliknite da pogledate pretragu');
					$loadedContent.slideUp('slow', function() { $loadedContent.hide(); });
				}
				
				
				
			} else {
				$(this).css({'font-weight': 'bold', 'color' : '#666666', 'background-image':'url(/css/img/ajax-loader.gif)', 'background-repeat': 'no-repeat', 'background-position': '50% 50%'});
			  	var href = $(this).attr('href');
				$linkElement = $(this);
				$linkElement.attr('title', 'Kliknite da sakrijete pretragu');
				/*
				$(this).parent().append('<div class="load-article-pretraga"><div class="loader"></div><div class="loaded-content"></div></div>');
				$(this).parent().find('.load-article-pretraga').slideDown();
	            $(this).parent().find('.loaded-content').load(href + 'format/html/', function() { $(this).parent().find('.loader').fadeOut('slow'); $(this).slideDown('slow') });
	            */
				
				$(this).parent().append('<div class="load-article-pretraga"><div class="loaded-content"></div></div>');
                //$(this).parent().find('.load-article-pretraga').slideDown();
                $(this).parent().find('.loaded-content').load(
				    href + 'format/html/', 
					function() 
					{ 
					   $(this).parent().slideDown('slow'); 
					   $linkElement.css({'background-image': 'url(/css/img/action_stop.gif)', 'background-repeat': 'no-repeat', 'background-position': '100% 50%'}); 
				   });
				
			}

			return false;
		  }
		);
		
    }
);

/**
 * Show / hide article
 */
function displayArticle(data, $link)
{
	alert(data);
	return false;
}

/**
 * Show / hide some container element by clicking on some other element
 * 
 * @param selElement jQuery selector of element to toggle
 * @param selWith jQuery selector of element which controls toggling of other element
 */
function toggleSlideElementWith(selElement, selWith) 
{
	$(selWith).click(
	function()
	{
		elementDisplay = $(selElement).css('display');
		if ('none' == elementDisplay) {
			$(selElement).slideDown(150);
		} else if ('block' == elementDisplay) {
			$(selElement).slideUp();
		}
        return false;
	}
    );
}