var noflash_div, flash_div, footer_pad, bgr_div, content_div, regionCookie, f_hdr, develop, scroll;
var IE = !window.getComputedStyle;
var IE6 = IE && navigator.appVersion.indexOf('MSIE 7') == -1;

var regionCookie=new jsCookie();
regionCookie.path="/";
regionCookie.domain="";
regionCookie.secure=false;
regionCookie.name="region";
regionCookie.expires="0,0,0,1"; // Minutes, Hours, Days, Years

function __load(){
	content_div = $('content-block');
	develop = $('develop');
	window.onresize = __resize;
	__resize();

	init_content();
	init_regions();
	init_text_inputs();
	if ( IE6 ) {
		png_fix();
	}
}
function __resize(){
										//not ie						//ie
	var w = Math.max(900, document.body.clientWidth);
	var h =	window.innerHeight || document.body.clientHeight;

	place_content(w, h);

	var right_margin = Math.round((w - 900) / 2);
	develop.style.right = -right_margin  + 'px';
}

function init_content(){
	if(!content_div){
		return false;
	}
	var root = content_div;
	var s_holder = $('scroll-holder');
	var s_content = $('scroll-content');

	var s_bar = $('scrollbar');
	var s_divs = $T('DIV', s_bar);
	var track = $C('track', s_divs, '', 1);
	var thumb = $C('thumb', s_divs, '', 1);
	var b_plus = $C('b-plus', s_divs, '', 1);
	var b_minus = $C('b-minus', s_divs, '', 1);

	var tim = new Timer(50);
	tim.start();

	var scroll = new Scroll(s_holder, s_content, {X: null, Y: {
		bar: s_bar,
		track: track,
		thumb: thumb,
		bPlus: b_plus, 
		bMinus: b_minus
	}}, tim);
	if(scroll.barY.th_mov){
		scroll.barY.th_mov.onaftermove.register('set angle', function(){
			this.elem.style.left = Math.round(this.left - (this.top / 4.5)) + 'px';
		});
	}
}
function init_regions(){
	var root = $('regions');
	if(!root){
		return false;
	}
	var divs = $T('DIV', root);
	root.button = $C('button', divs, '', 1);
	root.dropdown = $C('dropdown', divs, '', 1);
	root.display = $C('display', divs, '', 1);
	root.button.onclick = root.display.onclick = function(){
		this.dropdown.style.visibility = 'visible';
	}.bind(root);
	
	
	root.dropdown.onmouseout = function (e) {
		timer = setTimeout(function () {root.dropdown.style.visibility = 'hidden'}, 300 );
	}
	
	root.dropdown.onmouseover = function (e) {
		clearTimeout(timer);
		root.dropdown.style.visibility = 'visible';
	}

	root.items = $C('item', divs, 'DIV');

	if ( regionCookie.exists( ) ) {

		regionCookie.get( );
		regId = regionCookie.value;

		root.items.each(function(item){
			item.model = root;
			item.link = $T('A', item, 1);
			item._id = $T('INPUT', item, 1).value;
			item._text = item.link.firstChild.nodeValue;
			if ( item._id == regId ) {
				root.display.innerHTML = item._text;
			}
		});

	}

	root.items.each(function(item){
		item.model = root;
		item.link = $T('A', item, 1);
		item._id = $T('INPUT', item, 1).value;
		item._text = item.link.firstChild.nodeValue;
		item.link.onclick = function(){
			this.model.dropdown.style.visibility = 'hidden';
			this.model.display.innerHTML = this._text;
			setRegion(this._id);
			document.location.href = _company_network;
			return false;
		}.bind(item);
	});
}
function place_content(w, h){
	if(!content_div){
		return false;
	}
	return false;
	var top;
	if(h < 766){
		top = 115;
	}else{
		top = ((h - 766) / 1.7) + 115;
	}
	content_div.style.top = top + 'px';
}
function init_text_inputs(){
	var ips = $C('text', document, 'INPUT');
	if ( ips ) {
		ips.each(function(ip){
			var obj = text_inputs[ip.name];
			if(obj){
				ip._value = obj.value;
				ip.onblur = function(){
					if(this.value == ''){
						this.value = this._value;
					}
				};
				ip.onfocus = function(){
					if(this.value == this._value){
						this.value = '';
					}
				};
			}
		});
	}
}
var text_inputs = {
	astroauth_login: {
		value: 'Login'
	},
	astroauth_pass: {
		value: 'Password'
	}
}
AttachEvent(window, 'load', __load);

function setRegion( id ){

	if ( regionCookie.exists( ) ) {

		regionCookie.get( );
		if ( regionCookie.value != id ) {
			regionCookie.value = id;
		}

	}
	else {
		regionCookie.value = "1";
	}

	regionCookie.set( );	

}
function png_fix(){
	var imgs = $T('IMG');
	imgs.each(function(img){
		var name = img.src;
		if(name.match('\.png$')){
			var src = img.src;
			img.style.width = img.width + 'px';
			img.style.height = img.height + 'px';
			img.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '", sizingMethod="crop")';
			img.src = _root+'i/photo/blank.gif';		
		}
	})
}

function wo(link,ww,hh,title) {
	w=window.open(link,'',(ww ? 'width='+ww+',' : '')+(hh ? 'height='+hh+',' : '')+'toolbar=0,scrollbars=0,resizable=yes');
	if (link.indexOf('.html')==-1) {
		if (document.layers) title='';
		w.document.open();
		w.document.write('<html><head><title>'+title+'</title><meta http-equiv=Content-Type content="text/html; charset=windows-1251"></head>');
		w.document.write('<body bgcolor=white marginwidth=0 marginheight=0 topmargin=0 leftmargin=0><table width=100% height=100% border=0 cellspacing=0 cellpadding=0><tr><td align=center><img src='+link+' width='+ww+' height='+hh+' border=0 alt=""></td></tr></table></body></html>');
		w.document.close();
	}
	w.focus();
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}; 
function switchFontStyle( fontSize ) {
	jQuery("#scroll-content").css('font-size', parseFloat(fontSize, 10) );
}

function reInitScroll( ) {
	document.location.href = document.location.href;
}
