var modelMenuItemCount = 13;

Recreational = new Array("hyundai_Ix55", "hyundai_santa_fe(FL)", "hyundai_Ix35", "hyundai_H1");
RemoveRels = new Array("used_cars", "rec_test-drive", "hyundai_family");

$(document).ready(function(){

	//проверяем широкие таблицы
	$('#Content table').each(function(index, element){
		if ($(element).outerWidth(true) > 672) {
			$(element).wrap("<div class='scrollable'></div>");
		}
	});
	
	//удаляем подменю "автомобили"
	$('div.head__menu ul li.cars ul').remove();

	//обходим скрытое меню автомобилей и делим на recreational и passanger
	$('#allmodelstype li').each(function(indx, element){
		var rel = $(element).attr('rel');
		if ( jQuery.inArray(rel, RemoveRels) > -1) {
			$(element).remove();
		}else if ( jQuery.inArray(rel, Recreational) > -1) {
			$("#recreational ul.clearfix").append($(element));
		}else{
			$("#passanger ul.clearfix").append($(element));
		}
		$(element).removeAttr("rel");
	});
	//удаляем временный контейнер
	$('#allmodelstype').remove();

	//и вместо подменю "автомобили" устанавливаем содержимое меню autoonly
	var autoonly = $('#autoonly').html();
	

	$('div.head__menu ul li.cars').append(autoonly);
	//удаляем лишние пункты из меню "Автомобили"
	//$('div.head__menu ul li.cars div.autos div.autos__item ul.clearfix li:gt('+(modelMenuItemCount-1)+')').remove(); */


	$('#model-menu').show();
	$('div.head__menu ul li.cars ul').show();

	//подключаем ссылки "color"
	$('#Content .colors ul li a').click( function() {
		hrefLink = $(this).children('img').attr('src');
		hrefFile = hrefLink.substring(hrefLink.lastIndexOf('/')+1);
		newsrc = 'http://www.koreamotor.ru/' + 'data/colors/' + hrefFile;
		$(this).parent().parent().parent().find('div.colors__img img').attr('src', newsrc);
		$('#Content .colors ul li').removeClass('active');
		$(this).parent().addClass("active");
		return false;
	});

	//подставляем значения поиска
	try {
		$('#Content #searchString').val(searchString);
		$('#Content #searchType').val(searchType);
	}
	catch (e) {
	}

	//миниатюры в каталоге
	$('#Content .tradein .tradein__img .tradein__img__list a').click( function() { 
		h = $(this).attr('href');
		$('#Content .tradein .tradein__img .tradein__img__big img').attr('src', h);
		return false;
	});


});

function changeHref(obj, sFirstPart, sSecondPart){
	obj.href = 'mailto:' + sFirstPart + '@' + sSecondPart;
}

//	$('div.head__menu ul li:gt('+modelMenuItemCount+')').remove();
