// mouse stay
(function( $ ){
  $.fn.mouseStay = function( options ) {
    var settings = {
      // The handler will start if the mouse stays more than the specified milliseconds inside that element
      delayTime : 800,
      handler: function(){}
    };

    return this.each(function() {
      if(this.mouseStayScheduledHandler){
        clearTimeout(this.mouseStayScheduledHandler);
      }

      //TODO unbind the already bound mousehandlers

      if ( options ) {
        $.extend( settings, options );
      }

      $(this).mousemove( function(event){
        var _this = this;
        if(this.mouseStayScheduledHandler){
          clearTimeout(this.mouseStayScheduledHandler);
        }
        this.mouseStayScheduledHandler = setTimeout(function(){
            settings.handler.call(_this);
          }, settings.delayTime);
      });

      $(this).mouseleave(function(){
        if(this.mouseStayScheduledHandler){
          clearTimeout(this.mouseStayScheduledHandler);
        }
      });
    });
  };
})( jQuery );

/*
	TopZIndex 1.2 (October 21, 2010) plugin for jQuery
	http://topzindex.googlecode.com/
	Copyright (c) 2009-2011 Todd Northrop
	http://www.speednet.biz/
	Licensed under GPL 3, see  <http://www.gnu.org/licenses/>
*/
(function(a){a.topZIndex=function(b){return Math.max(0,Math.max.apply(null,a.map((b||"*")==="*"?a.makeArray(document.getElementsByTagName("*")):a(b),function(b){return parseFloat(a(b).css("z-index"))||null})))};a.fn.topZIndex=function(b){if(this.length===0)return this;b=a.extend({increment:1},b);var c=a.topZIndex(b.selector),d=b.increment;return this.each(function(){this.style.zIndex=c+=d})}})(jQuery);

var _$ = function(elmId)
{
	return document.getElementById(elmId);
}

function setEvent(obj, event, fnc)
{
	try {
		return obj.attachEvent(event, fnc);
	} catch (e) {
		return obj.addEventListener(event.replace(/^on/, ''), fnc, false);
	}
}
/* */
function InputDefaultValueOnFocus(e)
{
	e = e || window.event;
	elm = e.srcElement || e.target;

	InputDefaultValue.eventFocus(elm);
}

function InputDefaultValueOnBlur(e)
{
	e = e || window.event;
	elm = e.srcElement || e.target;
	
	InputDefaultValue.eventBlur(elm);
}

var InputDefaultValue = {

	'settings' : {},

	'add' : function(elmId, defaultValue, autoClear, required, styles)
	{
	   var elm = _$(elmId);

		if(!elm)
		{
		   return null;
		}
		else
		{
			InputDefaultValue.settings[elm.id] = {
			   'elmId' : elmId,
			   'defaultValue' : defaultValue,
			   'autoClear' : autoClear,
			   'required' : required,
			   'styles' : styles
			};
			
			setEvent(elm, 'onfocus', InputDefaultValueOnFocus);
			setEvent(elm, 'onblur', InputDefaultValueOnBlur);
		
			this.eventBlur(elm);
		}
	},

	'eventBlur' : function(elm)
	{
	   var sett = InputDefaultValue.settings[elm.id];

	   if(!elm.value.length && sett.required)
	   {
	      elm.value = sett.defaultValue;
	   }
	   
	   if(typeof(sett.styles) == 'object' && elm.value == sett.defaultValue)
		{
			var key;
			for(key in sett.styles)
			{
			   elm.style[key] = sett.styles[key];
			}
		}
	},

	'eventFocus' : function(elm)
	{
	   var sett = InputDefaultValue.settings[elm.id];

	   if(elm.value == sett.defaultValue && sett.autoClear)
	   {
	      elm.value = '';
	      if(typeof(sett.styles) == 'object')
			{
				var key;
				for(key in sett.styles)
				{
				   elm.style[key] = '';
				}
			}
	   }
	},
	
	'clear' : function(elm)
	{
		var sett = InputDefaultValue.settings[elm.id];
	   if(elm.value == sett.defaultValue)
	      elm.value = '';
	}
}

// velke obrazky hp
var $banners = null;

$(document).ready( function() {
	$banners = $('.bnnr-in').find('.item');

	$banners.each( function(idx) {
		$this = $(this);
		$this.css('left', idx * $this.width());

		if(idx == 0)
			$this.addClass('active');
	});

	if($banners.size() == 1 || $banners.size() == 0)
	{
		$('.bnnr-next').css('display', 'none');
		$('.bnnr-prev').css('display', 'none');
	}

	$('.bnnr-prev').bind('click', function() {

		if($(':animated').size())
			return;

		$banner = $banners.filter('.active');

		if($banner.prev('.item').size() != 0)
			$prev = $banner.prev('.item');
		else
			$prev = $banners.last('.item');

		if($prev.hasClass('active'))
			return;

		$banner.removeClass('active');
		$prev.addClass('active');

		var width = $banner.width();

		$banner.animate( { left : width }, 1200, 'swing');
		$prev.css('left', '-'+ width +'px');
		$prev.animate( { left : 0 }, 1200, 'swing');
	});

	$('.bnnr-next').bind('click', function() {

		if($(':animated').size())
			return;

		$banner = $banners.filter('.active');

		if($banner.next('.item').size() != 0)
			$next = $banner.next('.item');
		else
			$next = $banners.first('.item');

		if($next.hasClass('active'))
			return;

		$banner.removeClass('active');
		$next.addClass('active');

		var width = $banner.width();

		$banner.animate( { left : -width }, 1200, 'swing');
		$next.css('left', width+'px');
		$next.animate( { left : 0 }, 1200, 'swing');
	});
});

/* prepinani novinek/clanku na hp */
			$(document).ready(function() {

				$('.article-home h2').bind('click', function(){
					if($('.article-home').height() < 300)
					{
						$('.article-home h2').addClass('active');
						$('.article-home').animate( { height : '380px' }, 500, 'swing');
						$('.news-home').fadeOut().animate( { height : '46px' }, 200, 'swing').fadeIn().topZIndex( { increment: 60 } );
						setTimeout("$('.news-home h2').removeClass('active');", 500);
					}
				});
				$('.news-home h2').bind('click', function(){
				   if($('.news-home').height() < 300)
					{
						$('.news-home h2').addClass('active');
						$('.news-home').animate( { height : '380px' }, 500, 'swing');
						$('.article-home').fadeOut().animate( { height : '46px' }, 200, 'swing').fadeIn().topZIndex( { increment: 60 } );
						setTimeout("$('.article-home h2').removeClass('active');", 500);
					}
				});
			});
