$(function(){ clearFocus(); });

//-------------------------
//	Подмена изображений
//-------------------------
function swap(obj,type)
{
	$("#"+obj).attr("src","site/images/" + obj + "_" + type + ".gif");
	$("#"+obj).css("cursor","pointer");
}


//-------------------------
//	Всплывающее меню
//-------------------------
var hide;
var menu;
var cm = null;
function popupMenu(type,obj)
{
	
	var pos = $('#'+obj);
	if( cm == obj ) { hide = false; return; }
	cm = obj;
	var menuTitle = "pm_" + obj;
	
	menu = $('#' + menuTitle);
	menu.css('left',pos.offset().left);
	
	checkPopupMenu();
	hide = false;
	
	if(type == "show")
	{
		hide = false;
		$('.popup_menu').fadeOut();
		menu.show().css('opacity',0).fadeTo("fast",0.9);
	}
	else
	{
		hidePopupMenu();
	}

	pos.mouseout(hidePopupMenu);
	menu.mouseover(function() { hide = false; });
	menu.mouseout(hidePopupMenu);
	return;
}

function clearFocus()
{ 
	$("a").blur(); // Убираем пунктир у ссылок в IE 
}

function hidePopupMenu()
{
	hide = true;
	setTimeout("checkPopupMenu()", 3);
}

function checkPopupMenu()
{
	if(!hide) return;
	$('.popup_menu').fadeOut("fast",0,function(){ hide(); });
	cm = null;
}

//------------------------------
//Open image in new window
//-------------------------------

function OpenLargeImg( a, w, h )
{
            var newWindow;
            var basehref = $('base').attr('href');
            var img = $(a).attr('href');
            newWindow=window.open('','','toolbar=no,scrollbars=yes,left=10,top=10,width=' + (w + 18) +',height=' + (h + 33))
            newWindow.document.open("text/html","replace");
            newWindow.document.write('<html><body style="margin:0px; background:#e6dbb8">');
            newWindow.document.write('<center><img src="' + basehref + img + '" width="' + w + '" height="' + h + '" alt=""></center>');
			newWindow.document.write('<center><a href=# onClick="javacript: window.close();" style="color: Black;font-family: Verdana;font-size: 10pt;">Закрыть окно</a></center>');
            newWindow.document.write('</body></html>');
            newWindow.document.close();
}

function SelectModels() {
	cur_marka = $("#marka").val();
	if ($("#model")) $("#model").remove();	
	$("#model_cont").remove();
	if (cur_marka == 'Fiat') {
		var model_arr = new Array("500", "Albea", "Panda", "Panda 4x4 Climbing", "Grande Punto 3D", "Grande Punto 5D", "Bravo", "Sedici", "Croma New", "Doblo Panora", "Doblo Cargo", "Ducato");
	}
	if (cur_marka == 'Ssang yong') {
		var model_arr = new Array("Rexton II", "Kyron New", "Actyon", "Actyon Sports", "Rodius");
	}
	if (cur_marka == 'Isuzu') {
		var model_arr = new Array("N-series Шасси NLR85A", "N-series Шасси NQR75", "C-series Шасси CYZ51Q", "C-series Самосвал CYZ51 KLD", "E-series Тягач седельный 4х2 EXR51", "E-series Тягач седельный 6х4 EXZ51");
	}
	if (cur_marka == 'Uaz') {
		var model_arr = new Array("UAZ Patriot", "UAZ Pickup", "UAZ Hunter");
	}	
	if (model_arr) {
		var str='<select id="model" name="model">';
		var i=0;
		while (i < model_arr.length) {
				str = str + '<option value="' + model_arr[i] + '">' +  model_arr[i] + '</option>';
				i++;
			}
			str = str + '</select>';
			$("#model_label").after(str);
	}
}

