var slide = null;
function bannerRotate() {
  clearTimeout(slide);
  var $active = $('#banner div.active');
  if ( $active.length == 0 ) $active = $('#banner div:first');
  var $next =  $active.next().length ? $active.next() : $('#banner div:first');
  $active.addClass('last-active');
  $next.css({opacity: 0.0})
  .addClass('active')
  .animate({opacity: 1.0}, 700, function() {
    slide = setTimeout('bannerRotate()', 6000);
    $active.removeClass('active last-active');
  });
}
$(document).ready(function() {
	if($("#banner div").length > 1) {
	  setTimeout('bannerRotate()', 6000);
	}

	$("#banner_swf").flash({swf:"/hrd/img/banner3.swf", width:918, height:253});
	$("#charts").flash({swf:"/open-flash-chart.swf", width:610, height:300, flashvars: {"data-file":"/domeny/charts.php"}});
	$("#charts_en").flash({swf:"/open-flash-chart.swf", width:610, height:300, flashvars: {"data-file":"/domeny/charts.php?lang=en"}});

	$("#body .lang a[class!=a]").css({'opacity':0.4});
	$("form.form").submit(function() {
		$("p.red").remove();
		$.post("/hrd/mail.php", $(".form [name]").serialize(), function(data) {
			if(data.status == true) {
				$("form.form").before("<p class='green'>Mail send</p>");
				$("form.form [name]").val("");
			} else {
				$("form.form").before("<p class='red'>Change required inputs</p>");
			}
		}, "json");
		return false;
	});

	$("#price td.price").hover(function() {
		idx = $(this).parent().find('td').index($(this));
		idx_tr = $("#price tr").index($(this).parent());
		if(idx_tr%2!=0) idx++;

		$("#price tr").each(function(i, item) {
			if(i == 1) {
		      _idx = idx-2;
		      td = $(item).find('td').get(_idx);
		      $(td).addClass("a");
		    }
			if(i > 1) {
			    if(i%2==0) _idx = idx; else _idx = idx-1;
				td = $(item).find('td').get(_idx);
				$(td).addClass("a");
			}
		});
	}, function() {
		$("#price td.a").removeClass("a");
	});

	$("a[rel=fancybox]").fancybox();
});

