$(window).resize(function() {

/*    i1 = $('.next').position().left -44; */
    var wx = $(window).width() / 2 + 491;
    $('#icon').css('left',wx+'px');
    
});
    
$(document).ready(function() {
	function isCookieSet(){
		if(document.cookie.length>0){var i=document.cookie.indexOf("updateie6=");return(i!=-1);	}
		return false;
	}
	var needUpgrade=/(MSIE 6|MSIE 5.(\d+))/i.test(navigator.userAgent);if(needUpgrade&&!isCookieSet()){$("body").prepend('<div class="updateie6" style="display:none;" ><div><p><strong>Web Svaroh Active nepodporuje zastaralé prohlížeče</strong><br />Pro plnohodnotné prohlížení těchto stránek si prosím aktualizujte svůj Internet Explorer například <a href="http://www.microsoft.com/cze/windows/internet-explorer/">zde</a><br />nebo využijte jeden z alternativních prohlížečů:<span class="chrome"><a href="http://www.google.com/chrome/">Google Chrome</a></span><span class="firefox"><a href="http://www.mozilla.com/cs/">Mozilla FireFox</a></span><span class="opera"><a href="http://www.opera.com/">Opera</a></span></p><span id="hideme" style="display: none;"><a href="#" id="goaway">Skrýt</a></span></div></div>');$('div.updateie6').slideDown('slow');$("span#hideme").fadeIn("slow");$("a#whyupgrade").click(function(){$("div#whyupcontent").slideDown("slow");});$("a#goaway").click(function(){$("div.updateie6").slideUp("fast",function(){$(this).remove()});var exp=new Date();exp.setTime(exp.getTime()+(7*24*3600000));document.cookie="updateie6=hide; expires="+exp.toUTCString();});};

	$('body').addClass('jsok');

	if ($('body').hasClass('home')) {
		$('html').addClass('home');
	}
	
	$("#query").labelify({text: "label",labelledClass: "labelhi"});
	$(".perex").each(function(){
		var w = $(this).siblings('h2').width() + 95 + 16 + 50; // 95 = date, 16 = arrow
		$(this).width(w);
		$(this).corner({
			tl: { radius: 5 },
			tr: { radius: 5 },
			bl: { radius: 5 },
			br: { radius: 5 },
			antiAlias: true
		});
		$(this).hide();
     });

	$('#button, #popup .close, #popup2 .close').click(function(){
		$('body').toggleClass('auto');
		$('#nav').animate({width:'toggle'},300,function(){$('#button').toggleClass('off');});
		$('#news, #news2, #gallery, #popup, #popup2, #footer,#lang, .pagination').toggle();
		return false;
	});

	$('a[href="#comments"]').click(function(){
       $('#comments').slideDown(300,function(){$.scrollTo( '#comments',800); });
	   return false;
	});

	$('#gallery li').click(function(){
		var link = $(this).children('a').attr('href');
		location.href = link;
	});

	var s = parseInt($.cookie('svaroh'));
	if (isNaN(s)) s = 0;
	if (s == 0) { $('.prev').addClass('disabled'); };
	if (s == 27) {$('.next').addClass('disabled');};
	$(".home #carousel").jCarouselLite({
		visible: 4,
		speed:250,
		btnNext: ".next",
		btnPrev: ".prev",
		afterEnd: function(a) {
			$.cookie('svaroh', a[0].id);
		},
		circular:false,
		start:s
	});

	$('.prev,.next').click(function(){
		return false;
	});

	if (location.href.indexOf('#comments') != -1) {
       $('#comments').show();
	   $.scrollTo( '#comments',800);
	}

	if ($('body').hasClass('unvisible')) {
		initPreloader();
	}

	$('#section a').wrapInner('<span class="link">');
	$('.home #carousel li').each(function(index) {
		this.id = index;
	});

	$("#bckg").ezBgResize();

/*    i1 = $('.next').position().left -44; */
    var wx = $(window).width() / 2 + 500;
    $('#icon').css('left',wx+'px');

});

function initPreloader() {
  $('html,body').css('overflow','hidden');
  var w = $(window).width() / 2 - 66;
  var ww = $(window).width();
  var h = $(window).height() / 2 - 37;
  $('#intrologo').css('left',w).css('top',h);
  $('#loadbar, #percent').css('top',h + 80);
  $('#foobar').animate(
		{width:'100%'},
		{
			duration:5333,
			complete:function(){
				$('#intro,#intrologo,#percent').empty().remove();
	            $('html,body').css('overflow','auto');
				$('body').removeClass('unvisible');
			},
			step:function(){
				var x =$("#foobar").width();
				$('#percent').html(Math.abs(Math.floor(x / ww * 100)-1)+'%');
			}
	});
  var newOptions = {
    domain: '.svarohactive.cz',
    path: '/'
  }
  $.cookie('preloader', '1', newOptions);
}
