﻿var ie6 = (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))? true : false
function initAll()
{			
	initPNG()
	initInfPlosh()
	initPlosh()	
	setInterval(reSizeAllPlosh,500)		
	initImSee()
}
function initInfPlosh()
{
	var ob,obj,ii,t,cStyle,str
	window.infP = document.createElement('div')
	window.infP.className = 'plosh2 infPlosh'	
	document.body.appendChild(window.infP)
	var ob = window.infP	
	ob.isShow = false
	ob.onmouseover = function()
	{
		this.show()
	}
	ob.onmouseout = function()
	{
		this.hide()
	}	
	ob.show = function(res)
	{
		if (!this.isShow)
		{
			var ii,t,i
			if (res)
			{
				this.style.width = res.width + 'px'
				ii = getRect(res)					
				
				t = document.body.offsetWidth - res.width
				if (t> ii.left + res.xx) this.style.left = (ii.left + res.xx) + 'px'
				else this.style.left = t + 'px'
				
				this.ob10.className = 'txt' + res.cl				
				copyChild(res.inf,this.ob10)
				
				initImSee(this.ob10)
				
				this.style.display = 'block'		
				this.reSize()
				
				i = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop 				
				if (ie6)  ii.top -= 2		
				
				i = ii.top - i + res.yy + this.offsetHeight - document.documentElement.clientHeight
				
				i = ( i > 0) ? i : 0
				
				this.style.top = (ii.top + res.yy - i) + 'px'			
			}			
			this.style.display = 'block'			
			this.isShow = true			
		}
	}
	ob.hide = function()
	{
		if (this.isShow)
		{
			this.style.display = 'none'
			this.isShow = false
		}
	}
	
	mas =  document.getElementsByTagName('div')
	for (var i=0; i < mas.length; i++)
	{
		if (/^inf/.test(mas[i].className) )
		{
			str = mas[i].className.replace('inf','')
			ii = mas[i]
			obj = ii.parentNode
			t = obj.tagName
			if (/td/i.test(obj.tagName)) obj = ii.parentNode.parentNode
			obj.inf = ii
			cStyle = ii.currentStyle || window.getComputedStyle(ii, null)
			obj.yy = parseInt(cStyle.marginTop)
			obj.xx = parseInt(cStyle.marginLeft)
			obj.width = parseInt(cStyle.width)
			obj.cl = str
			
			obj.onmouseover = function()
			{
				window.infP.show(this)
			}
			obj.onmouseout = function()
			{
				window.infP.hide(this)
			}			
		}
	}
}

function insertImCar(mas)
{	
	var boss = document.getElementById('desk')
	
	var i,ob,obI,mE,obA
	for (i = 0; i < mas.length; i++)
	{
		mE = mas[i]
		ob = document.createElement('div')
		ob.className = "imCar"
		
		obA = document.createElement('a')
		obA.aHref = mE.href
		obA.onclick = function() {new_window(this.aHref,600,600); return false;}
		
		if (/\.swf$/.test(mE.src))
		{
			obA.innerHTML = writeFlash(mE.src,174,130,true)
			ob.appendChild(obA)
		}
		else
		{
			obI = document.createElement('div')
			obI.className = "dataIm"			
			obA.innerHTML = mE.info.replace(/==/g,'<br//>')
			obI.appendChild(obA)
			
			obI.boss = ob
			
			obI.onmouseover = function()
			{
				if (!this.isShow)
					{
						this.isShow = true
						var i = getRect(this.boss.im)
						var  ii = (ie6)?2:0
						
						this.style.top = (i.top - ii ) + 'px'
						this.style.left = (i.left + 1 - ii) + 'px'
						this.style.display = 'block'
					}		
			}
			obI.onmouseout = function()
			{
				if (this.isShow)
				{
					this.style.display = 'none'
					this.isShow = false
				}				
			}	
			
			ob.appendChild(obI)
			ob.inf = obI
			
			obI = document.createElement('img')
			obI.src = mE.src
			ob.im = obI
			ob.appendChild(obI)				
			
			ob.onmouseover = function()
			{
				this.inf.onmouseover()
			}
			ob.onmouseout = function()
			{
				this.inf.onmouseout()
			}
		}		
		ob.style.display = 'none'
		boss.appendChild(ob)		
	}	
	boss.fillIm = function()
	{			
		var  boss = document.getElementById('desk'),
			obL = getFElementbyClassName('l',boss),
			main = document.getElementById('main'),
			i = main.offsetWidth, ii = 0, iii = 174 + 4,
			//kol = Math.floor( ( i -100)/ iii ) * 2,
			kol = 10,
			mas = boss.getElementsByTagName('div')
		
		i = (main.offsetWidth - 100 - kol/2*iii - 10)/2		
		obL.style.marginRight =  i + 'px'
		
		for (i = 0; i < mas.length; i ++)
		{
			if (/imCar/.test(mas[i].className) )
			{				
				if (ii < kol) mas[i].style.display = 'inline'
				else mas[i].style.display = 'none'
				ii ++
			}
		}	
		if ( ii <= kol/2) boss.style.height = '135px'
		else boss.style.height = '269px'
		
	}	
	boss.fillIm()
	window.onresize = boss.fillIm	
}
function initPlosh()
{
	mas =  document.getElementsByTagName('div')
	var str = '',ii,ob,iii,obj,fil,st
	
	for (var i=0; i < mas.length; i++)
	{
		if (/plosh/.test(mas[i].className) )
		{ 				
			fil = mas[i]	
		//- cont -------------------
			ob = document.createElement('div')
			ob.className = 'txt'	
			obj = {}
			while (mas[i].childNodes.length > 0)
			{
				ii = mas[i].removeChild( mas[i].childNodes[0] )				
				if ( /name|blokIco/.test(ii.className)  ) 
				{
					iii = document.createElement('div')
					if ( /blokIco/.test(ii.className)  ) st = 'blokIco'
					else st = 'nameIm'
					obj[st] = iii
					ii.className = ''
					iii.className = st
					iii.appendChild(ii)						
				}
				else ob.appendChild(ii)				
			}		
			for (ii in obj)
			{
				fil[ii] = obj[ii]
				fil.appendChild(obj[ii])
			}			
			fil.ob10 = ob
			fil.appendChild(fil.ob10)	
			
		//-str -------------------		
			fil.str = document.createElement('div')
			fil.str.className = 'str'
			fil.appendChild(fil.str)	
			
		//- top ------------------			
			fil.ob1 = document.createElement('div')
			fil.ob1.className = 'f tZ imLT l t'
			fil.appendChild(fil.ob1)	
	
			fil.ob2 = document.createElement('div')
			fil.ob2.className = 'f tZ imHT t'			
			fil.appendChild(fil.ob2)		
			
			fil.ob3 = document.createElement('div')
			fil.ob3.className = 'f tZ imRT r t'
			fil.appendChild(fil.ob3)		
		//- mid ------------------			
			fil.ob4 = document.createElement('div')
			fil.ob4.className = 'f tZ imLV l'
			fil.appendChild(fil.ob4)	
			
			fil.ob5 = document.createElement('div')
			fil.ob5.className = 'f tZ imFon'			
			fil.appendChild(fil.ob5)
			
			fil.ob6 = document.createElement('div')
			fil.ob6.className = 'f tZ imRV r'
			fil.appendChild(fil.ob6)
		//- bot ------------------
			fil.ob7 = document.createElement('div')
			fil.ob7.className = 'f tZ imLB l b'
			fil.appendChild(fil.ob7)

			fil.ob8 = document.createElement('div')
			fil.ob8.className = 'f tZ imHB b'
			fil.appendChild(fil.ob8)
			
			fil.ob9 = document.createElement('div')
			fil.ob9.className = 'f tZ imRB r b'
			fil.appendChild(fil.ob9)
			
			if (/bt/.test(mas[i].className) )
			{				
				fil.bt = document.createElement('div')
				fil.bt.className = 'bt'
				fil.appendChild(fil.bt)
				
				
				fil.bt.onmouseover = function(){this.boss.isOver = true}
				fil.bt.onmouseout = function(){this.boss.isOver = false} 
				fil.bt.boss = fil
				fil.nameIm.onmouseover = function(){this.boss.isOver = true}
				fil.nameIm.onmouseout = function(){this.boss.isOver = false} 
				fil.nameIm.boss = fil
				fil.nameIm.style.cursor = 'pointer'
				
				fil.closePl = function()
				{
					if (this.isOver)
					{
						this.bt.style.backgroundPosition = '-24px 0'
						this.isOpen = false
						this.ob10.style.display = 'none'
						this.style.cursor = 'pointer'				
					}
				}
				fil.openPl = function()
				{					
					this.isOpen = true
					this.ob10.style.display = 'block'
					this.style.cursor = 'auto'	
					this.bt.style.backgroundPosition = '0px 0px'
				}
				
				fil.onclick = function()
				{
					if (this.isOpen) this.closePl()
					else this.openPl()					
					reSizeAllPlosh()
				}
				if (/btOpen/.test(mas[i].className) ) fil.openPl()
				else 
				{ 
					fil.isOver = true
					fil.closePl()
				}
			}
			
			fil.reSize = function()
			{	
				var i
				var cStyle = this.currentStyle || window.getComputedStyle(this, null)
				if (cStyle.position == 'absolute')
				{	
					i = {}
					i.top = 0
					i.left = 0
				}
				else 
				{
					i = getRect(this)	
					if (ie6)  i.top -= 2
				}
				
				for (var ii = 0; ii < this.childNodes.length; ii ++)
				{
					cStyle = this.childNodes[ii].currentStyle || window.getComputedStyle(this.childNodes[ii], null)
					if (cStyle.position == 'absolute')
					{
						this.childNodes[ii].style.top =  i.top + 'px'
						this.childNodes[ii].style.left =  i.left + 'px'						
					}						
				}				
				if (this.blokIco) this.blokIco.style.left = (i.left + this.offsetWidth - 40) + 'px'		
				if (this.bt) this.bt.style.left = (i.left + this.offsetWidth - 80) + 'px'				
				
				this.ob10.style.width = this.offsetWidth + 'px'				
				
				var h =( this.ob10.offsetHeight -  ( this.ob1.offsetHeight +  this.ob7.offsetHeight) )
				h = ( (h<0)?0:h) + 'px'		
				
				this.ob2.style.width = (this.offsetWidth - (this.ob1.offsetWidth + this.ob3.offsetWidth )) + 'px'
				this.ob5.style.width = (this.offsetWidth - (this.ob4.offsetWidth + this.ob6.offsetWidth )) + 'px'
				this.ob8.style.width = (this.offsetWidth - (this.ob7.offsetWidth + this.ob9.offsetWidth )) + 'px'
				
				this.ob4.style.height = h
				this.ob5.style.height = h
				this.ob6.style.height = h	
			}		

			fil.reSize()			
		}		
	}
}
function copyChild(res,place)
{
	var i,ob,obj
	place.innerHTML = ''
	for (i = 0; i < res.childNodes.length; i ++)
	{
		obj = res.childNodes[i]
		ob = obj.cloneNode(true)
		if ( ( obj.tagName == 'input') && (obj.type == 'text') )
		{
			ob.boss = obj
			ob.onchange = function()
			{
				this.boss.value = this.value
			}
		}
		place.appendChild(ob)
	}
}
function writeImSee()
{
	var str = '<div class = "imList">'	
	for (var i = 0; i < arguments.length; i ++)
		str += '<a href = ' + arguments[i] + '> </a>'	
	str += '</div>'
	document.write(str)
}
function initImSee(blok)
{
	var mas,i,ob,mD,ii,obj,t
	if (blok)  mas = blok.getElementsByTagName('div')
	else mas = document.getElementsByTagName('div')
	
	for (i = 0; i < mas.length; i ++)
	{
		mD = []
		if (/imList/.test(mas[i].className) )
		{
			ob = mas[i].getElementsByTagName('a')
			for (ii = 0; ii < ob.length; ii ++) mD.push(ob[ii].href)
			
			ob = mas[i]
			ob.innerHTML = ''
			
			for (ii = 0; ii < mD.length; ii ++) 
			{
				obj = document.createElement('a')
				obj.href = mD[ii]			
				obj.style.display = 'none'
				ob.appendChild(obj)	
			}
			t = document.createElement('p')
			ob.im = document.createElement('img')
			t.appendChild(ob.im)
			ob.appendChild(t)
			ob.im.src = mD[0]
			t = document.createElement('p')
			ob.appendChild(t)
			
			for ( ii = 0; ii < mD.length; ii ++)
			{
				obj = document.createElement('div')
				obj.className = "anh"
				obj.href = mD[ii]
				obj.innerHTML = ii + 1				
				obj.boss = ob				
				obj.onclick = function()
				{
					this.boss.im.src = this.href
					this.style.color = '#aaaaaa'
				}
				t.appendChild(obj)				
			}
			
		}
	}	
}

function getFElementbyClassName(cName,boss)
{
	var i = 0,rE,m
	m = boss.getElementsByTagName('div')		
	rE = new RegExp("\\b"+cName+'\\b')
	while (  (i < m.length)  &&  ( ! rE.test(m[i].className)  ) ) i ++
	if (i >= m.length) return 0	
	return m[i]
}
function reSizeAllPlosh()
{	
	var mas =  document.getElementsByTagName('*');		
	for (var i=0; i < mas.length; i++) if (/plosh/.test(mas[i].className) && (mas[i].style.display != 'none') ) mas[i].reSize();	
}
function getRect(obj)
{
	obj = obj || this;
	var i = new Object();	
	
	if (obj.getBoundingClientRect)
	{
		var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
		var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft ||document.body.scrollLeft;		
		
		var ii = obj.getBoundingClientRect();
		
		i.left = ii.left + scrollLeft;
		i.right = ii.right + scrollLeft;
		i.top = ii.top + scrollTop;
		i.bottom = ii.bottom + scrollTop;
	}
	else
	{
		i.top=0;
		i.left=0
		var elem = this;
		while(elem) 
		{
			i.top += elem.offsetTop;
			i.left += elem.offsetLeft;			
			elem = elem.offsetParent;
		}		
		i.right = i.left + this.offsetWidth;
		i.bottom = i.top + this.offsetHeight;
	}	
	return i;
}
function initPNG()
{
	if (ie6)
	{		
		var allImg = document.getElementsByTagName('Img')
		for (var i = 0; i < allImg.length; i++)
		{			
			if (/\.png$/.test(allImg[i].src))
			{				
				allImg[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + allImg[i].src + "', sizingMethod='crop')"
				allImg[i].style.height = allImg[i].height + 'px'				
				allImg[i].style.width = allImg[i].width + 'px'		
				allImg[i].src = 'images/null.gif'	
			}			
		}
	}
}
function addLoadEvent(func)
{		
	if (typeof window.onload != 'function') window.onload = func
	else 
	{
		var oldonload = window.onload;
		window.onload = function(){
		oldonload();
		func();
		}
	}
}
function writeFlash(src,width,height,f)
{	
	var flashParam = new Array(
		['quality', 'high'],
		['scale', 'noscale'],
		['wmode', 'opaque'],
		['allowFullScreen', 'false'],
		['salign', 'lt'],
		['play','true']
	)
	var str = '<embed type = "application/x-shockwave-flash" pluginspage = "https://www.macromedia.com/go/getflashplayer" '	
	for (var i = 0; i < flashParam.length; i++ ) str += flashParam[i][0] + '="' + flashParam[i][1]+ '" ' 
	str += 'width = "'+width +'" '	
	str += 'height = "'+height +'" '	
	str += 'src ="' + src + '" ' 	
	str += '> </embed>'
	if (f) return str
	document.write(str)
}

var active;
var timer;
function displayMark( objId, action )
{
	var obj = document.getElementById( objId );
	
	if( action=='table' )
	{
		if( timer )
		{
			active.style.display = 'none';
			clearTimeout( timer );
		}
		if( active && active!=obj )active.style.display = 'none';
		
		newTop = obj.parentNode.offsetTop - obj.parentNode.parentNode.scrollTop;
		obj.style.top = newTop + 'px';
//		obj.style.left = obj.parentNode.offsetLeft;		

		obj.style.display = action;
	}
		else
	{
//		obj.style.display = action;
		timer = setTimeout( "hiddeMark()", 1000 );
	}	
	
	active = obj;
	return false;
}

function hiddeMark()
{
	active.style.display = 'none';
}

