/**
* 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);


var config = {    
		sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		interval: 20, // number = milliseconds for onMouseOver polling interval    
		over: 
		  function(){
			  var toJestTo=$(this);
				$('#home #column-sections .expand').removeClass('expanded');
        $("#home #column-sections .expand .header ~ div").hide();
	      $('#home #news-bar ul').slideUp(50, function(){
       	  $('#home #news-bar ul').removeClass('expanded');
       	  $('#home #news-bar').removeClass('expanded');
     	    toJestTo.children().not('.header').slideDown('fast');
         	toJestTo.addClass('expanded');		
	    	});
		   },  
     timeout: 100, // number = milliseconds delay before onMouseOut    
     out: 
		   function(){
				var toJestTo=$(this);
		    toJestTo.children().not('.header').slideUp('fast', function(){
	        toJestTo.removeClass('expanded');
				});
				

		 }
};
var config2 = {    
		sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		interval: 20, // number = milliseconds for onMouseOver polling interval    
		over: 
		  function(){
			
		  	// super IE
	      $('#home #column-sections .relative').css('zIndex', 200);
	      $('#home #column-sections .expand').css('zIndex', 200);	
				$("#home #news-bar ul").css('zIndex', 9999);
				$("#home #news-bar").css('zIndex', 9999);
				
			  $("#home #column-sections .expand").children().not('.header').slideUp(50, function(){
				  $("#home #news-bar").addClass('expanded');
	        $("#home #news-bar ul").slideDown(150);
		    	$("#home #news-bar ul").addClass('expanded');
	  		});
		   },  
     timeout: 100, // number = milliseconds delay before onMouseOut    
     out: 
			function(){

			  $("#home #news-bar ul").slideUp(100, function(){
					$("#home #news-bar").removeClass('expanded');
				});
				
			  $("#home #news-bar ul").removeClass('expanded');
				
		  	// super IE
			  $('#home #column-sections .relative').css('zIndex', 9999);
			  $('#home #column-sections .expand').css('zIndex', 9999);	
			  $("#home #news-bar ul").css('zIndex', 200);
			  $("#home #news-bar").css('zIndex', 200);
		 }
};

$().ready(function(){

	$('#home #news-bar ul').removeClass('expanded');
	$("#home #news-bar ul").hide();
	$("#home #news-bar ").hoverIntent( config2 );

	$('#home #column-sections .expand').removeClass('expanded');
	$("#home #column-sections .expand .header ~ div").hide();
	$("#home #column-sections .expand").hoverIntent( config );	
	
	var searchFieldValue = $('#phrase').val();
	$('#phrase').focus(function() { if(($(this).val()) == searchFieldValue) { $(this).val('');} });
	$('#phrase').blur(function() { if(($(this).val()) == ''){$(this).val(searchFieldValue);} });
	
	
	$('#side-nav li a').hover( 
	function(){
	  $(this).parent().next().addClass('nobg');
	}, 
	function(){
	  $(this).parent().next().removeClass('nobg');
	});

    $('#contact-page .kontakty h3').addClass('hidden').next('div').hide();

    $('#contact-page .kontakty .left li:first-child h3:first-child').removeClass('hidden').next().show();

    $('#contact-page .kontakty h3').click(function () {

        if ($(this).hasClass('hidden')) {

            $('#contact-page .kontakty h3').next('div').slideUp('fast', function () { $(this).prev().addClass('hidden') });

            $('#contact-page .kontakty h3').addClass('hidden');

            $(this).next('div').slideDown('fast');

            $(this).removeClass('hidden');

        }

        else {

            $(this).next('div').slideUp('fast', function () { $(this).prev('h3').addClass('hidden') });

        }

    });
});