function close_cp(event){
	if(navigator.appName=="Netscape") t2=event.target
	else t2=window.event.srcElement
	var stop=0;
	
	while(!stop){
		if(!t2.parentNode.tagName) break;
		if(t2.parentNode.tagName=='BODY'){
				stop=1;
				for(i=0;i<6;i++){
					$('#topsubmenu'+topmenuids[i]).hide();
				}
				$('#priceList').hide();
				$('#catList').hide();
				break;
		}
		if(t2.getAttribute('id')){
			if(t2.getAttribute('id').match('topsubmenu'))
				break;
			if(t2.getAttribute('id').match('priceList'))
				break;
			if(t2.getAttribute('id').match('catList'))
				break;
		} 
		t2=t2.parentNode
	}
}
///document.onclick=close_cp


function getLikeElements(tagName, attrName, attrValue){
	var start, end = [], re = new RegExp("(^|\\s)"+attrValue+"(\\s|$)");
	if(tagName) 
		start = document.getElementsByTagName(tagName);
	else{
		start = (document.all && !window.opera) ? document.all :
		document.getElementsByTagName("*");
	}
	if(attrName) {
		for(var i = 0, l = start.length; i < l; i++) {
			if (attrName == "class" && start[i].className) {
				if(attrValue) {
					if (re.test(start[i].className) || start[i].getAttribute(attrName) == attrValue) {
						end.push(start[i]);
					}
				}
				else end.push(start[i]);
			}
		}
	}
	else end = start;
	return end;
}


function getElementPosition(elemId){
	var elem = document.getElementById(elemId);
	
	var w = elem.offsetWidth;
	var h = elem.offsetHeight;
	
	var l = 0;
	var t = 0;
	
	while (elem){
		l += elem.offsetLeft;
		t += elem.offsetTop;
		elem = elem.offsetParent;
	}
	
	return {"left":l, "top":t, "width": w, "height":h};
}

function fixPNG(element){
	if(/MSIE (7|8).+Win/.test(navigator.userAgent))
		return false;

	//Если браузер IE версии 5.5-6
	else if(/MSIE (5\.5|6).+Win/.test(navigator.userAgent)){
		var src;
	
		//Если текущий элемент картинка (тэг IMG)
		if(element.tagName=='IMG'){
			//Если файл картинки имеет расширение PNG
			if(/\.png$/.test(element.src)){
				src = element.src;
				element.src = "/i/dot.gif"; //заменяем изображение прозрачным gif-ом
			}
		//иначе, если это не картинка а другой элемент
		}else{
			//если у элемента задана фоновая картинка, то присваеваем значение свойства background-шmage переменной src
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
			if(src){
				src = src[1]; //берем из значения свойства background-шmage только адрес картинки
				element.runtimeStyle.backgroundImage='none'; //убираем фоновое изображение
			}
		}
		//если, src не пуст, то нужно загрузить изображение с помощью фильтра AlphaImageLoader
		if(src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
	}
}


function chBg(obj,flag){
	var classname=obj.className;
	if(flag==1){
		obj.className=classname+' active1';
	}else{
		classname=classname.replace('active1','');
		obj.className=classname;
	}
}

function showBl(id,flag){
	var obj=document.getElementById(id);
	if(flag==1){
		//obj.style.display='block';
		obj.style.height='187px';
		if(id=='b3')
			document.getElementById('b3d').style.top='-10px';
	}else{
		//obj.style.display='none';
		obj.style.height='53px';
		if(id=='b3')
			document.getElementById('b3d').style.top='0px';
	}
}

//меню
function menu(subMenuIndex){
	this.subMenuIndex=subMenuIndex;
	this.curShow=new Array();
	
	this.test=function(){
		alert(this.subMenuIndex);
	}
	this.showSM=function(id,subMenuIndex){
		this.subMenuIndex=subMenuIndex;

		var obj=document.getElementById('sm'+id);
		if(!obj) return;
		
		var collection = getLikeElements('div','class','submenu'+(this.subMenuIndex?this.subMenuIndex:''));
		for(var i = 0; i < collection.length; i++) {
			collection[i].style.display = 'none';
		}
		
		this.resetItemsActive();
		
		if(!this.curShow[id]){
			this.setItemActive(id);
			
			obj.style.display='block';
			this.curShow=new Array();
			this.curShow[id]=true;
		}else{
			obj.style.display='none';
			this.curShow=new Array();
		}
	}
	
	this.showSubMenu=function(idIndex){
		this.curShow[idIndex]=true;
		
		var obj=document.getElementById('sm'+idIndex);
		if(!obj) return;
		else obj.style.display='block';
	}
	
	this.setItemActive=function(idIndex){
		var obj=document.getElementById('i'+idIndex);
		if(!obj) return;
		
		obj.className=obj.className+' active2';
		this.setParentItemActive(idIndex);
		this.showSubMenu(idIndex);
	}
	
	this.setParentItemActive=function(idIndex){
		var obj=document.getElementById('i'+idIndex);
		if(!obj) return;
		
		var pid=obj.parentNode.id;
		pid=pid.replace(/[a-zA-Z]+/i,'');
		
		if(!pid) return;
		
		this.showSubMenu(pid);
		this.setItemActive(pid);
	}
	
	this.resetItemsActive=function(){
		var collection = getLikeElements('div','class','item');
		for(var i = 0; i < collection.length; i++){
			classname=collection[i].className;
			
			classname=classname.replace('active2','');
			collection[i].className=classname;
		}
	}
	
	return this;
}
