function slideSwitch() {
  var $active = $('.gallery img.active');
  if ( $active.length == 0 ) $active = $('.gallery img:last');
  var $next =  $active.next().length ? $active.next() : $('.gallery img:first');
  $active.addClass('last-active');
  $next.css({opacity: 0.0})
  .addClass('active')
  .animate({opacity: 1.0}, 1000, function() {
    $active.removeClass('active last-active');
  });
}
function slide(el, turn, handler, f, f_b, time) {
  if(f_b!=undefined) f_b();
  _obj = el.find('div.slide');
  count = _obj.children().length;
  margin = parseInt(_obj.css('marginLeft'));
  act = $(_obj.children().get(0));
  _size = parseInt(act.width())+parseInt(act.css('paddingLeft'))+parseInt(act.css('paddingRight'));
  _show = parseInt(el.find('div.slide').width()/_size);
  if(isNaN(margin)) margin=0;
  if(turn=='left') {
    if(margin==0) return;
    el.find('.sq2_l').unbind('click');
    _obj.stop().animate({'marginLeft':(margin+_size)+'px'}, time, function() { if(f!=undefined) f(); });
  } else if(turn=='right') {
    if((margin/_size) < (0+_show-count)) margin=_size;
    el.find('.sq2_r').unbind('click');
    _obj.stop().animate({'marginLeft':(margin-_size)+'px'}, time, function() { if(f!=undefined) f(); });
  }
}
function to_left(time, f) {
	slide($(".rotator"), 'left', undefined, function() {
		_item = $($(".rotator .slide > div").get(0));
		_w = parseInt(_item.css('width'))+parseInt(_item.css('paddingLeft'))+parseInt(_item.css('paddingRight'));
		marginLeft = parseInt($(".rotator .slide").css('marginLeft'));
		_news = $(".rotator .slide > div:last");
		$(".rotator .slide").prepend(_news);
		$(".rotator .slide").css({'marginLeft': (marginLeft-_w)+'px'});
		if(f!=undefined) f();
	}, function() { }, time);
}
function to_right(time, f) {
	slide($(".rotator"), 'right', undefined, function() {
		_item = $($(".rotator .slide > div").get(0));
		_w = parseInt(_item.css('width'))+parseInt(_item.css('paddingLeft'))+parseInt(_item.css('paddingRight'));
		marginLeft = parseInt($(".rotator .slide").css('marginLeft'));
		_news = $(".rotator .slide > div:first");
		$(".rotator .slide").append(_news);
		$(".rotator .slide").css({'marginLeft': (marginLeft+_w)+'px'});
		if(f!=undefined) f();
	}, function() { }, time);
}
function sq_l() { $(this).unbind('click'); to_left(400, function() { $("#body .sq_l").click(sq_l); }); }
function sq_r() { $(this).unbind('click'); to_right(400, function() { $("#body .sq_r").click(sq_r); }); }
function gen() {
	$("#partners li").css({'cursor':'pointer'}).click(function() {
		$("#partners li").removeClass("a");
		$(this).addClass("a");
		_idx = $("#partners li").index($(this));
		$(".content .item").hide();
		$($(".content .item").get(_idx)).stop().css({'opacity':0}).show().animate({'opacity':1});
		desc = $($(".content .item span.desc").get(_idx)).html();
		$(".content .desc2").stop().css({'opacity':0}).html(desc).show().animate({'opacity':1});
	});
	$("#news li").css({'cursor':'pointer'}).click(function() {
		_idx = $("#news li").index($(this));
		$(".content .item").hide();
		$($(".content .item").get(_idx)).stop().css({'opacity':0}).show().animate({'opacity':1});
	});
	$("#partners li:first").trigger('click');
	$(".partners .sq_l").css({'cursor':'pointer'}).click(sq_l);
	$(".partners .sq_r").css({'cursor':'pointer'}).click(sq_r);
	$(".list").scrollbar();
}
$(document).ready(function() {
	if($.browser.webkit) {
		$("input.aaa").css({'top':'26px'});
	}
	if ( $.browser.msie ) {
		//$("body").css({''});
		$("#menu .menu2 ul").css({'background':'#fff', 'border':'2px solid #bce8f7', 'top':'98px', 'marginLeft':'13px', 'width':'90px'});
		$("#menu .menu2 ul a").css({'marginLeft':'-4px'});
		$("#menu .menu3 ul").css({'background':'#fff', 'border':'2px solid #bce8f7', 'top':'98px', 'marginLeft':'19px'});
		$("#menu .menu3 ul a").css({'marginLeft':'-2px'});
		$("#menu .menu5 ul").css({'background':'#fff', 'border':'2px solid #bce8f7', 'marginLeft':'6px', 'width':'90px'});
		$("#menu .menu3 li").css({'padding-left':'3px', 'padding-right':'0px'});
		$("#menu .menu5 li").css({'padding-left':'4px', 'padding-right':'0px', 'width':'88px'});

		$("#menu .menu2_en ul").css({'background':'#fff', 'border':'2px solid #bce8f7', 'top':'98px', 'marginLeft':'16px', 'width':'90px'});
		$("#menu .menu2_en ul a").css({'marginLeft':'-3px'});
		$("#menu .menu3_en ul").css({'background':'#fff', 'border':'2px solid #bce8f7', 'top':'98px', 'marginLeft':'19px'});
		$("#menu .menu5_en ul").css({'background':'#fff', 'border':'2px solid #bce8f7', 'marginLeft':'6px', 'width':'90px'});

		$("#menu .menu2").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'70px', 'opacity':1}); }, function() { $(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
		$("#menu .menu3").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'50px', 'opacity':1}); }, function() { $(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
		$("#menu .menu5").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'190px', 'opacity':1}); }, function() { $(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });

		$("#menu .menu2_en").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'70px', 'opacity':1}); }, function() { $(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
		$("#menu .menu3_en").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'50px', 'opacity':1}); }, function() { $(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
		$("#menu .menu5_en").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'165px', 'opacity':1}); }, function() {$(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
		if($.browser.version == "9.0") {
			$("#menu li.menu2 ul").css({'paddingTop': '48px'});
			$("#menu .menu3").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'51px', 'opacity':1}); }, function() { $(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
			$("#menu li.menu3 ul").css({'paddingTop': '39px', 'marginLeft':'18px'});
			$("#menu .menu5").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'183px', 'opacity':1}); }, function() { $(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
			$("#menu .menu5 li").css({'line-height':'10px'});
			$("#menu .menu3 li a").css({'marginLeft':'-4px'});
			$("#menu .menu5 li:eq(0) a").css({'marginLeft':'-4px'});
			$("#menu .menu5 li:eq(1) a").css({'marginLeft':'-4px'});
			$("#menu .menu5 li:eq(3) a").css({'marginLeft':'-4px'});
			$("#menu .menu5 li:eq(4) a").css({'marginLeft':'-6px'});
			$("#menu .menu5 li:eq(5) a").css({'marginLeft':'-10px'});

			$("#menu li.menu2_en ul").css({'paddingTop': '48px'});
			$("#menu li.menu3_en ul").css({'paddingTop': '38px'});
			$("#menu li.menu5_en li").css({'line-height':'10px'});
			$("#menu .menu5_en").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'161px', 'opacity':1}); }, function() {$(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
		} else if($.browser.version == "8.0") {
			$("#menu li.menu2 ul").css({'paddingTop': '48px'});
			$("#menu .menu3").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'51px', 'opacity':1}); }, function() { $(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
			$("#menu li.menu3 ul").css({'paddingTop': '39px', 'marginLeft':'18px'});
			$("#menu .menu5").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'183px', 'opacity':1}); }, function() { $(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
			$("#menu .menu5 li").css({'line-height':'10px'});
			$("#menu .menu3 li a").css({'marginLeft':'-4px'});
			$("#menu .menu5 li:eq(0) a").css({'marginLeft':'-4px'});
			$("#menu .menu5 li:eq(1) a").css({'marginLeft':'-4px'});
			$("#menu .menu5 li:eq(3) a").css({'marginLeft':'-4px'});
			$("#menu .menu5 li:eq(4) a").css({'marginLeft':'-6px'});
			$("#menu .menu5 li:eq(5) a").css({'marginLeft':'-10px'});

			$("#menu li.menu2_en ul").css({'paddingTop': '48px'});
			$("#menu li.menu3_en ul").css({'paddingTop': '38px'});
			$("#menu li.menu5_en li").css({'line-height':'10px'});
			$("#menu .menu5_en").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'161px', 'opacity':1}); }, function() {$(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
		}
	} else {
		$("#menu .menu2").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'78px', 'opacity':1}); }, function() { $(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
		$("#menu .menu3").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'60px', 'opacity':1}); }, function() { $(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
		$("#menu .menu5").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'190px', 'opacity':1}); }, function() { $(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });

		$("#menu .menu2_en").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'79px', 'opacity':1}); }, function() { $(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
		$("#menu .menu3_en").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'60px', 'opacity':1}); }, function() { $(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
		$("#menu .menu5_en").hover(function() { $(this).find('ul').height(0).css({'opacity':0}).stop().animate({'height':'165px', 'opacity':1}); }, function() {$(this).find('ul').stop().animate({'height':'0px', 'opacity':0}); });
	}

	$("#buty li").css({'cursor':'pointer'}).click(function() {
		$("#buty li.a").removeClass("a");
		$(this).addClass("a");
		$("#body .buty_main img").stop().hide().css({'opacity':0});
		$("#body .buty_main img").attr("src", $(this).find('img').attr("src"));
		$("#body .buty_main a").attr("href", $(this).find('img').attr("src").replace('crop', 'org'));
		$("#body .buty_main span.title").html($(this).find('span.title').html());
		$("#body .buty_main span.model").html($(this).find('span.model').html());
		$("#body .buty_main span.rozmiar").html($(this).find('span.rozmiar').html());
		$("#body .buty_main img").stop().show().animate({'opacity':1});
		$("a[rel=lightbox]").fancybox({'overlayColor':'#000', 'overlayOpacity':0.8});
	});
	$("#body .sq_l").css({'cursor':'pointer'}).click(sq_l);
	$("#body .sq_r").css({'cursor':'pointer'}).click(sq_r);
	$("a[rel=lightbox]").fancybox({'overlayColor':'#000', 'overlayOpacity':0.8});
	$("a[rel=opis]").click(function() {
		src = $(".buty_main > a > img").attr("src").substr(10).split('.');;
		$.post("/Aopis.php", {"id":src[0]}, function(data) {
			$.fancybox('<div style="width:600px; margin:5px; text-align:justify;">'+data+'</div>');
		}, "html");
	});
});

