var xmlRequest;
var targetForXmlRequest; 
var browserWmode = "window";
var target = "sizer";
var IE='\v'=='v';

if(IE){
	browserWmode = "opaque";
}

var minimumWidth = 950;
var minimumHeight = 550;
var windowWidth = 0;
var windowHeight = 0;
var fitsize = true;
var counted;
var preloaded;

function na_preload_img(){ 
  var img_list = na_preload_img.arguments;
  if (document.preloadlist == null) 
    document.preloadlist = new Array();
  var top = document.preloadlist.length;
  for (var i=0; i < img_list.length-1; i++) {
    document.preloadlist[top+i] = new Image;
    document.preloadlist[top+i].src = img_list[i+1];
  } 
}

function na_change_img_src(name, nsdoc, rpath, preload){ 
  var img = eval((navigator.appName.indexOf('Netscape', 0) != -1) ? nsdoc+'.'+name : 'document.all.'+name);
  if (name == '')
    return;
  if (img) {
    img.altsrc = img.src;
    img.src    = rpath;
  } 
}

function na_restore_img_src(name, nsdoc){
  var img = eval((navigator.appName.indexOf('Netscape', 0) != -1) ? nsdoc+'.'+name : 'document.all.'+name);
  if (name == '')
    return;
  if (img && img.altsrc) {
    img.src    = img.altsrc;
    img.altsrc = null;
  } 
}

function countMe(){
	var divTag = document.createElement("div");
        
	divTag.id = "counter";
	divTag.className ="addContent";
	
	divTag.innerHTML = '<img src="http://counter.yadro.ru/hit?r'+escape(document.referrer)+((typeof(screen)=='undefined')?'':';s'+screen.width+'*'+screen.height+'*'+(screen.colorDepth?screen.colorDepth:screen.pixelDepth))+';u'+escape(document.URL)+';'+Math.random()+'" width=1 height=1 alt="">';
	
	document.body.appendChild(divTag);
	
	counted = true;
}

function checkSize(){
	
	var flashsite = document.getElementById("flashsite");
	
	var socIcons = document.getElementById("socials");
	
	if(!counted){
		countMe();
	}
	
	if(!flashsite){
		if(document.documentElement){  
			document.documentElement.scroll = "auto";
			document.documentElement.style.overflow = "auto";
		}
		if(document.body){  
			document.body.scroll = "auto";
			document.body.style.overflow = "auto";
        }
		if(typeof( window.innerHeight ) == 'number' ) {
			if(window.scrollbars){
				
				var hasVerticalScrollbar = document.body.scrollHeight > document.body.clientHeight;
				
				if(hasVerticalScrollbar){
					socIcons.style.right = 20;
				}else{
					socIcons.style.right = 0;
				}

				window.scrollbars.visibility = true;
				
			}
		}
		
		if(!preloaded){
			na_preload_img(false, 'images/fc_p.png', 'images/tw_p.png');
			preloaded = true;
		}
	
		return;
	}
	
	
	getWindowSize();
	targetResize();
	
	//if(IE && !fitsize){
	//	changeWindowSize();
	//}

}

function setTargetW(w) {
	if (document.all && !document.getElementById) {
		document.all[target].style.pixelWidth = w;
	} else {
		document.getElementById(target).style.width = w;
	}
}

function setTargetH(h) {
	if (document.all && !document.getElementById) {
		document.all[target].style.pixelHeight = h;
	} else {
		document.getElementById(target).style.height = h;
	}
}

function getWindowSize() {
	if( typeof( window.innerWidth ) == 'number' ) {
		windowWidth = window.innerWidth;
		windowHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
}

function targetResize(){

	if(windowHeight<minimumHeight || windowWidth<minimumWidth) {
		fitsize = false;
		
		if(windowWidth<minimumWidth){
			setTargetW(minimumWidth);
		}else{
			setTargetW(windowWidth);
		}	
		
		if(windowHeight<minimumHeight){
			setTargetH(minimumHeight);
		}else{
			setTargetH(windowHeight);
		}

		document.body.style.overflow = "auto";
	
	}else{
		
		setTargetH(windowHeight);
		setTargetW(windowWidth);
		
		document.body.style.overflow = "hidden";

	}
}


function createXMLRequest(){  
	var xmlhttp;
	try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
		xmlhttp = false;
	  }
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	  xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}  
function loadAndSetContent(file, query, target){ 
	
	targetForXmlRequest = target;

	if(!xmlRequest){
		 xmlRequest = createXMLRequest();
	}
	
	xmlRequest.open('post', file , true ); 
	xmlRequest.onreadystatechange = setContent; 
	xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	xmlRequest.send(query);              
}  
function setContent(){ 
	if (xmlRequest.readyState == 4) {
		 if(xmlRequest.status == 200) {
		   //alert(xmlRequest.responseText);
		   targetForXmlRequest.innerHTML = xmlRequest.responseText;
		 }
	}
}
