ingateAllPages = function(){
	$("input.inputSearch").focus(function(){
		if ( $(this).attr("value") == "поиск" ){
			$(this).attr({"value": ""});
		}
	});
	$("input.inputSearch").blur(function(){
		if ( $(this).attr("value") == "" ){
			$(this).attr({"value": "поиск"});
		}
	});
	$("input.clearme").focus(function(){
		if ( $(this).attr("title") == $(this).attr("value") ){
			$(this).removeAttr("value");
		}
	});
	$("input.clearme").blur(function(){
		if ( $(this).attr("value") == "" ){
			$(this).attr({"value": $(this).attr('title')});
		}
	});
	$("#toggle-menu li.toggle-close div").hide();
	$("#toggle-menu>li>a").click(function(){
		$(this).find('~div').slideToggle();
		return false;
	});
	$('ul.reddotted>li>a').click (function(){
		var path = this.href.match ( /(\d)$/gi );
		$('body').find('a[name='+path[0]+']').each ( function() {
			if ( this.parentNode.parentNode.nodeName.toLowerCase() == 'li' ) {
				$(this.parentNode.parentNode).click();
			}
		});
	});
}

bxAccordion = function ( idElm, headerSelector, panelSelector, activeClass ) {
	var panelHeight = 300;
	$('#'+idElm).find(panelSelector).each ( function () {
		if( Number ( this.offsetHeight ) > panelHeight ) panelHeight = Number ( this.offsetHeight ); 
	});
	$('#'+idElm).Accordion( {
					headerSelector	: headerSelector,
					panelSelector	: panelSelector,
					activeClass		: activeClass,
					panelHeight		: panelHeight,
					speed			: 300
				}
	);
}

initDaysAnimate = function () {
	$('ul.days li span').click(function(){
	
		if (!$(this).hasClass('off'))
			{
				//$('ul.days li span').removeClass('off');
				$(this).addClass('off');
				
				//$('ul.days li div.opened').slideUp('slow'); //скрываем расписание текущего дня
				$('ul.days li div.opened').removeClass('opened');
				
				$(this).next('div').slideDown('fast');
				$(this).next('div').addClass('opened');
			}
		else
			{
				$(this).removeClass('off');
				$(this).next('div').slideUp('fast');
			}
		
		ChangeDaysText();
	});
}

ChangeDaysText = function () {
		//меняем текст в "Показать все" - "Скрыть все"
		
		var total = $('ul.days li span').length; //дней всего
		var opened = $('ul.days li span.off').length; //дней открытых
		
		if (opened > (total-opened))
			{$('#showhide').html("Скрыть все");}
		else{$('#showhide').html("Показать все");}
}

initShowHideAnimate = function(){
	$('#showhide').click(function(){
		var total = $('ul.days li span').length; //дней всего
		var opened = $('ul.days li span.off').length; //дней открытых
		
		if (opened > (total-opened))
			{
				$('ul.days li div').slideUp('fast');
				$('ul.days li span').removeClass('off');
			}
		else{
				$('ul.days li div').slideDown('fast');
				$('ul.days li span').addClass('off');
			}
		
		ChangeDaysText();
		return false; //по ссылке никуда не переходим
	});
};

initHorizontAnimate = function () {
	$('#main_menu li').hover
	(
		function()
			{
				$(this).child('#main_menu li ul.sub').show('fast');
			},
		
		function()
			{
				 $(this).child('#main_menu li ul.sub').hide('fast'); 
			}
	);
	$('#main_menu li ul.sub').hover
	(
		function()
			{
				$(this).show('fast');
			},
		
		function()
			{
				$(this).hide('fast');
			}
	);
}

initTabsAnimate = function () {

	if (!window.location.hash)
		{
			$("#grey5").show();
			$("ul.reddotted_wide li:first").addClass('cur');
		}
	
	$('ul.reddotted_wide li span').click(function(){
	
		$('ul.reddotted_wide li').removeClass('cur'); //делаем все табы неактивными
		$(this).parent('li').addClass('cur'); //делаем текущий таб активным
			
		$('div.grey').hide();
				
		var num = $(this).children('a').attr('name');
		
		$('div#grey'+num).show();
        if(num == 7)
            YMaps.load(loadMap);
	})
	
	$('ul.reddotted li a').click(function(){
	
		var num = $(this).attr('rel');
		
		if (num == 4 || num == 5 || num == 6)
			{
				$('div.grey').hide();
				$('div#grey'+num).show();
				
				$('ul.reddotted_wide li').removeClass('cur');
				$('ul.reddotted_wide li a[@name = '+num+']').parents('li').addClass('cur');
			}	
	})
}

function to6(arr) {
    for(i = 0; i < arr.length; i++) {
        var val = costs[arr[i]][arr[i+1]];
        $('#group_'+arr[i]).val(val);
        i++;
    }
    $('#grey4').hide();
    $('#grey6').show();
	$('ul.reddotted_wide li').removeClass('cur');
	$('a[name=6]').parents('li').addClass('cur');
    setCost();
}


initCover = function(){
	$(".cover_content").hide();
    $("#programmList").show();
	$(".cover").click(function(){
		$(this).next("div.cover_content").slideToggle();
        if(this.id == 'mapContainer')
            map.redraw();
		$(this).find("span.arr").toggleClass("active");
	});
}
initChooseDate = function(){
	iDate = $("#chooseDateNow");
	iClose = $("#showDatePopup .close");
	iDate.click(function(){
		var offsetThis = $(this).offset();
		var offsetWrap = $("#content table.desc").offset();
		var xQ = offsetThis.left;
		var yQ = offsetThis.top;
		var xW = offsetWrap.left;
		var yW = offsetWrap.top;
		var x = Math.floor(xQ - xW);
		var y = Math.floor(yQ - yW);
		$("#showDatePopup").show().css({
			'left' 		: x - 11,
			'top' 		: y - 11
		});
		return false;
	});
    /*
    $("#showDatePopup .inactive").click(function(){
        $("#no_reserv").show(300);
        setTimeout(function(){$("#no_reserv").hide(300)}, 2000);
        return false;
    });
    */
	iClose.click(function(){
		$(this).parents("#showDatePopup").hide();
		return false;
	});
}
initOrderSteps = function(){
	
}

$(document).ready(function(){

		$(function(){
			$('#special_slider').anythingSlider();
		});
    initAutoSlider();

	initCover();
	initChooseDate();
	initOrderSteps();
	
	ingateAllPages();
	initDaysAnimate();
	initTabsAnimate();
	initShowHideAnimate();
	ChangeDaysText();
	//initHorizontAnimate();
//	$('input.datetime').datePicker({startDate:'01/01/1900'});
//	$('input.datetime').dpSetPosition($.dpConst.POS_TOP, $.dpConst.POS_RIGHT);
	
	

		  /*.hover(
				function() {
					alert(11);
					$(this).children("div.turkarta-popup").show();
				}, 
				function() {
					alert(22);
					$(this).children("div.turkarta-popup").hide();
				}*/
				
				
				
				
	/* PHOTO SLIDER */
	var frame_size = 250;
	var frame_elem = $("#photo_thumb_inner ul");
	var elem_size = 86;
	var img_count = $("#photo_thumb_inner ul li").size();
	var elem_count = Math.round(img_count/2);
	var frame_count = 6;
	if ($(window).width() <= 1088) frame_count = 3;
	if (($(window).width() > 1088) && ($(window).width() <= 1280)) frame_count = 7;
	var frame_actions = elem_count - frame_count;
	var frame_elem_size = elem_size*elem_count;
	var slider_scale = (elem_size*elem_count)/height;
	var value_range = frame_actions*elem_size;
	var i = 0, j = 0;

	$("#photo_thumb_inner").css("overflow","hidden");
	var height = elem_size*elem_count;
	frame_elem.height(height);
	
	$("#content a.photo_up").click(function(){
		if (i > 0){
			i--;
			val = elem_size*(-i);
			frame_elem.animate({"top": val}, 300);
			$("#photo_slider").slider( "value", (frame_actions - i)*elem_size );
			
		}
		return false;
	});
	$("#content a.photo_down").click(function(){
		if (i < frame_actions){
			i++;
			val = elem_size*(-i);
			frame_elem.animate({"top": val}, 300);
			$("#photo_slider").slider( "value", (frame_actions - i)*elem_size );
		}
		return false;
	});

	$("#photo_slider").slider({
		orientation: "vertical",
		range: "max",
		value: value_range,
		min: 0,
		max: frame_actions*elem_size,
		slide: function(event, ui) {
			slide_pos = ui.value - frame_actions*elem_size;
			frame_elem.css("top", slide_pos);
			i = frame_actions - Math.round(ui.value/elem_size);
		}
	});
	
	
	var img_small = $("#photo_thumb_inner li");
	
	$("#content a.photo_prev").click(function(){
		if (j > 0){
			j--;
			img_small.eq(j).click();
			step = Math.floor(j/frame_actions);
		}
		return false;
	});
	$("#content a.photo_next").click(function(){
		if (j < img_count - 1){
			j++;
			img_small.eq(j).click();
			step = Math.floor(j/frame_actions);
		}
		return false;
	});
	
	
	$("#photo_thumb_inner li a").click(function(){
		$(this).parents("li").click();
		return false;
	});
	
	img_small.click(function(){
		if (!$(this).hasClass("active")){
			var index = img_small.index(this);
			j = index;
			var preview_src = $(this).find("a").attr("href");
			var big_src = $(this).find("a").attr("rel");
			var desc = $(this).find("img").attr("alt");
			
			$("#photo_preview a:visible").animate({"opacity":0}, 300, function(){
                $(this).hide();
                $("#photo_preview a:eq("+j+")").show().ready(function(){
					$(this).animate({"opacity": 1}, 300);
				});
                if($("#photo_preview a:eq("+j+")").ready)
					$(this).animate({"opacity": 1}, 300);
			});
			
			$("#photo_thumb_inner li").removeClass("active");
			$(this).addClass("active");
			$("#photo_gallery_left p.photo_name").html(desc);
		}
		return false;
	});
	
	// фотогалерея в /marshrut
	// если картинок не так много, то убираем скролл
	if (($('#photo_gallery').width() >= 1133) || ($('#photo_thumb_inner ul li').size() <= 12)) {
		$('#photo_slider').hide();
		$('.photo_up').hide();
		$('.photo_down').hide();
	}

// функция обрезки лишних символов
function trim(value){
val = value.replace(/^([\s]*)/g,"");
val = val.replace(/([\s]*)$/g,"");
	return val;
};

// поиск
$(".input_wrapper input").focus(function(){
	if ($(this).attr("value") == $(this).attr("title")) {
		$(this).attr("value", "");
	}
});
$(".input_wrapper input").blur(function(){
	if (trim($(this).attr("value")) == "") {
		$(this).attr("value", $(this).attr("title"));
	}
});
	
});


initAutoSlider = function() {
    var isMouseOver = false;
    $('.anythingSlider').mouseover(function(){
        isMouseOver = true;
    });
    $('.anythingSlider').mouseout(function(){
        isMouseOver = false;
    });
    nextSlide = function() {
        if(!isMouseOver)
            $('span.arrow.forward').click();
    }
    setInterval('nextSlide();', 7000);
}


jQuery(function($){
    $.datepicker.regional['ru'] = { 
        closeText: 'Закрыть',
        prevText: '&#x3c;Пред',
        nextText: 'След&#x3e;',
        currentText: 'Сегодня',
        monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь',
        'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
        monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн',
        'Июл','Авг','Сен','Окт','Ноя','Дек'],
        dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'],
        dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'],
        dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
        weekHeader: 'Не',
        dateFormat: 'dd.mm.yy',
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: ''};
    $.datepicker.setDefaults($.datepicker.regional['ru']);
});


