var agt = navigator.userAgent.toLowerCase();
var ver = parseInt(navigator.appVersion);
var ie = ((agt.indexOf('msie') != -1) && (agt.indexOf('opera') == -1));
var ie5 = (ie && (ver == 4) && (agt.indexOf('msie 5.0')!= -1) );
var opera = (agt.indexOf("opera") != -1);
var opera8 = (agt.indexOf("opera 8") != -1);

// - position bottom (для IE5 Opera8)
function position_bottom()
{
	var e = (document.body ? document.body : document.documentElement);
	var m = document.getElementById('bodyBlock');
	var b = document.getElementById('bottom');

	if(e.clientHeight < m.clientHeight)
	{
		b.style.top = m.clientHeight - b.clientHeight;
	}
	else
	{
		b.style.top = e.clientHeight - b.clientHeight;
	}
}

if(ie5 || opera8)
{
	window.onload = function(){position_bottom();}
	window.onresize = function(){position_bottom();}
}
//*******************************************************************

var d = document
var win;

function setCookie(name, value, expires, path, domain, secure)
{
	var curCookie = name + '=' + escape(value) +
	((expires) ? ';expires=' + expires : '') +
	((path) ? ';path=' + path : '') +
	((domain) ? ';domain=' + domain : '') +
	((secure) ? ';secure' : '');
	if ((escape(value)).length <= 4000) document.cookie = curCookie+';';
}

function getCookie(name)
{
	var prefix = name + "=";
	var cookieStartIndex = document.cookie.indexOf(prefix);
	if (cookieStartIndex == -1) return null;
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
	if (cookieEndIndex == -1) cookieEndIndex = document.cookie.length;
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function newWin(url,w,h)
{
	var left = (screen.availWidth/2) - w/2;
	var top = 0;

	if(opera)
	{
		top = Math.floor((d.body.clientHeight/2) - h/2);
	}
	else
	{
		top = Math.floor((screen.availHeight/2) - h/2);
	}
	
	var features = 'width=' + w + ',height=' + h + ',scrollbars=1,status=no,resizable,left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top + '';
	win = window.open("" + url + "", "", features);
}

function gallery(path)
{
	var img = new Image();
	img.onload = function(){
		var w = img.width;
		var h = img.height;

		win = window.open("", "", "width=" + w + ", height=" + h + " ");
		win.document.write("<html><body style='margin:0px;padding:0px;text-align:center;'>");
		win.document.write("<img src='" + img.src + "' alt='закрыть окно' onclick='window.close();'>");
		win.document.write("</body></html>");
		win.document.close();
	}
	img.src = path;
}
//*******************************************************************
// - enter flash
function shSWFile(swf,width,height,backcolor)
{
	d.write(
		'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+width+'" height="'+height+'">' +
		'<param name="movie" value="'+swf+'">' +
		'<param name="quality" value="best">' +
		'<param name="bgcolor" value="'+backcolor+'">' +
		'<param name="wmode" value="transparent">' +
		'<embed src="'+swf+'" quality="best" bgcolor="'+backcolor+'" width="'+width+'" height="'+height+'" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>' +
		'</object>'
		);
}
//*******************************************************************

function replaceMult()
{
	var obj = d.getElementById('topclip');
	var h = obj.offsetHeight;
	if(h == 550){minMult(); setCookie('statusClip',0);}
	else if(h == 150){maxMult(); setCookie('statusClip',1);}
}
function minMult()
{
	var obj = d.getElementById('topclip');
	var objMiddle = d.getElementById('middle');
	var h = obj.offsetHeight;
	var step = 50;
	obj.style.height = (h - step) + 'px';
	if(h > 200)
	{
		window.setTimeout('minMult()', 1);
		objMiddle.style.paddingTop = 24 + 'px';
		if(opera){obj.onmousemove = function(){return false}}
	}
}
function maxMult()
{
	var obj = d.getElementById('topclip');
	var objMiddle = d.getElementById('middle');
	var h = obj.offsetHeight;
	var step = 50;
	obj.style.height = (h + step) + 'px';
	if(h < 500)
	{
		window.setTimeout('maxMult()', 1);
		objMiddle.style.paddingTop = 0 + 'px';
		if(opera){obj.onmousemove = function(){return false}}
	}
}
