var slidecnter = 0;
$(function(){
	$("#left_sidebar .h_lm").click(function(){
		if(!$(this).hasClass("active")){
			$(this).insertAfter($(".active"));
			$(".h_lm").removeClass("active");
			$(this).addClass("active");
			if($("img", $(this)).hasClass("mir")){
				$("ul.mir").show();
				$("ul.rus").hide();
				$("a.rus1").hide();
				$("a.mir1").show();
				$("img.mir").attr("src", "/img/mir_a_act.png");
				$("img.rus").attr("src", "/img/rus_a.png");
			}else{
				$("ul.mir").hide();
				$("ul.rus").show();
				$("a.rus1").show();
				$("a.mir1").hide();
				$("img.mir").attr("src", "/img/mir_a.png");
				$("img.rus").attr("src", "/img/rus_a_act.png");
			}					
		}
		return false;
	});
	if($("#big_block_img img.big").length > 0){
		$("#big_block_img img.big").hide();
		$("#big_block_img img.big:first").show();
		$(".oval_t .rp_bbi p").text(headn[slidecnter]);
		setInterval(function(){
			$("#big_block_img img.big").fadeOut(2000);
			setTimeout(function(){
				$("#big_block_img img.big:eq("+slidecnter +")").fadeIn(2000);
				$(".oval_t .rp_bbi p").text(headn[slidecnter]);
				if(Cufon!='undefined') Cufon.replace(".oval_t .rp_bbi p");
			}, 2000);
			slidecnter ++;
			if(slidecnter >= $("#big_block_img img.big").length) slidecnter = 0;
		}, 20000);
	}
	$("a[rel=gal]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'overlayOpacity'	: '0.97',
		'overlayColor'		: '#ffffff',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-inside">'+title+' (' +  (currentIndex + 1) + ' из ' + currentArray.length + ')</span>';
	}});
	$(".tourdetail1 div").each(function(){
		if($("img", this).length < 1){
			//if($(this).text() == '') $(this).hide();
			
			text = $(this).text();
			first = text[0];
			if(first != undefined){
				i = 1;
				if(first==' '){ first = text[1]; i=2;}
				if(first==' '){ first = text[2]; i=3;}
				newtext = '';
				for(;i<text.length;i++) newtext += text[i];
				if(first=='' || first==' ' || first=='\n'){
					$(this).hide();
				}else{
					$(this).html('<span class="i">'+first+'</span>' + newtext);
					if(window.navigator.userAgent.match("Opera"))
						$("span.i", $(this)).css({"margin-bottom":"-10px","margin-top":"0px","display":"inline"});
					else
						$("span.i", $(this)).css({"margin-top":"13px"});
				}
			}
		}
	});
	$(".tourdetail1 p").each(function(){
		if($("img", this).length < 1){
			text = $(this).text();
			first = text[0];
			if(first != undefined){
				i = 1;
				if(first==' '){ first = text[1]; i=2;}
				if(first==' '){ first = text[2]; i=3;}
				newtext = '';
				for(;i<text.length;i++) newtext += text[i];
				if(first=='' || first==' ' || first=='\n'){
					$(this).hide();
				}else{
					$(this).html('<span class="i">'+first+'</span>' + newtext);
					if(window.navigator.userAgent.match("Opera"))
						$("span.i", $(this)).css({"margin-bottom":"-10px","margin-top":"0px","display":"inline"});
					else
						$("span.i", $(this)).css({"margin-top":"13px"});
				}
			}
		}
	});

	$("a.num_up").click(function(){if($("input.num").val() < 1) $("input.num").val(1); else{var num=$("input.num").val(); num++; $("input.num").val(num);} return false;});
	$("a.num_down").click(function(){$("input.num").val($("input.num").val()-1); if($("input.num").val() < 1) $("input.num").val(1); return false;});
	$(".form_item form").submit(function(){
		var error = "";
		if($("input.person").val()=="") error += "Вы не указали контактное лицо\n";
		if($("input.contact").val()=="") error += "Укажите контактную информацию\n";
		if($("input.num").val()=="") error += "Внесите количество человек\n";
		if(error!=""){
			alert(error);			
		}else{
			$.post("/inc/ajax/sendform.php", {
				"person":$("input.person").val(),
				"contact":$("input.contact").val(),
				"num":$("input.num").val(),
				"link":location.href
			}, function(){$(".form_item form")[0].reset(); alert("Спасибо, ваша заявка принята.");});
		}
		return false;
	});
	$(".feedback form").submit(function(){
		var error = "";
		if($("input.name").val()=="") error += "Вы не ввели своё имя\n";
		if($("input.phone").val()=="") error += "Укажите телефон\n";
		if($("textarea.mess").val()=="") error += "Введите текст сообщения\n";
		if(error!=""){
			alert(error);			
		}else{
			$.post("/inc/ajax/feedback.php", {
				"person":$("input.name").val(),
				"phone":$("input.phone").val(),
				"mess":$("textarea.mess").val(),
				"link":location.href
			}, function(){$(".feedback form")[0].reset(); alert("Спасибо, ваше сообщение отправлено.");});
		}
		return false;
	});
	$(".oval_t .rp_bbi").click(function(){
		if(headt[slidecnter]!="") location.href=headt[slidecnter];
	});
	$(".lp_bbi .name_yy").click(function(){
		//if(headc[slidecnter]!="") location.href=headc[slidecnter];
		location.href="/tours/";
	});
	$(".lp_bbi i").click(function(){
		//if(headc[slidecnter]!="") location.href=headc[slidecnter];
		location.href="/tours/";
	});
	$(".openrus").click(function(){document.scrollTop=0; $("#lbbackground").height($(document).height()).fadeIn(); $("#ruspopup").fadeIn();});
	$(".openmir").click(function(){document.scrollTop=0; $("#lbbackground").height($(document).height()).fadeIn(); $("#mirpopup").fadeIn();});
	$(".main_lightbox .esc").click(function(){$(this).parent().parent().fadeOut();});
	$("#lbbackground").click(function(){$("#ruspopup").fadeOut(); $("#mirpopup").fadeOut(); $("#lbbackground").fadeOut();});

	$(".printlink").click(function(){
		window.open(this.href, "Версия для печати", "width=600,height=700,scrollbar=1");
		return false;
	});
	$("a.banner_1").each(function(){
		if(this.rel != ''){
			var targ = $(this);// alert($("div:eq(0)", targ).text());
			$("span:eq(1)", targ).css('display', "block");
			$("span:eq(1) div", targ).hide();
			$("span:eq(1) img", targ).hide();
			setInterval((function(targ_){ return function(){
				if(!$("span:eq(0)", targ).hasClass('hid')){					
					$("span:eq(0) div", targ).fadeOut(1000);
					$("span:eq(0) img", targ).fadeOut(1000);
					$("span:eq(1) div", targ).fadeIn(1000);		
					$("span:eq(1) img", targ).fadeIn(1000);
					$("span:eq(0)", targ).addClass("hid");
				}else{
					$("span:eq(1) div", targ).fadeOut(1000);
					$("span:eq(1) img", targ).fadeOut(1000);
					$("span:eq(0) div", targ).fadeIn(1000);					
					$("span:eq(0) img", targ).fadeIn(1000);
					$("span:eq(0)", targ).removeClass("hid");
				}
			}})(targ), this.rel*1000);
		}
	});
});

function cuf(){
	var line = "h1, h2, h4, h5, h3, h6, #line_news .banner_1 .txt_banner_1 p, .l_date, .r_date, .cont_tel, #big_block_img .lp_bbi, #big_block_img .rp_bbi, #search_tur, .how_mest, .some_country .price, .send_us, .from_catal, .to_catal, .date_tc, #top_content h2, .this_day, .main_all_text p span.i, .main_all_text div span.i, .top_cont_rig, .pay_in h2, .pay_out h2, .add_pay h2, .line_top_content p, .banpl_item .banner_item .txt_banner_1 p";
	Cufon.replace(line);
	$(line).css('display','block');
}		
