function li()
{
  var window = document.body.clientWidth;
  if (window >= 1250 && window <= 1450)
  {
    $('.last_item_is_banner').hide()
  }
  else {
    $('.last_item_is_banner').show()
  }
}
$(function() { li(); });
$(window).resize(function() { li(); });
$(document).ready(function(){

	$('a.reviewLink').click(function(){
	$(window).scrollTop(0);

	$('#dark').show();
	$('#data').show();
	var ki_ua = window.navigator.userAgent;

	if (ki_ua.indexOf ("MSIE") >= 0) {
			if( parseInt(ki_ua.substr(ki_ua.indexOf("MSIE")+5, 3)) < 7 ){ 
			
	$("#hvost").css("display", "none");
	}}
	$("#data #errors2").html("");
	$("#data2 #errors2").html("");
	return false;

	});
	$('a.suggestionLink').click(function(){
	$(window).scrollTop(0);
	$('#dark').show();
	$('#data2').show();
	var ki_ua = window.navigator.userAgent;

	if (ki_ua.indexOf ("MSIE") >= 0) {
			if( parseInt(ki_ua.substr(ki_ua.indexOf("MSIE")+5, 3)) < 7 ){ 
			$("#hvost2").css("display", "none");
	}}
	$("#data #errors2").html("");
	$("#data2 #errors2").html("");
	return false;

	});
		$('#data .close_data_window a').click(function(){
		$('#dark').hide();
		$('#data').hide();
		});
		
		$('#answer_otzyv .close_data_window a').click(function(){
		$('#answer_otzyv').hide();
		$('#dark').hide();
		});
		
		$('#data2 .close_data_window a').click(function(){
		$('#dark').hide();
		$('#data2').hide();
		});



	var hover_mover = $('#nav').find('div.hover_mover').children('b');
	
	hover_mover.mouseover(function(){
		
		$('#nav').find('li.active').removeClass('active');
		$('#nav').find('li.preActive').removeClass('preActive');
		
		var active_item = $(this).parent().parent();
		active_item.addClass('active');
		active_item.prev('li').addClass('preActive');
	});
	
	
	$('#nav').find('li.active').find('ul').live('mouseleave',function(){
		
		$('#nav').find('li.active').removeClass('active');
		$('#nav').find('li.preActive').removeClass('preActive');
	});
	
	$('#nav p a:contains(Модельный ряд)').replaceWith('<span>Модельный ряд</span>');
	$('#nav p a:contains(Услуги)').replaceWith('<span>Услуги</span>');
	
	$('#nav').live('mouseleave',function(){
		
		$('#nav').find('li.active').removeClass('active');
		$('#nav').find('li.preActive').removeClass('preActive');
	});
		
	/* $('#clients a.choice').click(function(){
		
		$(this).parent().parent().find('div').toggle();
		$('div.phones').find('div').toggle();
		return false;
	}); */
	
	$('#catalog_tabs div.switch_tab li.tab_sw').click(function(){
	
		var tabs = $(this).parent().parent().parent('div.tabs');
		var switch_tab = tabs.children('div.switch_tab');
		var switch_content = tabs.children('div.switch_content');
		var index_element = $(this).index();
		
		switch_content.find('div.content_sw div.article_block').hide();
		switch_content.find('div.content_sw div.article_block:eq(' + index_element + ')').show();
		
		/* if(index_element == 2) {switch_content.find('div.content_sw div.sb_block').hide();}
		else {switch_content.find('div.content_sw div.sb_block').show();} */
		
		switch_tab.find('li.orangeButton').removeClass('orangeButton');
		$(this).addClass('orangeButton');
	});
	
	$('div.article ul').each(function(){
		var listStyleType = $(this).css('list-style-type');
		var ulClass = $(this).attr('class');
		
		if( listStyleType == 'none' && ulClass == '') {
			$(this).addClass('tirelist');
		}
	});
	$('div.article:not(.table_form) table').attr('border','0');
	$('div.article table:not(.table_form) tr:odd').addClass('odd');
	
	$('div.filter_car').bind('click',function(e){
		
		var items_list = $(this).children('ul:first');
		var object_list = $(this).children('ul:last');
		
		item_clicked = $(e.target);
		if( item_clicked.is('li,span') )
		{
			if( item_clicked.is('span') ) {item_clicked = item_clicked.parent();}
			
			if( item_clicked.parent().is('#car_items') )
			{
				
				if( item_clicked.is('.all_cars') ) 
				{
					object_list.find('li').show();
					items_list.find('li.active').removeClass('active');
					item_clicked.addClass('active');
					object_list.find('h2').show(); 

					return false;
				}
				
				clicked_class = item_clicked.attr('class').slice(5);
				object_list.find('li').hide();
				object_list.find('h2').hide();
				object_list.find('li.typeid_' + clicked_class).show();
				items_list.find('li.active').removeClass('active');
				item_clicked.addClass('active');
			}
		}
	});
	
	
	
	$('div.filter_car').trigger('click');
	
	$('#choice_town a.choice').click(function(){$('#choice_town').children('div').toggleClass('active_shadow');return false;});
	$('#choice_town').find('ul').mouseleave(function(){$('#choice_town').children('div').toggleClass('active_shadow');});
	$('div.call_back a').click(function(){$('#callback').toggle();return false;}); 
	$('#callback').mouseleave(function(){$(this).toggle();});
	  $('.forToggle').toggle(function(){
		$(this).next().show() 
	  },function(){
		$(this).next().hide()
	  });
	
	$('#cars_gallery li.last_item_is_banner').click(function(){
		
		var orangeButton = $('div.tabs div.switch_tab ul').find('li.orangeButton').removeClass('orangeButton');
		orangeButton.next('li').addClass('orangeButton');
		
		$('div.switch_content div.content_sw').hide();
		$('div.switch_content div.content_sw:eq(1)').show();
		
		return false;
	});
	
	
	function gup( name )
	{
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		var regexS = "[\\?&]"+name+"=([^&#]*)";
		var regex = new RegExp( regexS );
		var results = regex.exec( window.location.href );
		if( results == null )
		return "";
		else
		return results[1];
	}
	
	var month_index = gup( 'month' );
	if( month_index )
	{
		var active_month = $('ul.months').find('a[rel="' + month_index + '"]');
		active_month.css('border','1px solid red');
		var active_month_text = active_month.text();
		active_month.replaceWith('<span>' + active_month_text + '</span>');
	}
		$('div.news_arhive div.years a').bind('visibility_hide_month',function(){
		
		newsArhive = $('div.news_arhive');
		divYear = newsArhive.find('div.years');
		ulMonths = newsArhive.find('ul.months');
		
		firstYear = ulMonths.eq(0);
		lastYear = ulMonths.eq( ulMonths.length - 1 ); 
		
		firstYear.addClass('first');
		lastYear.addClass('last');
		
		divYear.find('a.prev').css('visibility','visible');
		divYear.find('a.next').css('visibility','visible');
		
		if( $(this).is('.prev') ) {
			year--;
			if( newsArhive.find('ul.y' + year).is('.first') ) {
			
				$(this).css('visibility','hidden');
				divYear.find('a.next').css('visibility','visible');
			}
		}
		
		if( $(this).is('.next') ) {
			year++;
			if( newsArhive.find('ul.y' + year).is('.last') ) {
			
				$(this).css('visibility','hidden');
				divYear.find('a.prev').css('visibility','visible');
			}
		}
		
		divYear.find('span').html(year);
						
		var newsArhive = divYear.parent('div.news_arhive');		
		newsArhive.find('ul.months').hide();
		newsArhive.find('ul.y' + year).show();
		
		return false;
	});
	
	$('div.news_arhive div.years a').click(function(e){
		
		ClickedClass = $(e.target).attr('class');
		year = $('div.news_arhive div.years span').html();
		$('div.news_arhive div.years a.' + ClickedClass).triggerHandler('visibility_hide_month', [year]);
		
		return false;
	});
	
	year_index = gup( 'year' );
	month_index = gup( 'month' );
	
	if( year_index && month_index ) {
		$('ul.y' + year_index + ' li[rel=' + month_index + ']').addClass('active');
	}
	
	if( year_index ) {
	
		if( $('div.news_arhive').find('ul.y' + year_index).is(':hidden') ) {
			year_index = parseInt(year_index);
			year = year_index + 1;
			$('div.news_arhive div.years a.prev').triggerHandler('visibility_hide_month', [year]);
			
			return false;
		}
		else {return false;}
	}
	
});


function hvost(){	
var ki_ua = window.navigator.userAgent;

	if (ki_ua.indexOf ("MSIE") >= 0) {
			if( parseInt(ki_ua.substr(ki_ua.indexOf("MSIE")+5, 3)) < 7 ){ 
			$("#hvost3").css("display", "none");
	}}		
					}
