var layoutInt;

if (document.addEventListener) {document.addEventListener("DOMContentLoaded", init, false);}

/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)>");
document.write("<\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
    if (this.readyState == "complete") {
        init();
    }
};
/*@end @*/

if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            clearInterval(_timer);
            delete _timer;
            init(); // call the onload handler
        }
    }, 10);
}

if(!detectIE()){window.onload = clearInterval(layoutInt);}



function init(){layoutInt = setInterval(init2, 100);}

function init2(){
var html = document.documentElement;
var content = document.getElementById('content');
var layout = document.getElementById('layout');

if(html && content && layout){
var siteHeight = 650 + content.offsetHeight;
//window.alert(content.offsetHeight);
if(siteHeight < html.clientHeight){
layout.style.height = html.clientHeight+'px';
}else{
layout.style.height = siteHeight+'px';
}
}


// выход из функции, если она уже вызывалась
//   if (arguments.callee.done) return;

// флаг, чтобы не запускать функцию дважды
// 	   arguments.callee.done = true


//window.alert(siteHeight);
if(detectIE() > 6 || !detectIE()){roundCorners();}
//dropShadows();
}

function dropShadows(){
var obj = getElementsByClass('dropShadows', null, null);
	for(i=0;i<obj.length;i++){
		topLeft = document.createElement('SPAN');
		topRight = document.createElement('SPAN');
		bottomLeft = document.createElement('SPAN');
		bottomRight = document.createElement('SPAN');
		
		sideLeft = document.createElement('SPAN');
		sideRight = document.createElement('SPAN');
		sideTop = document.createElement('SPAN');
		sideBottom = document.createElement('SPAN');
		//window.alert(window.client);
		topLeft.className = 'dropShadowCorner topLeft';
		topRight.className = 'dropShadowCorner topRight';
		bottomLeft.className = 'dropShadowCorner bottomLeft';
		bottomRight.className = 'dropShadowCorner bottomRight';
		
		
		sideLeft.className = 'dropShadow sideLeft';
		sideRight.className = 'dropShadow sideRight';
		sideTop.className = 'dropShadow sideTop';
		sideBottom.className = 'dropShadow sideBottom';
		
		var pStyle = getElementComputedStyle(obj[i], 'position');
		if(pStyle != 'relative' && pStyle != 'absolute'){obj[i].style.position = 'relative'; }
		
		
		
	
		
		obj[i].appendChild(sideLeft);
		obj[i].appendChild(sideRight);
		obj[i].appendChild(sideTop);
		obj[i].appendChild(sideBottom);
		
		obj[i].appendChild(topLeft);
		obj[i].appendChild(topRight);
		obj[i].appendChild(bottomLeft);
		obj[i].appendChild(bottomRight);
		

}
}

function roundCorners(){
// выход из функции, если она уже вызывалась
   if (arguments.callee.done) return;

// флаг, чтобы не запускать функцию дважды
 	   arguments.callee.done = true


var obj = getElementsByClass('roundCorners', null, null);
	for(i=0;i<obj.length;i++){
	//window.alert('sda');
		topLeft = document.createElement('SPAN');
		topRight = document.createElement('SPAN');
		bottomLeft = document.createElement('SPAN');
		bottomRight = document.createElement('SPAN');
		
		sideLeft = document.createElement('SPAN');
		sideRight = document.createElement('SPAN');
		sideBottom = document.createElement('SPAN');
		sideTop = document.createElement('SPAN');
		//window.alert(window.client);
		topLeft.className = 'roundCorner topLeft';
		topRight.className = 'roundCorner topRight';
		bottomLeft.className = 'roundCorner bottomLeft';
		bottomRight.className = 'roundCorner bottomRight';
		
		sideLeft.className = 'side left';
		sideRight.className = 'side right';
		sideBottom.className = 'side bottom';
		sideTop.className = 'side top';
		
		
		var oStyle = getElementComputedStyle(obj[i], 'position');
		if(oStyle != 'relative' && oStyle != 'absolute'){obj[i].style.position = 'relative'; }
		
		obj[i].appendChild(topLeft);
		obj[i].appendChild(topRight);
		obj[i].appendChild(bottomLeft);
		obj[i].appendChild(bottomRight);
		
		obj[i].appendChild(sideLeft);
		obj[i].appendChild(sideRight);
		obj[i].appendChild(sideBottom);
		obj[i].appendChild(sideTop);
				
	}
}

function getElementComputedStyle(elem, prop)
{
  if (typeof elem!="object") elem = document.getElementById(elem);
  
  // external stylesheet for Mozilla, Opera 7+ and Safari 1.3+
  if (document.defaultView && document.defaultView.getComputedStyle)
  {
    if (prop.match(/[A-Z]/)) prop = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
    return document.defaultView.getComputedStyle(elem, "").getPropertyValue(prop);
  }
  
  // external stylesheet for Explorer and Opera 9
  if (elem.currentStyle)
  {
    var i;
    while ((i=prop.indexOf("-"))!=-1) prop = prop.substr(0, i) + prop.substr(i+1,1).toUpperCase() + prop.substr(i+2);
    return elem.currentStyle[prop];
  }
  
  return "";
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}



function showPhoto(img, descr) {
document.getElementById('bigImg').src = img;
document.getElementById('bigImgDescr').innerHTML = descr;
showPop();
}





/*========================================
we make functions for any number of popups
underPop1
underPop2
...

popup1
popup2
...
========================================*/

//they are hidden
var popNum = 0;


function showPop() {
popNum++;
under = document.getElementById('underPop' + popNum);
pop = document.getElementById('popup' + popNum);

//show popup stuff
under.style.display = 'block';
pop.style.display = 'block';

//set underpop size
under.style.left = 0;
under.style.top = 0;
var layout = document.getElementById('layout');
//window.alert(html.offsetHeight);
under.style.width = Math.max(document.body.offsetWidth, document.body.scrollWidth) + 'px';
under.style.height = Math.max(document.getElementById('site').offsetHeight, document.body.scrollHeight) + 'px';

pop.style.left = 0;
pop.style.top = 0;

//set popup position
pop.style.left = document.documentElement.scrollLeft + ((document.body.offsetWidth - document.documentElement.scrollLeft - pop.offsetWidth) / 2) + 'px';
pop.style.top = document.documentElement.scrollTop + ((document.documentElement.clientHeight - pop.offsetHeight) / 2) + 'px';
}



function hidePop() {
if(popNum) {
	document.getElementById('underPop' + popNum).style.display = 'none';
	pop = document.getElementById('popup' + popNum);
	pop.style.display = 'none';
	if(pop.nodeName == 'form') {pop.reset();}
	popNum--;
	}
}


function showPopEnter() {
under = document.getElementById('underPopEnter');
pop = document.getElementById('popupEnter');

//show popup stuff
under.style.display = 'block';
pop.style.display = 'block';


//set underpop size
under.style.left = 0;
under.style.top = 0;
under.style.width = Math.max(document.body.offsetWidth, document.body.scrollWidth) + 'px';
under.style.height = Math.max(document.getElementById('site').offsetHeight, document.body.scrollHeight) + 'px';

pop.style.left = 0;
pop.style.top = 0;

//set popup position
pop.style.left = document.documentElement.scrollLeft + ((document.body.offsetWidth - document.documentElement.scrollLeft - pop.offsetWidth) / 2) + 'px';
pop.style.top = document.documentElement.scrollTop + ((document.documentElement.clientHeight - pop.offsetHeight) / 2) + 'px';
}



function hidePopEnter() {
document.getElementById('underPopEnter').style.display = 'none';
pop = document.getElementById('popupEnter');
pop.style.display = 'none';
pop.reset();
}

function detectIE(){
var browser = navigator.appName;
if (browser == "Microsoft Internet Explorer"){
	var b_version = navigator.appVersion;var re = /\MSIE\s+(\d\.\d\b)/;
	var res = b_version.match(re);
	//if (res[1] <= 6){return true;}
	return res[1];
	}
	return false;
}
