// JavaScript Document
function getsize(element) {  
	return {w: element.offsetWidth, h: element.offsetHeight}; 
} 
function GetPosition(element) {
    var offsetLeft = 0, offsetTop = 0;
    do {
        offsetLeft += element.offsetLeft;
        offsetTop  += element.offsetTop;
    } while (element = element.offsetParent);
	//alert("x:" + offsetLeft +"y"+ offsetTop); 
    return {x:offsetLeft, y:offsetTop};
}
function SetPosition(obj, x, y){
    with(obj.style) {
    	position = 'absolute';
    	top = y + 'px';
    	left = x + 'px';
    }
} 
function PlaceOnScreenCenter(obj){
	viewportH = document.documentElement.clientHeight;
	viewportW = document.documentElement.clientWidth;
	//alert(viewportW);
	ALheight = obj.offsetHeight;
	ALwidth = obj.offsetWidth;
	//alert(obj.id+" - "+ALwidth);
	if(ALheight<viewportH){
		var topPos = Math.abs((viewportH/2)-(ALheight/2))+document.documentElement.scrollTop;
	} else {
		var topPos = Math.abs((viewportH/2)-(ALheight/2))+document.documentElement.scrollTop-(ALheight-viewportH)/2;
	}
	var leftPos = Math.abs((viewportW/2)-(ALwidth/2))+document.documentElement.scrollLeft;
	if (navigator.userAgent.match('MSIE') ) {
		obj.style.position = 'absolute';
		obj.style.top = topPos;
		obj.style.left = leftPos;
		obj.style.visibility = 'visible';
	} 
		else 
	{
		obj.style.position = 'absolute';
		obj.style.top = topPos+"px";
		obj.style.left = leftPos+"px";
		obj.style.visibility = 'visible';
	}
}

function SetSize(obj, x, y){
    with(obj.style) {
    	width = y + 'px';
    	height = x + 'px';
    }
}
function point(obj, PointColor, DefoultColor, Cursor){
	if (navigator.userAgent.match('MSIE') ) {
		with(obj.style) {
			if(background!=PointColor){
				background = PointColor;
				cursor = Cursor;
			} else {
				background = DefoultColor;
			}
		}
	}
}
function Collapse(obj){
    with(obj.style) {
    	width = '';
    	height ='';
    }	
}
function correctPNG() {
		for (var i=0; i<document.images.length; i++) {
		var img = document.images[i];
		var imgName = img.src.toUpperCase();
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
		var imgID = (img.id) ? "id=\"" + img.id + "\" " : "";
		var imgClass = (img.className) ? "class=\""+img.className+"\" " : "";
		var imgTitle = (img.title) ? "title=\""+img.title+"\" " : "title=\"" + img.alt + "\" ";
		var imgStyle = "display:inline-block;"+img.style.cssText;
		if (img.align == "left") imgStyle = "float:left;" + imgStyle;
		if (img.align == "right") imgStyle = "float:right;" + imgStyle;
		if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
		var strNewHTML = "<span "+imgID+imgClass+imgTitle+" style=\"width: "+img.width+"px; height: "+img.height+"px;"+imgStyle+";"    + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+img.src+"\', sizingMethod='scale');\"><img src=\"images\/blank.gif\" width=\"1\" height=\"1\" /></span>";
		img.outerHTML = strNewHTML;
		i = i-1;
		}
		}
}
		if (window.attachEvent && navigator.userAgent.indexOf("Opera")==-1)   window.attachEvent("onload", correctPNG); 

mtTails = new Array();
function ControlMainFrame(){
	//document.getElementById("avantalink").style.top = 50+"px";
	setInterval(
				function (){
					
	viewportW = document.documentElement.clientWidth;
	if(viewportW<1200){
		if(document.getElementById("MainF").width!=viewportW){
			document.getElementById("MainF").width=viewportW;
			document.getElementById("fish").style.backgroundPosition="-100px";

		}
		var elems = document.getElementsByName('mtTail'); 
			for(var i=0; i<elems.length; i++){
				if(elems[i].firstChild.style.left != "0px" ){
					elems[i].firstChild.style.left = "0px";	
				}
				if(viewportW>1000){
					var w = 141-(1200-viewportW)/2;
				} else {
					var w =  141-(1200-1000)/2;
				}
				if(w<1){w=1;}
				elems[i].firstChild.style.width = w+"px";
				
			}
	} else {
		if(document.getElementById("MainF").width!=1200){
			document.getElementById("MainF").width=1200;
			document.getElementById("fish").style.backgroundPosition="0px";
		}
		var elems = document.getElementsByName('mtTail'); 
		for(var i=0; i<elems.length; i++){
			var parentPos = GetPosition(elems[i].parentNode);
			if(elems[i].firstChild.style.left != (parentPos['x']-141+elems[i].parentNode.offsetWidth)+"px" ){
				elems[i].firstChild.style.left = (parentPos['x']-141+elems[i].parentNode.offsetWidth)+"px";	
			}				
			elems[i].firstChild.style.width = 141+"px";
		}		
	}
 
	}, 1);
}
PreloadedImages = new Array();
function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}
function PreloadImage(URL){
	var PreloadedImage = new Image();
	var name = str_replace("/", "_", URL);
	PreloadedImage.src= URL;
	PreloadedImages[name] = PreloadedImage;
}
function Pimage(URL){
	var name = str_replace("/", "_", URL);
	//alert(name);
	return PreloadedImages[name].src;
}
var GlobalDark = 0;
function DisplayDark(obj){
	 var DarkField = document.createElement('div');
	 DarkField.id = "DarkField";
	 //DarkField.style.backgroundImage = "img/avanta/50_gray.png";
    with(DarkField.style) {
		//backgroundColor = 'red' ;
		zIndex = obj.style.zIndex-1;
		backgroundImage = "url(img/avanta/50_gray.png)";
    	position = 'absolute';
    	top = 0 + 'px';
    	left = 0 + 'px';
    }
	 document.body.appendChild(DarkField);
	 SetSize(DarkField, document.body.offsetHeight, document.body.offsetWidth);
	 GlobalDark = 1;
}
function UnDark(){
	if(GlobalDark == 1){
		document.body.removeChild(document.getElementById("DarkField"));
	}
	GlobalDark = 0;
}
//alert("Размер документа: "+ document.body.offsetWidth +"x"+ document.body.offsetHeight);
