var ie6 = (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))? true : false,
	 ie7 = (/MSIE (7).+Win/.test(navigator.userAgent))? true : false,
	ie = navigator.appName.indexOf("Microsoft") != -1
var flashParam = new Array(
['quality', 'high'],
['scale', 'noscale'],
['wmode', 'transparent'],//opaque
['allowFullScreen', 'false'],
['allowScriptAccess','always'],
['salign', 'lt'],
['play','true']
)
function initAll()
{
	var bt = tool_createElem('div','btInTop')
	window.bt = bt
	document.body.appendChild(bt)
	bt.onclick = function()
	{
		showFlashLoader("data/qubrit-uploader-add.swf",650,650,'','im='+window.img)
	}
	bt.onmouseover = function()
	{		
		window.bt.style.display = 'block'
	}
	bt.onmouseout = function()
	{			
		window.bt.style.display = 'none'
	}
	
	var mas = tool_getElementsByClassName('imSm',document.body),
		i
	for (i = 0; i < mas.length; i ++)
	{
		mas[i].onmouseover = function()
		{
			var i = tool_getRect(this)
			window.bt.style.top = i.top + 'px'
			window.bt.style.left = i.left + 'px'
			window.bt.style.display = 'block'			
			window.img = this.src.replace(/.*\//g,'')
		}
		mas[i].onmouseout = function()
		{			
			window.bt.style.display = 'none'
		}
    }
}
function showFlashLoader(name,width,height,id,param,parampampam)
{
	var main = tool_getElementsByClassName('main')[0]
	
	if (!window.flLoader) 
	{
		window.flLoader = tool_createElem('div','showFl')		
		document.body.appendChild(window.flLoader)
	}
	else
	{
		window.flLoader.style.display = 'block'		
	}
	window.bt.style.display = 'none'
	main.style.height = document.documentElement.clientHeight + 'px'
	window.flLoader.style.height = document.documentElement.clientHeight + 'px'
	window.scrollTo(0,0)

	window.flLoader.innerHTML = tool_writeFlashFullStr(name, width, height, id, param + '&str=' + encode(parampampam))	
}
function closeFlashLoader()
{
	window.flLoader.style.display = 'none'
	tool_getElementsByClassName('main')[0].style.height = 'auto'
}
function tool_writeFlashFullStr(src,width,height,id,param)
{	
	var str,i	
	param = param.replace(/\+/g,'&')
	if (ie)
	{
		str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width = "'+width +'" height = "'+height +'" id = "'+ id +'"  >'		
		for (i = 0; i < flashParam.length; i++ ) str += '<param name="' + flashParam[i][0] + '" value="' + flashParam[i][1]+ '" /> '
		str += '<param name="movie" value="' + src + '" /> <param name="FLASHVARS" value="' + param + '" /> </object>'		
	}
	else
	{
		str = '<embed type = "application/x-shockwave-flash" pluginspage = "https://www.macromedia.com/go/getflashplayer" '	
		for ( i = 0; i < flashParam.length; i++ ) str += flashParam[i][0] + '="' + flashParam[i][1]+ '" ' 
		str += 'width = "'+width +'"  height = "'+height +'"  name = "'+ id +'" id = "'+ id +'" src ="' + src + '" FLASHVARS="' + param + '" > </embed>'	
	}	
	return str
}
function tool_writeFlashFull(src,width,height,id,param)
{	
	var str,i
	
	param = param.replace(/\+/g,'&')
	if (ie)
	{
		str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width = "'+width +'" height = "'+height +'" id = "'+ id +'"  >'		
		for (i = 0; i < flashParam.length; i++ ) str += '<param name="' + flashParam[i][0] + '" value="' + flashParam[i][1]+ '" /> '
		str += '<param name="movie" value="' + src + '" /> <param name="FLASHVARS" value="' + param + '" /> </object>'		
	}
	else
	{
		str = '<embed type = "application/x-shockwave-flash" pluginspage = "https://www.macromedia.com/go/getflashplayer" '	
		for ( i = 0; i < flashParam.length; i++ ) str += flashParam[i][0] + '="' + flashParam[i][1]+ '" ' 
		str += 'width = "'+width +'"  height = "'+height +'"  name = "'+ id +'" id = "'+ id +'" src ="' + src + '" FLASHVARS="' + param + '" > </embed>'	
	}	
	document.write(str)
}
function tool_createElem(tagName,clName)
{
	var ob = document.createElement(tagName),m
	(clName)?ob.className = clName:''
	for (var i = 2; i < arguments.length; i ++) {m = arguments[i].split(':');ob.style[ m[0] ] = m[1]}
	return ob
}
function tool_getElementsByClassName(cName,_boss)
{
	var boss = (_boss)?_boss:document.body,
		i = 0,mR = [],m = boss.getElementsByTagName('*'),rE = new RegExp("\\b"+cName+'\\b')		
	while (i < m.length) {if (rE.test(m[i].className)) mR.push(m[i]);	i ++}	
	return mR
}
function tool_getRect(obj)
{	
	var i = {}
	if (obj.getBoundingClientRect){
		var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop,
			scrollLeft = window.pageXOffset || document.documentElement.scrollLeft ||document.body.scrollLeft,
			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		
		while(obj) {
			i.top += obj.offsetTop
			i.left += obj.offsetLeft			
			obj = obj.offsetParent}		
		i.right = i.left + this.offsetWidth
		i.bottom = i.top + this.offsetHeight
	}	
	return i
}
function encode(val) {
	return encodeURIComponent(val);
}
function decode(val) {
    return decodeURIComponent(val.replace(/\+/g, " "));
}
