function bind_animate_box ()
{
	$('.abox>div').hoverIntent(
		function(){
			$('.abox>div').removeClass('sfhover');
			$(this).addClass('sfhover');
			$('.abox>div').each(function(){
				if (!$(this).hasClass('sfhover')) {
					$(this).animate({opacity:0.2},300);
				}
			});
		},function(){
			$('.abox>div').removeClass('sfhover').animate({opacity:1},100);
		}
	);
}

(function($)
{
	$.fn.tooltip = function(options)
	{
		$tooltips = $(this);

		options = $.extend
		({
			index: 9999,
			tooltip: 'div.tooltip',
			fade: false,
			fade_speed: 500,
			x: 0,
			y: 0,
			follow: true,
			offset: true,
			standalone: false
		}, options);

		$tooltip_trigger = $tooltips;

		if (options.follow)
		{
			$tooltip_trigger.css
			({
				'position': 'relative'
			});

			$tooltip_trigger.children(options.tooltip).css
			({
				'position': 'absolute',
				'z-index': options.index
			});
		}

		$tooltip_trigger.live('mouseenter', function(event)
		{
			$tooltip = $(this).children(options.tooltip);

			if (options.standalone)
			{
				$('body').append($tooltip.clone());

				$tooltip = $('body > ' + options.tooltip).last();
			}

			if (options.fade)
			{
				$tooltip.not(':animated').fadeIn(options.fade_speed);
			} else
			{
				$tooltip.show();
			}
		});

		$tooltip_trigger.live('mouseleave', function()
		{
			$tooltip = $(this).children(options.tooltip);

			if (options.standalone)
			{
				$tooltip = $('body > ' + options.tooltip).last();
			}

			if (options.fade)
			{
				$tooltip.fadeOut(options.speed, function()
				{
					if (options.standalone)
					{
						$tooltip.remove();
					}
				});
			} else
			{
				$tooltip.hide();

				if (options.standalone)
				{
					$tooltip.remove();
				}
			}
		});

		if (options.follow)
		{
			$tooltip_trigger.live('mousemove', function(event)
			{
				$this = $(this);
				$tooltip = $(this).children(options.tooltip);

				if (options.standalone)
				{
					$tooltip = $('body > ' + options.tooltip).last();
				}

				$tooltip.css
				({
					'top': event.pageY + (options.offset && ! options.standalone ? -$this.offset().top : 0) + options.y,
					'left': event.pageX + (options.offset && ! options.standalone ? -$this.offset().left : 0) - $tooltip.width() + options.x
				});
			});
		}

		return this;
	}
})(jQuery);


var config =
{

	// form inputs using tip values
	form_tips: 'input[name=search], input[name=name], input[name=telefon], input[name=email], input[name=emailodesilatel], input[name=emailprijemce], textarea[name=message], input[name=kod]',

	// form inputs using validation
	form_validate: 'input[name=name], input[name=email], input[name=emailodesilatel], input[name=emailprijemce], textarea[name=message], input[name=kod]',


	// default tips for form inputs
	formdata:
	{
		name: 'Jméno...',
                telefon: 'Telefon...',
		email: 'Email...',
                emailodesilatel: 'Email odesílatele...',
                emailprijemce: 'Email příjemce...',
		message: 'Zpráva...',
                kod: '5 + 10 = '
	}

};




$(document).ready(function(){

        bind_animate_box();


        $("#slider").easySlider({
            auto: true,
            continuous: true,
            speed:	1800,
            pause:	10000,
            numeric: false,
            controlsShow: false
	});

        $("#galerie img, #img-preload img").lazyload({
            placeholder : "../../images/blank.gif",
            effect : "fadeIn"
        });

        $('.box-galerie').hover(function(){
		$(".cover", this).stop().animate({top:'115px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'180px'},{queue:false,duration:160});
	});


        if($('#infotext').attr('title')){
              $.n.success($('#infotext').attr('title'),{
               effect: 'slide',
               timeout: 5000
              });
        }


        $('#napsat-komentar').click(function(){
		$.scrollTo( '#napsat-komentar-box', 1700);
	});

        $('#back-to-top').click(function(){
		$.scrollTo('.logo', 1000);
	});


	$("#soc-icons").jsocial({highlight: true,
		buttons: "linkedin,digg,technorati,delicious,google,reddit,facebook,twitter,stumbleupon",
		imagedir: "../../images/small/",
		imageextension: "gif",
		blanktarget: false
	});


        //activate the lightbox
        $('a[href$=jpg], a[href$=png], a[href$=gif], a[href$=jpeg], a[href$=JPG], a[href$=PNG], a[href$=GIF], a[href$=JPEG]').prettyPhoto({theme: "light_square"});


	$('#back-to-top').click(function(){
            $('html, body').animate({scrollBottom:0},1000);
            return false;
	});





// FORM VALIDATION BEGIN

	$(config.form_validate).blur( function()
	{
		val = $(this).val();

		$(this).removeClass('valid');

		if (val == '' || val == $(this).data('tip'))
		{
			$(this).addClass('error');
		} else
		{
			if ($(this).attr('name') == 'email' || $(this).attr('id') == 'email' || $(this).hasClass('email'))
			{
				if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(val))
				{
					$(this).removeClass('error').addClass('valid');
				} else
				{
					$(this).addClass('error');
				}
			} else
			{
				$(this).removeClass('error').addClass('valid');
			}
		}
	});

	// FORM VALIDATION END

	// FORM TIPS BEGIN

	$(config.form_tips).each( function()
	{
		if ($(this).attr('name') != '' && $(this).attr('name') in config.formdata)
		{
			tip = config.formdata[$(this).attr('name')];
			$(this).data('tip', tip);

			if ($(this).val() == '')
			{
				$(this).val(tip);
			}
		} else
		{
			$(this).data('tip', '');
		}
	});

	$(config.form_tips).focus( function()
	{
		if ($(this).val() == $(this).data('tip'))
		{
			$(this).val('');
		}
	});

	$(config.form_tips).blur( function()
	{
		if ($(this).val() == '')
		{
			$(this).val($(this).data('tip'));
		}
	});

	$('form').submit( function()
	{
		$(this).find('input, textarea').each( function()
		{
			if ($(this).data('tip') != '')
			{
				if ($(this).val() == $(this).data('tip'))
				{
					$(this).val('');
				}
			}

			$(this).blur();
		});

		if ($(this).find('input.error, textarea.error').length > 0)
		{
			return false;
		}
	});

	// FORM TIPS END


});




