/**
 * @author jman
 */

function bgHeight(){
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
	}
	else {
		cont = document.getElementById("mainContainer");
		inner = document.getElementById("page");
		//alert("БЫЛО: \nокно " + cont.clientHeight + "px \n" + "содержимое " + inner.clientHeight + "px"  );
		cont.style.height = (cont.clientHeight < inner.clientHeight) ? "auto" : "100%";
		//alert("СТАЛО: \nокно " + cont.clientHeight + "px \n" + "содержимое " + inner.clientHeight + "px"  );
	}
}



//Функция которая убирает обводку ссылок и кнопок
function shitfocus(){
	var arrLinks = document.getElementsByTagName('a');
	for (i = 0; i < arrLinks.length; i++) {
		arrLinks[i].hideFocus = true;
	}
	var arrInputs = document.getElementsByTagName('input');
	for (i = 0; i < arrInputs.length; i++) {
		arrInputs[i].hideFocus = true;
	}
}


function prev(container){
	var children = container.childNodes;
	for (i = 0; i < children.length; i++) {
		if (children[i].nodeType != 1) {
			container.removeChild(children[i]);
		}
	}
	var nextArrow = container.lastChild;
	container.removeChild(nextArrow);
	var lCh = container.lastChild;
	container.removeChild(lCh);
	var prevArrow = container.firstChild;
	container.removeChild(prevArrow);
	container.insertBefore(lCh, container.firstChild);
	container.insertBefore(prevArrow, container.firstChild);
	container.appendChild(nextArrow);
	listDisplay(children);
}

function next(container){
	var children = container.childNodes;
	for (i = 0; i < children.length; i++) {
		if (children[i].nodeType != 1) {
			container.removeChild(children[i]);
		}
	}
	var prevArrow = container.firstChild;
	container.removeChild(prevArrow);
	var fCh = container.firstChild;
	container.removeChild(fCh);
	var nextArrow = container.lastChild;
	container.removeChild(nextArrow);
	container.appendChild(fCh);
	container.insertBefore(prevArrow, container.firstChild);
	container.appendChild(nextArrow);
	listDisplay(children);
}

function listDisplay(children) {
	for (a = 0; a < children.length; a++) {
		if (a > 7 && a != children.length - 1 ) {
			children[a].style.display = 'none';
		}
		else {
			children[a].style.display = 'block';
		}
	}
}


//галеря для страны
function galery(imgCont,photos){
	for(i=0; i < imgCont.childNodes.length; i++){
		if (imgCont.childNodes[i].tagName == "IMG") {
			prevIMG = imgCont.childNodes[i];
		}
	}
	ex = (document.getElementById('mainPhoto').src.indexOf(photos['img00']['photo']));
	abspath =(document.getElementById('mainPhoto').src.substring(0, ex));
	for(name in photos){
		photos[name]['photo'] = abspath + photos[name]['photo'];
		photos[name]['preview'] = abspath + photos[name]['preview'];
	}
	for(name in photos){
		if( photos[name]['preview'] == prevIMG.src){
			mainPhotoSrc = photos[name]['photo'];
		}
	}

	mainPhotoIMG = document.getElementById('mainPhoto');
	for(name in photos){
		if(photos[name]['photo'] == mainPhotoIMG.src){
			prevIMGSrc= photos[name]['preview'];
		}
	}
	mainPhotoIMG.src = mainPhotoSrc;
	prevIMG.src = prevIMGSrc;
}

function strobo(){
	for (var i = 0; i < document.getElementsByTagName('*').length; i++){
		if(document.getElementsByTagName('*')[i].className == "strobo"){
			var elem = document.getElementsByTagName('*')[i].firstChild;
			setInterval(function(){
			elem.className = (elem.className != "active")? "active": "";
			 }, 400 );
		}
	}
}



//Обратная связь

function modalWindow(elem, flag) {
	var obj = document.getElementById(elem);
	if (flag != "hide") {
		runSpalshScreen("show" ,2 , "000", true);
		obj.parentNode.removeChild(obj);
		document.body.appendChild(obj);
		obj.style.display = "block";
		obj.style.position = "fixed";
		obj.style.zIndex = '600';
		obj.top = 0;
		if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
			obj.top = parseInt(document.documentElement.scrollTop, 10);
			obj.style.position = "absolute";
		}
		obj.height = obj.clientHeight;
		obj.width = obj.clientWidth;
		var windowHeight = document.documentElement.clientHeight;
		var windowWidth = document.documentElement.clientWidth;
		obj.style.top = ((windowHeight / 2) - (obj.height / 2)) + obj.top
				+ "px";
		obj.style.left = ((windowWidth / 2) - (obj.width / 2)) + "px";
		if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
			window.attachEvent("onscroll", function(){setScroll(obj)});
		}
		document.getElementById('tShadow').onclick = function (){
			modalWindow(elem, "hide");
		}
	} else {
		obj.style.display = "none";
		runSpalshScreen("hide");
	}
}

function runSpalshScreen(flag, opacity, bg, slow ) {
	if (flag != "hide") {
		var shadow = document.createElement('div');
		shadow.id = ('tShadow');
		document.body.appendChild(shadow);
		shadow.style.width = '100%';
		shadow.style.top = 0;
		shadow.style.left = 0;
		shadow.style.position = 'fixed';
		if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
			document.body.style.backgroundAttachment = "fixed";
			document.body.style.height = '100%';
			shadow.style.position = 'absolute';
			shadow.style.top = parseInt(document.documentElement.scrollTop, 10) + "px";
			var fr = document.createElement("iframe");
			fr.id = ('fShadow')
			fr.style.width = '100%';
			fr.style.height = '100%';
			fr.style.left = 0;
			fr.style.top = parseInt(document.documentElement.scrollTop, 10) + "px";
			fr.style.position = "absolute";
			fr.style.zIndex = 100;
			fr.border = 0;
			fr.style.filter = ('alpha(opacity=0)');
			fr.style.backgroundImage = 'url(x.gif)';
			fr.style.backgroundAttachment = 'fixed';
			document.body.appendChild(fr);
		}
		if (bg){
			shadow.style.backgroundColor = "#" + bg;
		}
		shadow.style.zIndex = '400';
		if (opacity) {
			var op = opacity
			shadow.style.opacity = op/10;
			shadow.style.filter = ('alpha(opacity='+op*10+')');
		}
		else {
			shadow.style.opacity = '0';
			shadow.style.filter = ('alpha(opacity=0)');
		}
		if (slow) {
			for (var i = 0; i <= 100; i += 5) {
				(function(){
					var pos = i;
					setTimeout(function(){
						shadow.style.height = pos + "%";
					}, (pos + 1) * 2);
				})();
			}
		}
		else{
			shadow.style.height = "100%";
		}
	}
	else {
		var shadow = document.getElementById('tShadow');
		shadow.parentNode.removeChild(shadow);
		if(document.getElementById('fShadow')){
			var elem = document.getElementById('fShadow');
			elem.parentNode.removeChild(elem);
		}
	}
}

function setScroll(obj){
	if (document.getElementById('tShadow')) {
		document.getElementById('tShadow').style.top = parseInt(document.documentElement.scrollTop, 10) + "px";
		document.getElementById('fShadow').style.top = parseInt(document.documentElement.scrollTop, 10) + "px";
	}
	var windowHeight = document.documentElement.clientHeight;
	obj.style.top = ((windowHeight / 2) - (obj.height / 2)) + parseInt(document.documentElement.scrollTop, 10) + "px";
}

//Загрузка старницы
window.onload = function(){
	shitfocus();
	bgHeight();
}


