function setCount(count, nameClass){
 var str = new String();
	var i = new Number();
	i = 0;
	str = "div."+nameClass;
	$(str).each(
		function(){
			i++;
			if(i>count){	
				this.style.display = "none";
			}
			else{
    this.style.display = "inline";
			}
		}
	);
}

var mCur = new Object();
var ttpsID = 0;

document.onmousemove = function(e){
 mCur = mouseXY(e);
	m_x = mCur.x;
 m_y = mCur.y;
 if(document.getElementById("ttps"+ttpsID)){
		document.getElementById("ttps"+ttpsID).style.left = (m_x - 135)+"px";
		document.getElementById("ttps"+ttpsID).style.top = (m_y + 15)+"px";
	}	
}

function mouseXY(e){
 var x = 0, y = 0;
 if (!e) e = window.event;
 if (e.pageX || e.pageY){
  x = e.pageX;
  y = e.pageY;
 }
 else if (e.clientX || e.clientY){
  x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
  y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
 }
 return {"x":x, "y":y};
}

function resizeWindow(){
	// чертова кроссбраузерность!!!
	if($.browser.mozilla || $.browser.opera ){
	 width = this.outerWidth; // ширина окна
	}
	else{
  width = document.documentElement.clientWidth;		
	}
	if(width < 1120){
		setCount(2, "imagebox");
		setCount(2, "videobox");
	}
	else if(width < 1245){
		setCount(4, "imagebox");
		setCount(3, "videobox");
	}
	else{
		setCount(6, "imagebox");
		setCount(4, "videobox");
	}		
}

function pageLoad(){
	// делаем resize только для современных быстрых браузеров
	if($.browser.mozilla || $.browser.opera){
		// подключаем нужные слушалки
		window.onresize = resizeWindow;
		resizeWindow();
	}
	else{
 	// подключаем нужные слушалки к IE
		window.onresize = resizeWindow;
		resizeWindow();		
	}
	if(typeof initialize == 'function'){
	 initialize();
	}
	else{
	 //alert('Не загружен!');	
	}
}

function mOverBut(id){	
 for(i = 0; i < id.childNodes.length; i++){
		if(id.childNodes[i].className == "a"){
		 id.childNodes[i].className = "b";	
		}
	}
}

function mOutBut(id){	
 for(i = 0; i < id.childNodes.length; i++){
		if(id.childNodes[i].className == "b"){
		 id.childNodes[i].className = "a";	
		}
	}
}

function showTech(id){
 if(id == 'first'){
		document.getElementById("twow").style.display = 'none';
		document.getElementById("first").style.display = 'block';
	}
	else if(id == 'twow'){
		document.getElementById("first").style.display = 'none';
		document.getElementById("twow").style.display = 'block';
	}
	else{}
}

function mOverTech(id){
	document.getElementById("baseImg").src = id.src;
}

function mClick(model, id){	
	switch(id){
	 case 'naves':
		 document.location.href = "/catalog/navesnoe/?model=" + model + "#start_model";
		 break;
		case 'photo':
 	 document.location.href = "/gallery/?q=" + model;
		 break;
		case 'video':
		 document.location.href = "/video/?q=" + model;
		 break;
		default:
		 break;
	}
}

function mVote(model){
 prev = "/order/?model=";
 document.location.href = prev + model;		
}

function mOrder(model){
	prev = "/order/?model=";
 document.location.href = prev + model;	
}

function mLoadResult(){
 document.getElementById('cel_model_2').value = document.adminForm.sel_model.options[document.adminForm.sel_model.selectedIndex].text;
}

function onlyTelefon(e){
 var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);
 if (e.ctrlKey || e.altKey || key < 32)return true;
	key = String.fromCharCode(key);
 //return /[\d-+\.]/.test(key);
	return /[\d\-+. \(\)]/.test(key);
}

function setListCity(){
 //alert("Выбрано значение "+document.getElementById('city').options[document.getElementById('city').selectedIndex].value);
	document.location.href = "/dilers/?city="+document.getElementById('city').options[document.getElementById('city').selectedIndex].value;
}

function setListService(){
	document.location.href = "/remont/?q="+document.getElementById('model').options[document.getElementById('model').selectedIndex].value;
}

function showTTPS(id){
	//alert("x = "+m_x+" | y = "+m_y);
	ttpsID = id;
 document.getElementById("ttps"+id).style.display = "block";
}

function hideTTPS(id){
	ttpsID = id;
 document.getElementById("ttps"+id).style.display = "none";
}

/*
function mOverBut(id){
	var i = new Number(0);
 $("div.bigbut").each(
  function(){
			i++;
		 if(i == id){
			 for(j = 0; j < $("div.bigbut").children.length; j++){
					alert("class A"+$("div.bigbut").children.length);	
				}
			}
		}
	);
}
*/

function closeNG2010(){
 document.getElementById('ng2010').style.display = 'none';
}