$(function(){
	$('#body').click( hideMenu );
	leftMenuHeight = $('#left-menu').css('height');
	$("#left-menu-toggler").toggle(
		function () {
			$('#left-menu').animate( { height:"10px" }, { queue:true, duration:500 } );
		},
		function () {
			$('#left-menu').animate( { height:leftMenuHeight }, { queue:false, duration:500 } );
		}
	);
});

var showObj, showMenuObj;
var flag=false;
function showMenu(obj, menu){
	showMenuObj = document.getElementById(menu);
	showObj = obj;
	if (showMenuObj.style.display == 'block'){
		showMenuObj.style.display = 'none';
		showObj.className = showObj.className.replace(' select', '');
		showObj = null;
		showMenuObj = null;
		flag = setFlag(false);
	}else{
		showObj.className += ' select';
		showMenuObj.style.display = 'block';
		window.setTimeout('setFlag(true)', 500);
	}
	return false;
}
function setFlag(value){
	flag = value;
}
function menuOver(obj, menu){
	if(showObj){
		showMenuObj.style.display = 'none';
		showObj.className = showObj.className.replace(' select', '');
		showObj = null;
		showMenuObj = null;
		showMenuObj = document.getElementById(menu);
		showObj = obj;
		showMenuObj.style.display = 'block';
		showObj.className += ' select';
	}
}
function hideMenu(){
	if(flag){
		showMenuObj.style.display = 'none';
		showObj.className = showObj.className.replace(' select', '');
		showObj = null;
		showMenuObj = null;
		flag = setFlag(false);
	}
}
function changeFoto(obj){
	document.getElementById('img-large').src = obj.href;
	return false;
}
function wopen(url){
	window.open(url	, '_blank','resizable=yes');
	return false;
}
var currTbl, currLink;
function getTbl(id, oLink){
	if(currLink)
		currLink.className = 'none';
	if (currTbl)
		currTbl.style.display = 'none';
	currTbl = document.getElementById(id);
	currTbl.style.display = 'block';
	currLink = oLink;
	currLink.className = 'active';
}
function change_span2()
	{
	var stFlag = document.getElementById('mbprice').value;
	var span = document.getElementsByTagName('span');
		for (i = 0; i < span.length; i ++)
		if(span[i].className == 'RUB' || span[i].className== 'EUR') {
			span[i].style.display = 'none';}
		for (i = 0; i < span.length; i ++) {
		if(span[i].className == stFlag)
			{
				//USD показать
				//RUB скрыть
				span[i].style.display = 'block';
			}
		}
	}
function flyout(url,obj) {
	var img = new Image;
	img.src = url;
	img.className="flyout";
	obj.appendChild(img);
}
function flyclear(obj) {
	for (var i=0; i<obj.childNodes.length; i++) {
		if (obj.childNodes[i].className == "flyout") {
			obj.childNodes[i].className = "hide";
		}
	}
}
function ChangeFoto(oID, nImg)
{
	var img = document.getElementById(oID);
	img.src = nImg;
}
function change2(rub, usd, id)
{
	if(document.getElementById('usedprice'+id).value == 'usd')
	{
		document.getElementById('divusedprice'+id).innerHTML = usd;
		setCookie('currency','USD');
	}
	else
	{
		document.getElementById('divusedprice'+id).innerHTML = rub;
		setCookie('currency','RUB');
	}
}
function change()
	{
	var stFlag = document.getElementById('usedprice').value;
	var span = document.getElementsByTagName('span');
		for (i = 0; i < span.length; i ++)
		if(span[i].className == 'RUB' || span[i].className== 'USD' || span[i].className== 'ORIG')
			span[i].style.display = 'none';
		for (i = 0; i < span.length; i ++) {
		if(span[i].className == stFlag)
			{
				//USD показать
				//RUB скрыть
				span[i].style.display = 'block';
			}
		}
		setCookie('currency',stFlag);
	}
function setCookie (name, value){
      document.cookie = name + '=' + escape(value) + '; path=/; expires=Fri, 01-Jan-2025 00:00:01 GMT;';
}
function setSort(str) {
    document.searchform.sort.value = str;
//    document.getElementById ('page_sort').value = '1';
    document.searchform.submit();
}
function wopen (obj){
 var wo = window.open("", "abc", "width=10, height=10, scrollbars=0, status=0");
 wo.document.open();
 var win = "";
 win = "<html><head>";
 win += "<title>Image</title>";
 win += "<script>function resizes (obj){";
 win += "var w=obj.width, h=obj.height;";
 win += "window.resizeTo (w+10, h+46);";
 win += "}</"+"script"+">";
 win += "<style type='text/css'> * {margin:0; padding:0; border:0; } </style> </head>"
 win += "<body>";
 win += "<table cellpadding='0' cellspacing='0' width='100%' height='100%'><tr><td align='center'>";
 //win += "<img src='" + obj + "' alt='' onload='resizes(this)' />";
 win += "</td></tr></table>";
 win += "</body></html>";
 wo.document.write(win);
 wo.window.focus();
 wo.document.close();
}
function changeText(obj)
{
var n = obj.id.substring(1);
var divs = document.getElementsByTagName("div");
for (i = 0; i < divs.length; i++)
{
var el = divs[i];
if (el.id.substring(0, 4) == 'text')
{ if (el.id.substring(4) == n) el.style.display = "block"; else el.style.display = "none"; }
}
}
function changeFoto(obj){
	document.getElementById('img-large').src = obj.href;
	return false;
}

//<script language="javascript" type="text/javascript"> ml("address","mail","ru"); </script>
function ml (mailprefix, maildomain, mailsuffix, mailname)
{
    if (mailname == null) { mailname = mailprefix + '@' + maildomain + '.' + mailsuffix; }

    document.write('<a href="mailto:' + mailprefix + '@' + maildomain + '.' + mailsuffix + '">' + mailname + '</a>');
}

function collage_height(){
    var backImg=document.getElementById('collage').style.backgroundImage;
    backImg=backImg.replace('url("','');
    backImg=backImg.replace('")','');
    backImg=backImg.replace('url(','');
    backImg=backImg.replace(')','');
    backImgPath='http://bmw-balttrade.ru'+backImg;
    var existImg = new Image();
    existImg.src = backImgPath;
    imgHeight = existImg.height;
    if(imgHeight>0){
        document.getElementById('collage').style.height=imgHeight+'px';
        document.getElementById('left-menu').style.marginTop='-'+imgHeight+'px';
    }
}

$(document).ready(function(){
	$('[id^="a-"]').click(function(){
		id= $(this).attr("id").substr(2);
		//itop = $("#"+id).css("top");
		//left = $("#"+id).css("left");
		$("#"+id).show();
		//$("#"+id).css("top", top);
		//$("#"+id).css("left", left);
		//alert("#"+id);
	});
	
	$('[id^="a-close-"]').click(function(){
		id= $(this).attr("id").substr(8);
		$("#"+id).hide();
	});
});
