function $(id){
	return document.getElementById(id);
}

function open_new_window_images( images_src, width, height, title){
	var wtop = (screen.height-height)/2;
	var wleft = (screen.width-width)/2;
	if(!title || title === ''){
		title = "Изображение в полный размер";
	}
	image_window = window.open(images_src, 'image', 'top='+ wtop +', left='+ wleft +', height='+height+', width='+width+',resizable=no,personalbar=no,menubar=no,titlebar=no,status=no');
	image_window.document.write("<html><head><title>" + title + "</title></head>");
	image_window.document.write("<body style='margin:0; padding: 0;'><img src='" + images_src + "'></body></html>");
	image_window.document.close();
	return false;
}

var CreateMenu = function( parentElementId ){
	try {
		var w = document.body.clientWidth;
	} catch (e) {
		if ( document.addEventListener ) {
			document.addEventListener( "DOMContentLoaded", function(){
				document.removeEventListener( "DOMContentLoaded", arguments.callee, false );
				CreateMenu(parentElementId);
			}, false );
		} else if ( document.attachEvent ) {
			document.attachEvent("onreadystatechange", function(){
				if ( document.readyState === "complete" ) {
					document.detachEvent( "onreadystatechange", arguments.callee );
					CreateMenu(parentElementId);
				}
			});
		}
		return 0;
	}

	var blockParentMenu = $(parentElementId);

	var listLink = blockParentMenu.getElementsByTagName("a");
	var listBlock = blockParentMenu.getElementsByTagName("div");

	var childMenu = null;
	var currLink  = null;

	var handlerItem = function(){
 		if( this.activItem ) {
			this.className += " js-activItem";
			this.childMenu.style.display = "block";
			var width = this.parentNode.clientWidth - 10;
			if(this.childMenu.clientWidth < width){
				this.childMenu.style.width = width+"px";
			}
 		} else {
 			this.className = this.className.replace(/(\s|\b)js-activItem\b/, "");
			this.childMenu.style.display = "none";
 		}
 	}

	for(i=0, len=listLink.length; i < len ; i++) {
		var childMenu = listLink[i].id.match(/^parent_menu_([a-z0-9]+)$/i);
		if(!childMenu) continue;
		var currLink = listLink[i];
 		var childMenuEl = $("menu_"+childMenu[1]);

 		currLink.showItem = true;
 		currLink.childMenu = childMenuEl;
		currLink.parentNode.style.width = currLink.parentNode.clientWidth+"px";

 		childMenuEl.showMenu = false;
 		childMenuEl.parentItem = currLink;

		currLink.onmouseover = function(){
			this.activItem = true;
			handlerItem.call(this);
		};
		currLink.onmouseout = function(){
			this.activItem = false;
			handlerItem.call(this);
		};

		childMenuEl.onmouseover = function(){
			currLink.activItem = true;
			handlerItem.call(currLink);
		};
		childMenuEl.onmouseout = function(){
			currLink.activItem = false;
			handlerItem.call(currLink);
		};

 		childMenu
	}
};

CreateMenu("menuTop");