	function updateTips( t ) {
		tips.text( t ).addClass( "ui-state-highlight" );
		setTimeout(function() {
			tips.removeClass( "ui-state-highlight", 1500 );
		}, 500 );
	}
		
	function checkLength( o, n, min, max ) {
		if ( o.val().length > max || o.val().length < min ) {
			o.addClass( "ui-state-error" );
			updateTips( "Length of " + n + " must be between " +
				min + " and " + max + "." );
			return false;
		} else {
			return true;
		}
	}

	function checkRegexp( o, regexp, n ) {
		if ( !( regexp.test( o.val() ) ) ) {
			o.addClass( "ui-state-error" );
			updateTips( n );
			return false;
		} else {
			return true;
		}
	}

$(document).ready(function () {
	var popeyeOptions = {
        caption:    false,
        navigation: 'permanent',
        direction:  'right',
        opacity:    1
    }
    
    $( "#l_baner" ).css("right", (document.body.clientWidth/2) + 470);
	$( "#r_baner" ).css("left", (document.body.clientWidth/2) + 470);
    
    $('.ppy').popeye(popeyeOptions);
	$('ul.topnav').superfish();

	$("ul.topnav li a").hover(function() {
		$(this).parent().find("ul.subnav").slideDown('fast').show();
		$(this).parent().hover(function() {
		}, function(){ $(this).parent().find("ul.subnav").slideUp('slow'); });
		}
		).hover(function() { $(this).addClass("subhover"); }, function(){ $(this).removeClass("subhover");
	});
	
	$.easing.custom = function (x, t, b, c, d) {
		var s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	}

    $('#addfav').poshytip({
		className: 'tip-darkgray',
		bgImageFrameSize: 11,
		alignTo: 'target',
		alignX: 'left',
		alignY: 'center',
		offsetX: 5
	});
	
	$('#tip-darkgray').poshytip({
		className: 'tip-darkgray',
		bgImageFrameSize: 11,
		showOn: 'none',
		alignTo: 'target',
		alignX: 'inner-left',
		alignY: 'bottom',
		offsetX: 80,
		offsetY: 20
	});
	
	$(".scrollable").scrollable({ easing: 'custom', speed: 700, circular: true, vertical: true, keyboard: false });
	
	
		$("#contact_dialog").dialog({
			autoOpen: false,
			height: 300,
			width: 540,
			modal: true,
			resizable: false,
			buttons: {
				"Poslať": function() {
					var bValid = true;
					$( "#contact_email" ).removeClass( "ui-state-error" );
					$( "#contact_text" ).removeClass( "ui-state-error" );

					bValid = bValid && checkLength( $( "#contact_email" ) , "email", 6, 80 );
					//bValid = bValid && checkRegexp( contact_email, /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]+$/, "eg. ui@jquery.com" );

					if ( bValid ) {
						$.ajax({ 
							type: 'POST', 
							url: linkPostContact, 
							data: $("#contactform").serialize(),
							success: function(){ window.location = window.location.pathname }
						}) 
						
						$( "#contact_dialog" ).dialog( "close" );
					}
				}
			},
			close: function() {
				$( "#contact_email" ).removeClass( "ui-state-error" );
				$( "#contact_text" ).removeClass( "ui-state-error" );
			}
			});
			
			$('#contact_dialog_link').click(function() {
				$( "#contact_dialog" ).dialog( 'open' );
				return false;
			});
	
	
	
});


