top.obj = null;
top.noIframeAlt = 1;
top.AA_ploadTime = new Date().getTime() / 1000;
top.AA_timer = null;
top.AA_timerTarget = null;

function AA_secs() {
    var time = parseInt( new Date().getTime() / 1000 - top.AA_ploadTime );
    var etime = top.AA_timerTarget.getAttribute("etime");
    top.AA_timerTarget.innerHTML = periodStr( etime - time );
}

function periodStr(v) {
    if( parseInt( v ) >= 31536000) return 'Вечность';
    v = Math.max( v, 0 );
//    var ss = parseInt( v ) % 60;
    var mm = parseInt( v/60 ) % 60;
    var hh = parseInt( v/3600 ) % 24;
    var dd = parseInt( v/86400 );
    var t = new Array();
    if( dd > 0) t.push( dd + ' д.' );
    if( hh || ( dd && mm)) t.push( hh + ' ч.' );
    if( mm ) t.push( mm + ' м.' );
//    if( ss || ( v < 60) ) t.push( ss + ' с.' );
    return t.join(' ');
}
function show_alt() {
    var alive=0
    try{
        alive = top.obj.offsetParent
    } catch(e) {}
    var obj = top.gebi('iinfo_alt');
    if (!obj) return false;
    if (alive && obj.style.display != 'none') setTimeout("show_alt()",500);
    else obj.style.display='none';
    return true;
}
function itemInfo(obj,evnt,show) {
	
	var div = gebi(obj.getAttribute('div_id'));		
	var iinfo_alt = top.gebi('iinfo_alt');
	if(!div) 
		return;
	
	if(!iinfo_alt) {
		
		iinfo_alt = ce('div');
		iinfo_alt.setAttribute('id','iinfo_alt');
		iinfo_alt.onmouseover=function(e){this.style.display='none'}
		var body=gebn('body')[0];
		body.insertBefore(iinfo_alt,body.childNodes[0]);
	}

	if (!show) {
            if(top.AA_timer != null) {
                window.clearInterval(top.AA_timer);
                top.AA_timerTarget = null;
                top.AA_timer = null;
            }
            iinfo_alt.style.display='none';
            document.onmousemove=function(){};
            return;
        }
	if ( show==2 ) {
		document.onmousemove=function(e) {itemInfo(obj, e||event, 1);}
		
		if (!iinfo_alt.getAttribute('art_id') || obj.getAttribute('div_id') != iinfo_alt.getAttribute('art_id')) {
			iinfo_alt.innerHTML = div.innerHTML;
			iinfo_alt.setAttribute('art_id',obj.getAttribute('div_id'));
		}

                var list = iinfo_alt.getElementsByTagName("samp");
                if( list.length > 0 ) {
                    for(var i =0 ; i < list.length; i++ ) {
                        var samp = list[i];
                        if(!samp.hasAttribute("etime") ) continue;
                        var etime = samp.getAttribute("etime");
                        if( top.AA_timer == null ) {
                            top.AA_timerTarget = samp;
                            top.AA_timer = window.setInterval( 'AA_secs()' , 1000);
                            AA_secs();//first init
                        }
                    }
                }
		            
		iinfo_alt.style.display = 'block';

		top.obj = obj;
		if (top.show_alt) {
			top.show_alt();
		}
	}

	var coor = getIframeShift();
	var ex = evnt.clientX+coor.l;
	var ey = evnt.clientY+coor.t;
//        var scrollLeft = !top.document.body.scrollLeft && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : top.document.body.scrollLeft;
//        var scrollTop = !top.document.body.scrollTop && document.documentElement.scrollTop ? document.documentElement.scrollTop : top.document.body.scrollTop;

//        var ex = 0;
//        var ey = 0;
//	if (top.noIframeAlt) {
//            ex = evnt.clientX + scrollLeft;
//            ey = evnt.clientY + scrollTop + 10;
//	}

        var delta = 12;
	var x = ex + iinfo_alt.offsetWidth > top.document.body.clientWidth + 10 ? ex - iinfo_alt.offsetWidth - delta : ex + delta;
	var y = ey + iinfo_alt.offsetHeight > top.document.body.clientHeight - 20 ? ey - iinfo_alt.offsetHeight - delta : ey + delta;

	if (x<0)x = ex-iinfo_alt.offsetWidth/2;
	if (x<7)x = 7;
	
	if (x > top.document.body.clientWidth - iinfo_alt.offsetWidth - 20) {
		x= top.document.body.clientWidth - iinfo_alt.offsetWidth - 20;
	}

	iinfo_alt.style.left = x + 'px';
	iinfo_alt.style.top = y + 'px';
	return;
}

function boxInit(sms1,ds1){window.sms1=sms1;window.ds1=ds1}
function boxSize(isStretch) {
    var sms1=window.sms1;
    var ds1=window.ds1;
    if( isStretch ) {
        var e=gebi('box');
        var wh = winHeight();
        if( wh > sms1 && e.offsetHeight >= sms1 ) {
            e.style.height='100%';
            if( e.offsetHeight > ds1 ) {
                e.style.height= ds1+'px';
                e.style.top = ((wh - ds1) / 2) + 'px';
            } else {
                e.style.top = '0px';
            }
        } else {
            e.style.height= sms1+'px';
            e.style.top = '0px';
        }

        e.style.width=(e.offsetHeight-145)*1.8+'px';
    } else hideLogo(0);
}
function gameShow() {
    window.delta = 1;
    if(window.gameVisibleInterval==null)
        window.gameVisibleInterval = window.setInterval('gameVisible()', 10);
}

function gameVisible() {
    if(window.w==100) {
        clearProgress();
        loaderFadeOut();
        gebi('fl').style.left = '0px';
        gebi('fl').style.position = 'static';
    }
}

function loaderFadeOut() {
    var e = gebi('lscreen');
    var e2 = gebi('fl');

    var o = e.style.opacity;
    if(o==undefined) {
        loaderFaded(e,e2);
        return;
    }

    if(o=='') e.style.opacity = o = 1;
    e.style.opacity-=0.1;

    var o2 = e2.style.opacity;
    if(o2=='') e2.style.opacity = o2 = 0;
    e2.style.opacity=parseFloat(o2)+0.1;

    if(Math.round(o*10)<=1) {
        loaderFaded(e,e2);
        return;
    }

    setTimeout("loaderFadeOut()", 10);
}

function loaderFaded(e,e2) {
    e.style.display = 'none';
    e2.style.opacity = 1;
}

//window.onkeyup = function(e) {
//    alert(e.keyCode);
//}

function progressBg() {
    var e = gebi('loader').childNodes[0].childNodes[0];
    var s = e.style.backgroundPosition.split('px');
    var l = s[0] ? parseInt(s[0]) + 2 : 0;
    var t = s[1] ? parseInt(s[1]) : 0;
    e.style.backgroundPosition = l+'px '+t+'px';
    if(window.progressBgInterval==null)
        window.progressBgInterval = window.setInterval('progressBg()', 50);
}

function clearProgress() {
    clearInterval(window.gameVisibleInterval);
    clearInterval(window.progressBgInterval);
    clearInterval(window.progressInterval);
}

window.delta = 0;
function progress() {
    var e = gebi('loader').childNodes[0].childNodes[0];
    if(!window.w)window.w = 1;
    var delta = window.delta ? window.delta : 1 / window.w;
    if(delta > 0.9 && !window.delta) delta = 0.9;
    window.w += delta;
    if(window.w>=100) {
        window.w = 100;
        gameShow();
    }
    e.style.width = window.w+'%';
    e.childNodes[0].innerHTML = Math.round(window.w)+'%';
    if(!window.delta&&window.progressInterval==null)
        window.progressInterval = window.setInterval('progress()', 10);
}

function progressBar() {
    progressBg();
    progress();
}

function winWidth(){if(window.innerWidth)return window.innerWidth;var d=document.documentElement;if(d&&d.clientWidth)return d.clientWidth;var db=document.body;return db?db.clientWidth:0}
function winHeight(){if(window.innerHeight)return window.innerHeight;var d=document.documentElement;if(d&&d.clientHeight)return d.clientHeight;var db=document.body;return db?db.clientHeight:0}
function goto_link(link){window.location.href=link}
function function_exists(function_name){return (typeof function_name=='string')?(typeof this.window[function_name]=='function'):(function_name instanceof Function)}
function popup(l,w){if(!window.focus)return true;var h=typeof(l)=='string'?l:l.href;window.open(h,w,'width=388,height=209,left=50,top=50,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no');return false}
function popup_support(){var wnd = window.open('/support.php','faor_support','width=800,height=800,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=no');wnd.focus();return false}
function gebi(id){return document.getElementById(id)}
function gebn(id){return document.getElementsByTagName(id)}
function ce(id){return document.createElement(id)}
function getCoords(obj){var o=typeof(obj)=='string'?gebi(obj):obj;var r={'l':o.offsetLeft,'t':o.offsetTop,'w':o.offsetWidth,'h':o.offsetHeight};while(o=o.offsetParent){r.l+=o.offsetLeft;r.t+=o.offsetTop;}return r}
function getIframeShift(obj){var obj=obj||window;var r={'l':0,'t':0};while(o=obj.frameElement){obj=obj.parent;r.l+=o.offsetLeft-obj.document.body.scrollLeft;r.t+=o.offsetTop-obj.document.body.scrollTop;while(o=o.offsetParent){r.l+=o.offsetLeft;r.t+=o.offsetTop;}}return r}
function showUserInfo(nick){var url="/info.php?"+encodeURIComponent(nick);window.open(url,"","width=720,height=700,location=yes,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no")}
function srAddEvent(obj, type, fn){if (obj.addEventListener)obj.addEventListener(type, fn, false);else if(obj.attachEvent)obj.attachEvent(("on"+type),fn)}
function rsHRReplace(e){if(!function_exists('_nhr'))return;var div=ce('div');div.innerHTML=_nhr('98%','center','',e.style.cssText);e.style.display = 'none';e.parentNode.insertBefore(div,e)}
function hideLogo(r){var b=gebi('bottom');if(!b)return;var e=gebi('flclient');var f=e.getBoundingClientRect().top;b.style.height=(f>0?f/2:0)+'px';if(!r)gebi('topLogo').style.backgroundImage=f<100?"":"url('/img/gameborder/gameborderFaor_piece05.jpg')"}
function HRnHR() {var s=gebn('hr');var l=s.length;for(var i=0;i<l;i++)rsHRReplace(s[i])}
srAddEvent(window, 'load', HRnHR);
