var menuBlockName = "menu";

function getObj(objID)
{
	return document.getElementById(objID)? document.getElementById(objID): false;
}

function init()
{
	var menuObj = getObj(menuBlockName);
	if(!menuObj)
		return;

	var menuImg = menuObj.getElementsByTagName("IMG");
	for(var i = 0; i < menuImg.length; i++)
	{
		menuImg[i].onmouseover = menuOver;
		menuImg[i].onmouseout  = menuOut;
	}
}

function menuOver()
{
	var img = this.src.split(/\//);
	this.src = "images/menu" + getMenuNum(img[img.length - 1]) + "_1.gif";
}

function menuOut()
{
	var img = this.src.split(/\//);
	this.src = "images/menu" + getMenuNum(img[img.length - 1]) + ".gif";
}

function openDetail(imgHref, model, wid, hei)
{
	// стартуем в центре
	var start_left = (screen.width  - wid) / 2;
	var start_top  = (screen.height - hei) / 2;

	wWid = parseInt(wid) - 4;
	wHei = model.length? parseInt(hei) + 30: parseInt(hei) - 4;

	var win = window.open("", "", "width="+ wWid + ", height=" + wHei + ", top=" + start_top + ", left=" + start_left);
	win.document.write("<html><head><title>" + model + "</title></head" + ">");
	win.document.write("<link type=\"text/css\" rel=\"stylesheet\" href=\"/style.css\">");
	win.document.write("<body class=\"body_bg\">");
	win.document.write("<img src=\"" + imgHref + "\" width=\"" + wid + "\" height=\"" + hei + "\" /><br />");
	if(model.length)
		win.document.write("<center class=\"mod_detail\">" + model + "</center>");
	win.document.write("</body></html>");
	win.focus();

	return false;
}


function openModel(wHref, wid, hei)
{
	if(!wid || !hei)
	{
		var im = new Image();
		im.src = wHref;
		wid = im.width;
		hei = im.height;
	}
	window.open(wHref, "", "width="+ (wid + 20) + ", height=" + (hei + 20) + ", resizable=1").focus();
	return false;
}

function showModel(wHref)
{
	var obj = getObj("portfImg");
	obj.getElementsByTagName("A")[0].href = wHref;
	obj.getElementsByTagName("IMG")[0].src = dirname(wHref) + basename(wHref).replace(/preview_/, "");
	return false;
}

function dirname(wHref)
{
	var adress = wHref.replace(/(http:\/\/)?[^\/]+/, "").split(/\//);
	var directory = "";
	for(var i = 0; i < adress.length - 1; i++)
		directory += adress[i] + "/";
	return directory;
}

function basename(wHref)
{
	var adress = wHref.split(/\//);
	return adress[adress.length - 1];
}

function getMenuNum(srcName)
{
	return parseInt(srcName.replace(/menu/, ""));
}