$(document).ready(function(){

	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').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();
		
		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.is('.active') ) {return false;}
			
			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 span.close_callback_window').click(function(){$('#callback').hide()});
	
$('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();
	});
	
	$(document).click(function(e){
		var clickM = $(e.target);
		if( clickM.closest('#callback').length != 1 ) {
			
			$('#callback').hide();
		}
	});
	
	
	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];
	}
	
	$("input[type='submit']").css('cursor','pointer');
	
	
	$('#nav li p.catal a:contains(Услуги)').replaceWith('<span>Услуги</span>');
	$('div.path').each(function(){
		$(this).find('a:contains(Услуги)').replaceWith('<span>Услуги</span>');
	});
	$('#nav li p.catal a:contains(Корпоративным клиентам)').replaceWith('<span>Корпоративным клиентам</span>');
	$('div.path').each(function(){
		$(this).find('a:contains(Корпоративным клиентам)').replaceWith('<span>Корпоративным клиентам</span>');
	});
	
	
	$('span.order_callback').each(function(){
		$(this).click(function(){
			
			$('#order_callback').show();
		});
	});
	
	$('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()
{
  $('.dropSubMenu').css({'height':'1px'});
  $('.topMenuLi').hover(function() {
    $(this).find('.topMenuLink').addClass('onLink');
    $(this).find('.dropSubMenu').show();
    $(this).find('.dropSubMenu').animate({'height':(parseInt($(this).find('.dropSubMenu ul').outerHeight()))+'px' })
  }, function() {
    $(this).find('.topMenuLink').removeClass('onLink');
    $(this).find('.dropSubMenu').stop();
    $(this).find('.dropSubMenu').hide();
    $(this).find('.dropSubMenu').css({'height':'1px'})
  });    
  
  $('.forToggle').toggle(function(){
    $(this).next().show() 
  },function(){
    $(this).next().hide()
  });

  $("a.fancy").fancybox({
    'titleShow' : false,
    'overlayColor' : '#000'
  });
  
  var optionValue = '';
  
  $('#modelInp').val(' ');
  $('#bulkSelector option').remove();
  
 // xmlParser($('#autoSelector option:selected').attr('id'));
  
  $('#autoSelector').change(function(){
    $('#bulkSelector option').remove();
    //$('.modelInp').val(' ');
    $('#autoSelector option:selected').each(function(){
      xmlParser($(this).attr('id'));
      $('.modelInp').val($(this).text());
    })    
  });

  $('#bulkSelector').change(function(){
    $('#bulkSelector option:selected').each(function(){
      $('#modelInp').val($('#autoSelector option:selected').text() + ' ' + $(this).text());
      //$('#modelInp').attr({disabled:'disabled'})
    })
  }) 
             
})



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");
	}}		
					}


