var opened = 0;
var intID = '';

function opn_btns(objid){

	document.getElementById(objid).style.display = 'block';

}

function close_btns(objid){

	document.getElementById(objid).style.display = 'none';
}


rld = function(){
	document.location.href = document.location.href;
};

function setIntv(){
	if (intID != '') window.clearInterval(intID);
	intID = setInterval("rld()", 60000*1000);
}

//setIntv();

/* title page cross script */
var cur_node = 0;
var ivalCross = null;

var oSwitchImgs = new Array();

oSwitchImgs[0] = 'p-prev-dsbl';
oSwitchImgs[1] = 'p-prev';
oSwitchImgs[2] = 'p-next-dsbl';
oSwitchImgs[3] = 'p-next';

function swtch_ttl_news(direction){

	// back
	if (direction == 0){
		var tmp_node = cur_node-1;
	} else {
	// forward
		var tmp_node = cur_node+1;
	}

	var oTmp = document.getElementById('ttl_news'+tmp_node);
	if (oTmp != undefined){
		cur_node = tmp_node;
		oTmp.style.display = 'block';
		
		var oTtl = false;

		if (cur_node == 0){
			document.getElementById('ttl-prev-img').className=oSwitchImgs[0];

		} else {
			document.getElementById('ttl-prev-img').className=oSwitchImgs[1];
		}
		
		var i = 0;
		while (document.getElementById('ttl_news'+ i) != undefined){
			if (i != cur_node){
				document.getElementById('ttl_news'+ i).style.display = 'none';
			}
			
			i++
		}
		// check next page

		if (document.getElementById('ttl_news'+ (cur_node + 1)) != undefined){
			
			document.getElementById('ttl-next-img').className=oSwitchImgs[3];
		} else {
			document.getElementById('ttl-next-img').className=oSwitchImgs[2];
		}
	}
}

function cross_news(){

	swtch_ttl_news(1);

	var oTmp = document.getElementById('ttl_news'+(cur_node+1));
	if (oTmp == undefined){
		cur_node = -1;
	}

}

function clearIntAndMove(to){
	if (ivalCross != null){
		clearInterval(ivalCross);
	}
	swtch_ttl_news(to);
}

/* function added phrase to the page */
function showPhrase(){

	if (oPhrases != undefined && $_('phCont') != undefined){
		var elem_id = Math.floor(Math.random()*oPhrases.length);
		
		$_('phCont').innerHTML = oPhrases[elem_id].title+'<div>'+oPhrases[elem_id].author+'</div>';
		
	}
}


var theme_prefix = 'theme';
var you_prefix = 'you';
function selFilterType(id, prefix){
	sw_tab(prefix+'_0_'+id, prefix+'_0'); 
	portal.storage.set('pphp_'+prefix, id);
	$_(prefix+'_inn').innerHTML = $_(prefix+'_0_'+id).innerHTML;
	//showHide(prefix);
	$_(prefix+'_value').value = id;
}

portal.ready(function _r(){if (typeof portal.storage.get('pphp_'+theme_prefix) != "undefined") sw_tab(theme_prefix+'_0_'+portal.storage.get('pphp_'+theme_prefix), theme_prefix+'_0')});
portal.ready(function _t(){if (typeof portal.storage.get('pphp_'+you_prefix) != "undefined") sw_tab(you_prefix+'_0_'+portal.storage.get('pphp_'+you_prefix), you_prefix+'_0')});

var alpha = '0.5';

function showLayer(num){

	if ($_('q_'+num)){

		// make lightbox
		var el = elem('div', {'class' : 'loader-abs'});

		var el_inn = elem('div', {'class' : 'inner'});
		el_inn.style.opacity = el.style["'-khtml-opacity"] = el.style["-moz-opacity"] = alpha;
		if (/MSIE/.test(navigator.userAgent)) {
			el_inn.style.filter = alpha === '' ? '' : "alpha(opacity=" + (alpha * 100) + ")";
			if (!el_inn.currentStyle || !el_inn.currentStyle.hasLayout)
				el_inn.style.display = 'inline-block';
		}
		el.appendChild(el_inn);
		
		// making new sub layer and attaching to it event
		portal.events.attach(el_inn, "mousedown", function (evt){
			if (el){
				el.parentNode.removeChild(el);
				el = null;
			}
			//el.style.display = 'none';
		});
		
		var el_out = elem('div', {'class' : 'outer'});

		var el_close = elem('div', {'class': 'close'}, false, portal.mess.close);
		portal.events.attach(el_close, "mousedown", function (evt){
			if (el){
				el.parentNode.removeChild(el);
				el = null;
			}
		});
		
		el_out.appendChild(el_close);

		var div_q = elem('div', {'class': 'q png'}, false, false);
		div_q.innerHTML = $_('q_'+num).innerHTML;
		el_out.appendChild(div_q);
		var div_a = elem('div', {'class': 'a'}, false, false);
		div_a.innerHTML = $_('a_'+num).innerHTML;
		el_out.appendChild(div_a);
		
		el.appendChild(el_out);
							
		document.body.appendChild(el);
		
		var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
		
		el.style.width = el_inn.style.width = document.body.scrollWidth + 'px';
		el.style.height = el_inn.style.height = document.body.scrollHeight + 'px';
		el_out.style.top = scrollTop + getClientHeight()/2 +  'px';

	}

}


function showPackLayer(num){

	if ($_('q_'+num)){

		var el = elem('div', {'class' : 'loader-abs pack-layer'});

		var el_inn = elem('div', {'class' : 'inner'});
		el_inn.style.opacity = el.style["'-khtml-opacity"] = el.style["-moz-opacity"] = alpha;
		if (/MSIE/.test(navigator.userAgent)) {
			el_inn.style.filter = alpha === '' ? '' : "alpha(opacity=" + (alpha * 100) + ")";
			if (!el_inn.currentStyle || !el_inn.currentStyle.hasLayout)
				el_inn.style.display = 'inline-block';
		}
		el.appendChild(el_inn);
		
		portal.events.attach(el_inn, "mousedown", function (evt){
			if (el){
				el.parentNode.removeChild(el);
				el = null;
			}
		});
		
		var el_out = elem('div', {'class' : 'outer'});

		var el_close = elem('div', {'class': 'close'}, false, portal.mess.close);
		portal.events.attach(el_close, "mousedown", function (evt){
			if (el){
				el.parentNode.removeChild(el);
				el = null;
			}
		});
		
		el_out.appendChild(el_close);

		var tmpel = elem('div', {'class': 'a'}, false, false);
		var spn = document.createElement('SPAN');
		spn.innerHTML = $_('a_'+num).innerHTML;
		tmpel.appendChild(spn)
		el_out.appendChild(tmpel);

		el.appendChild(el_out);
							
		document.body.appendChild(el);
		
		var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
				
		el.style.width = el_inn.style.width = document.body.scrollWidth + 'px';
		el.style.height = el_inn.style.height = document.body.scrollHeight + 'px';
		
		el_out.style.top = scrollTop + getClientHeight()/2 + 'px';

		

	}

}

/* function show problem layer for IE6 */
function showIE6Update(){
	var elCOntainer = elem('div', {'class' : 'trouble'}, false, portal.mess.IE6);
	elCOntainer.appendChild(elem('a', {'class' : 'clr'}, false, false));
	elCOntainer.appendChild(elem('a', {'class' : 'ie png', 'href' : 'http://www.microsoft.com/rus/windows/internet-explorer/'}, false, 'Internet Explorer'));
	elCOntainer.appendChild(elem('a', {'class' : 'ff png', 'href' : 'http://www.mozilla-russia.org/products/firefox/'}, false, 'Mozilla FireFox'));
	elCOntainer.appendChild(elem('a', {'class' : 'clr'}, false, false));
	if ($_('trouble')){
		$_('trouble').appendChild(elCOntainer);
	}
	
}

/* check for browser */
var vIE = (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;
if (vIE < 7 && vIE != -1)
	portal.ready(showIE6Update);
	
/* hide pano */
function hidePano() {
	var state,exdate=new Date();
	exdate.setDate(exdate.getDate()+365);

	if ($_('coverflow-layout').style.display != 'none'){
		$('#coverflow-layout').hide(200);
		$('#hide').removeClass('b-mosaic-hide').addClass('b-mosaic-show').html(portal.mess.mosaic.show);
		state = 1;
	} else {
		$('#coverflow-layout').show(200);
		$('#hide').addClass('b-mosaic-hide').removeClass('b-mosaic-show').html(portal.mess.mosaic.hide);
		state = 0;
	}
	
	setCookie('no_pano',state,exdate.toGMTString(),'/');
}



// gallery
$(document).ready(function(){

	// for each gallery on the page
	var i = 1, found = false;
	do{
		
		if ($('#gallery-'+i).length > 0){
			Galleria.loadTheme('/js/jquery/galleria/src/themes/lightbox/galleria.lightbox.js');
			$('#gallery-'+i).galleria({
				data_source: '#gallery-src-'+i,
		        keep: '#gallery-src-'+i,
		        image_margin: '5',
		        data_config: function(img) {
			        return {
			            description: $(img).attr('alt')
			        }
			    }
			});
			found = true;
			i++;
		} else
			found = false;
	
	}while (found)

})