// author : Nevena Stojanovic, notvena@gmail.com
// date : 09.03.2009.


/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
/* end hover intent */


$imagePath = "";
//$isLoggedIn = false;

/* function for accordion */
function doSlide(element)
{
var $elementToSlide = $(element).children('.slide');	
elementToSlide = element + " li .slide";
$(elementToSlide).click(
		function() {

			var checkElement = $(this).next();
			
			var $parent = $elementToSlide.parents('ul.slidingpanels');
			$parent = $(element);

			if($parent.hasClass('collapsible') && checkElement.is(':visible')) 
				{
				$(this).next().slideUp('normal');
				}	
			else 
				{
				$(elementToSlide).next().slideUp();
				checkElement.slideToggle('normal');
				}

		}
	);	
}

$(document).ready(function(){	


/* vesti */						   
$newspopupCnt = 0;
$overlayCnt = 0;
$('ul.newspopup').each(function(){
	$(this).attr("id", "popup"+$newspopupCnt);
	$newspopupCnt++;
	});

if ($('ul.newspopup').length>0) // create overlay div
	{
	$('ul.newspopup li .full').hide();	
	$('ul.newspopup').each(function(){
								
		if ($(this)[0].className.indexOf('homenewspopup')>0)
			{
			$('<div class="overlay homenewsoverlay" id="overlay'+$overlayCnt+'"><div class="closefull" title="Zatvori">Zatvori</div></div>').insertBefore($(this));
			$targetheight = parseFloat($(this).height(), 10) - 30;
			//$targetheight = $(this).height() - 70;
			$('.homenewsoverlay').css('min-height',$targetheight + "px");
			$('.homenewsoverlay').css('height',$targetheight + "px");			
			
			}
			else
			{
			$('<div class="overlay" id="overlay'+$overlayCnt+'"><div class="closefull" title="Zatvori">Zatvori</div></div>').insertBefore($(this));
			}
		$overlayCnt++;
		});		
		

	

	$('ul.newspopup li a.full-news').click(function(e){
		e.preventDefault();
		
		$('#overlay'+$(this).parents('ul.newspopup').attr("id").substr(5)+' *:not(.closefull)').empty();
		//$('.overlay *:not(.closefull)').empty();
		
		$fulltext = ($(this).parent('li').children('div.full').html()!=null) ? $(this).parent('li').children('div.full').html() : ' ';
		$fullnewscontent = 	'<span class="date">'+ $(this).parent('li').children('span.date').html() + '</span>' +
							$fulltext;
							//$(this).parent('li').children('div.full').html();
							//'<div id="close"><a href="#" title="Zatvori">Zatvori</a></div>';
		//alert($(this).parents('ul.newspopup').attr("id").substr(5));

	$('#overlay'+$(this).parents('ul.newspopup').attr("id").substr(5)).prepend($fullnewscontent);
	$('#overlay'+$(this).parents('ul.newspopup').attr("id").substr(5)).fadeIn();

//		$('.overlay').prepend($fullnewscontent);
//		$('.overlay').fadeIn();
	});		
	
	
	}


$('.closefull').click(function(e){
	//$('#overlay'+$(this).parents('ul.newspopup').attr("id").substr(5)).prepend($fullnewscontent);
	//$('#overlay'+$(this).parents('ul.newspopup').attr("id").substr(5)).fadeIn();	
	
	$(this).parents('.overlay').fadeOut();
	});

/* [end] vesti */		
/* anketa */
	$('a.anketa-popup').click(function(e){
		$('#overlay-anketa').css('top','-142px').fadeIn();
	});	

/* [end] anketa */	

/* partners login */
$('#register').hide();
$loginShown = false;
$('#partners-ser, #partners-eng').click(function(e){
	if (!$isLoggedIn)
		{
		e.preventDefault();
		if (!$loginShown)
			{
			$('#register').animate({opacity:'show', height:'show'}, 'normal');
			$loginShown = true;
			}
		else 
			{
			$('#register').animate({height:'hide'}, 'normal');
			$loginShown = false;
			}
		}
	
	});
/* [end] partners login */


/* languages dropdown  */
$('#lang').hide();
$langShown = false;
$('#current-lang, #lang li a').click(function(e){
	if ($(this).attr('id') == "current-lang")
		e.preventDefault();
	if (!$langShown)
		{
		$('#lang').animate({opacity:'show', height:'show'}, 'normal');
		$langShown = true;
		}
	else 
		{
		$('#lang').animate({height:'hide'}, 'normal');
		$langShown = false;
		}
	
	});

$('.closelang').click(function(event){
		$('#lang').animate({height:'hide'}, 'normal');
		$langShown = false;
	});

$('#current-lang').mouseover(function(event){
		//alert($('#lang').css('height'));
		if($('#lang').css('height')=='auto')
			$('#lang').animate({opacity:'show', height:'show'}, 'normal');
	});

$('#current-lang').bind('mouseleave', function(event){
		//alert(event.relatedTarget.nodeName);
		
		if (!(event.relatedTarget.nodeName=="LI" || event.relatedTarget.nodeName=="UL"))
			$('#lang').animate({height:'hide'}, 'normal');
		
	});

$('#lang').bind('mouseleave', function(event){
		$('#lang').animate({height:'hide'}, 'normal');
	});

$('#lang ul li').click(function(event){
		$('#lang').animate({height:'hide'}, 'normal');
	});
/* [end] languages dropdown  */

/* main nav flyout*/
$('#navigation-ser ul li ul, #navigation-eng ul li ul').css('top','27px')
$('#navigation-ser ul li:not(.active) ul, #navigation-eng ul li:not(.active) ul').css('top','27px').hide();

$('#navigation-ser ul li, #navigation-eng ul li').hover(function(){}, function(event){
	if ($(this).children('a').is('.parent') && $(this).is('.active'))
		{
		$(this).children('ul').css('z-index','5');
		}
	else
		{
		$(this).children('ul').animate({height:'hide'}, 'normal');	
		$(this).removeClass('over');
		}

													});

$('#navigation-ser ul li:not(.active) a.parent, #navigation-eng ul li:not(.active) a.parent').hoverIntent(function(event){
		$(this).parents('li').children('ul').animate({opacity:'show', height:'show'}, 'normal').css('z-index','6');
		$(this).parents('li').addClass('over');	
	}, 
	function(event){
		//event.stopPropagation();
		$(this).removeClass('over');
	});

/* [end] main nav flyout*/

	/* sliding pannel - for example industry and solutions page*/
	if ($('ul.slidingpanels').length>0)
		{
		$('ul.slidingpanels li div.full').hide(); 
		//alert('aaaaaaaaaaaa');
		doSlide('ul.slidingpanels'); 
		}	
						   



});	