function ss() {

    var $active = $('#images .active');

    if ( $active.length == 0 ) $active = $('#images img:last');

    var $next =  $active.next().length ? $active.next() : $('#images img:first');

    $active.addClass('last-active');
     $next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function() {
        $active.removeClass('active last-active');
     });

}

$(document).ready(function(){

	$('a').focus(function() {
		this.blur();
	});
	
   if	($("ul#topmenu li.selected:last-child").is(":visible"))
		$("div#header div.right").addClass("lasthov");
	else {
		$("ul#topmenu li:last-child a").hover(function(){$("div#header div.right").addClass("lasthov")},function(){$("div#header div.right").removeClass("lasthov")});
	}
	
	Cufon.replace('.text h1, .text h2, .text h3, div#top2 h2, div#menu h2');
 	
	function formatTitle(title, currentArray, currentIndex, currentOpts) {
	    return '<div id="tip7-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="/img/fancybox/closelabel.gif" /></a></span>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + '&nbsp;</div>';
	}
		
	$("a.lightbox, table.gallery a, ul.photos a").fancybox({
		'showCloseButton'		: false,
		'titlePosition' 		: 'inside',
		'titleFormat'			: formatTitle	
	});	
	
	$("#activelang").html ( $("#selectlang ul li.active a").html() );
	
	$("#activelang").click(function(e) {
		e.stopPropagation();
		
		if ($("#selectlang ul").is(":visible"))
			$("#selectlang ul").slideUp();
		else
			$("#selectlang ul").slideDown();
			
	});	
	
	$("body").click(function() {
		$("#selectlang ul").slideUp();
	});
	
    var form_kontakt = $("#form_kontakt").validate({
    rules: {
        'name'  : "required",
        'email': { required: true, email: true },
		  "tel"	: "required",
		  "msg"	: "required"			
    },
    messages: {
        'name'  : "",
			'email'  : "",
			'tel'  : "",
			"msg" : ""
    },

    errorPlacement: function(error, element) {
        if ( element.is(":radio") )
            error.appendTo( element.parent().next().next() );
        else if ( element.is(":checkbox") )
            error.appendTo ( element.next() );
        else
            error.appendTo( element.parent() );
    }
    
    });	
	 
    var form_zapyanie = $("#form_zapytanie").validate({
    rules: {
        'name'  : "required",
        'email': { required: true, email: true },
		  "tel"	: "required"	
    },
    messages: {
        'name'  : "",
			'email'  : "",
			'tel'  : ""
    },

    errorPlacement: function(error, element) {
        if ( element.is(":radio") )
            error.appendTo( element.parent().next().next() );
        else if ( element.is(":checkbox") )
            error.appendTo ( element.next() );
        else
            error.appendTo( element.parent() );
    }
    
    });		 	
	
	var sitemap = $("#sitemap");
	var sitemapH = sitemap.outerHeight();
	sitemap.css("bottom", -sitemapH + "px").hide();

	$("a[href=#sitemap]").click(function()
	{
		if (sitemap.is(":animated"))
			return false;
		if (sitemap.is(":visible"))
			sitemap.stop(true).animate({ bottom:  -sitemapH + "px" }, 750, "swing", function() { $(this).hide(); });
		else
			sitemap.show().stop(true).animate({ bottom: "0px" }, 750, "swing");
		return false;
	});
	
	$('#sitemap').animate({opacity: "0.9"});	
	
   setInterval( "ss()", 4000 );
		
	$('table.zebra tr:even').addClass('even');				
		
});
