/*
HR_Blackout
Разработан студией Фузайлова 
http://fuzaylov.net/
*/

var HelpeR = function() {
   
    this.browserName                 = navigator.appName;
    this.browserVersion              = navigator.appVersion;
    this.ie                          = this.browserName == 'Microsoft Internet Explorer';
    this.ie6                         = this.browserVersion.indexOf('MSIE 6.0') != -1;
    this.ie7                         = this.browserVersion.indexOf('MSIE 7.0') != -1;
    this.opera                       = this.browserName == 'Opera';
    this.netscape                    = this.browserName == 'Netscape';
    this.BG                          = document.createElement('div');
    this.WHITE                       = document.createElement('div');
    this.cls                         = document.createElement('div');
	this.cls.style.padding           = '5px';
	this.title                       = document.createElement('div');
	this.title.align                 = tit_align;
	this.title.style.fontFamily      = tit_font;
	this.title.style.fontSize        = tit_font_size + 'px';
	this.title.style.color           = tit_font_color;
    this.closeA                      = document.createElement('a');
    this.closeA.href                 = 'javascript:effect.close()';
    this.cls.align                   = 'right'; 
    this.WHITE.align                 = 'center';
    this.BG.style.backgroundColor    = main_bgcolor;
    this.WHITE.style.backgroundColor = '#ffffff';
	this.BG.style.position           = this.ie6 ? 'absolute' : 'fixed';
    this.WHITE.style.position        = 'absolute';
    this.BG.style.left               = '0px';
    this.BG.style.top                = '0px';
    this.BG.style.zIndex             = '888';
    this.WHITE.style.zIndex          = '999';
    this.xPic                        = new Image();
    this.xPic.src                    = close_img;
	this.xPic.style.border           = '0px';
    this.loadingPic                  = new Image();
    this.loadingPic.src              = loading_img;
    this.loadingPic.style.marginTop  = '9px';
	this.loadingPic.style.border     = '0px';
    this.resizeStep                  = 20;
    this.movePosition                = 10;
    this.closeA.appendChild(this.xPic);
    
	window.onload = function() {
        var a = document.getElementsByTagName('a');
        
		for(var i = 0; i < a.length; i++) {
	        effect.processing(a[i]);
        }
	};

    window.onresize = function() {
	    effect.getWinSize();
        effect.resize();
    };	
}

HelpeR.prototype = {  
    
	setDefault : function() {
	    
		this.ie ? this.BG.style.filter = "alpha(opacity=0);" : this.ie ? this.BG.filters.alpha.opacity = 0 : null;
	    this.BG.style.opacity = 0;
        this.WHITE.style.width  = '50px';
        this.WHITE.style.height = '50px';
	    this.title.hasChildNodes() ? this.title.removeChild(this.title.lastChild) : null;
        this.c = 0;	  
    },
  
    processing : function(obj) {
	    
		function handler(e) {
	        var e = e || window.event;
            e.preventDefault ? e.preventDefault() : e.returnValue = false;
	        effect.gogogo(obj.href, obj.title);
        }
	    
		var classes = obj.className.split(/\s+/);
	    var i;
	    
		for(i in classes) {
			if(classes[i] == "HR") {
				if(obj.attachEvent) {
		            obj.attachEvent('onclick', handler);
	            }
                else if(obj.addEventListener) {
    	            obj.addEventListener('click', handler, false);
	            }
            }
	    }
    },
  
    close : function() {
	    
		while(this.WHITE.hasChildNodes()) {
            this.WHITE.removeChild(this.WHITE.lastChild);
        }
        document.body.removeChild(this.WHITE);
        document.body.removeChild(this.BG);   
    },
  
    screenHor : function() {
	    
		this.hor = null;
        
		if(window.scrollX) {
            this.hor = parseInt(window.scrollX);
        }
        else if(document.documentElement.scrollLeft) {
            this.hor = parseInt(document.documentElement.scrollLeft);
        }
        else if(document.body.scrollLeft) {
            this.hor = parseInt(document.body.scrollLeft);
        }
        
		this.hor == null ? this.hor = 0 : null;
        this.hor += (Math.round(effect.winWidth / 2) - 25);
        this.hor += 'px';
        return this.hor;  
    },
  
    screenVer : function() {
	    
		this.ver = null;
        
		if(window.scrollY) {
            this.ver = parseInt(window.scrollY);
        }
        else if(document.documentElement.scrollTop) {
            this.ver = parseInt(document.documentElement.scrollTop);
        }
        else if(document.body.scrollTop) {
            this.ver = parseInt(document.body.scrollTop);
        }
        
		this.ver == null ? this.ver = 0 : null;
        this.ver += (Math.round(effect.winHeight / 2) - 25);
        this.ver += 'px';
        return this.ver;  
    },
  
    setDiv : function(title) {
	    
		this.BG.style.width   = Math.max(this.maxWidth,this.winWidth)   + 'px';
        this.BG.style.height  = Math.max(this.maxHeight,this.winHeight) + 'px';
        this.WHITE.style.left = this.screenHor();
        this.WHITE.style.top  = this.screenVer();
	    this.titleText        = document.createTextNode(title);
	    this.title.appendChild(this.titleText);
        document.body.appendChild(this.BG);  
    },
  
    checkLoading : function () {
	    
		if(this.opera) {
            if(this.img.complete == true) {
	            this.WHITE_WIDTH  = parseInt(effect.img.width);
	            this.WHITE_HEIGHT = parseInt(effect.img.height);
                effect.WHITE.removeChild(effect.WHITE.lastChild);
	            setTimeout("effect.resizeWidth(" + this.WHITE_WIDTH + "," + this.WHITE_HEIGHT + ")");
            }
            else {
                setTimeout("effect.checkLoading()", 1000);
            }
        }
        else if(this.ie6 || this.ie7) {
            if(this.img.readyState == "complete" && this.img.complete == true) {
	            this.WHITE_WIDTH  = parseInt(effect.img.width);
	            this.WHITE_HEIGHT = parseInt(effect.img.height);
                effect.WHITE.removeChild(effect.WHITE.lastChild);
	            setTimeout("effect.resizeWidth(" + this.WHITE_WIDTH + ","  +this.WHITE_HEIGHT + ")");
            }
            else {
                setTimeout("effect.checkLoading()", 1000);
            }
        }  
    },
  
    loadIMG : function(url) {
	    
		this.img = new Image();
        this.img.src = url;
        
		if(this.netscape) {
	        this.img.onload = function() {
                this.WHITE_WIDTH  = parseInt(effect.img.width);
	            this.WHITE_HEIGHT = parseInt(effect.img.height);
                effect.WHITE.removeChild(effect.WHITE.lastChild);
	            setTimeout("effect.resizeWidth(" + this.WHITE_WIDTH + "," + this.WHITE_HEIGHT + ")");
            };
        }
        else {
            setTimeout("effect.checkLoading()");
        }  
    },
  
    closeBut : function() {
	    
		this.c += 1;
        this.WHITE.style.height = (parseInt(this.WHITE.style.height) + this.c) + 'px';
        
		if(this.c >= 10) {
	        this.cls.appendChild(this.title);
            this.cls.appendChild(this.closeA);
            this.WHITE.appendChild(this.cls);
        }
        else {
            setTimeout("effect.closeBut()", 50);
        }  
    },
  
    resizeWidth : function(width, height) {
	    
		this.c += this.resizeStep;
        this.WHITE.style.width = this.c + 'px';
        
		if(parseInt(this.WHITE.style.left) > 10) {
            this.WHITE.style.left = parseInt(this.WHITE.style.left) - this.movePosition + 'px';
        }
        if(this.c >= width + 10) {
            this.WHITE.style.width = width + 10 + 'px';
	        this.c = 0;
	        setTimeout("effect.resizeHeight(" + height + ")");
        }
        else {
            setTimeout("effect.resizeWidth(" + width + "," + height + ")")
        }  
    },
  
    resizeHeight : function(height)  {
	    
		this.c += this.resizeStep;
        this.WHITE.style.height = this.c + 'px';
        
		if(parseInt(this.WHITE.style.top) > 10) {
            this.WHITE.style.top = parseInt(this.WHITE.style.top) - this.movePosition + 'px';
        }
        
		if(this.c >= height + 10) {
            this.WHITE.style.height = height + 10 + 'px';
	        this.c = 0;
	        this.WHITE.style.paddingTop = '5px';
            this.WHITE.appendChild(this.img);
	        setTimeout("effect.closeBut()");
        }
        else {
            setTimeout("effect.resizeHeight(" + height + ")")
        }  
    },
  
    getWinSize : function() {
	    
		if(!this.ie6 && window.innerWidth && window.innerHeight && window.screen && window.screen.width && window.screen.height) {
            this.winWidth  = parseInt(window.innerWidth);
	        this.winHeight = parseInt(window.innerHeight);
	  
	        this.maxWidth  = parseInt(window.screen.width);
	        this.maxHeight = parseInt(window.screen.height);
        }
        if(this.ie) {
            if(document.documentElement.clientWidth && document.documentElement.clientHeight && document.body && document.body.offsetWidth && document.body.offsetWidth) {
                this.winWidth    = parseInt(document.documentElement.clientWidth);
	            this.winHeight   = parseInt(document.documentElement.clientHeight); 
		
		        this.maxWidth    = parseInt(document.body.offsetWidth);
	            this.maxHeight   = parseInt(document.body.offsetHeight);
            }
        }
    },
  
    resize : function() {
	    
		this.BG.style.width  = this.maxWidth  + 'px';
        this.BG.style.height = this.maxHeight + 'px';
        
		if(this.img.width) {
            if(this.winWidth >= this.img.width) {
	            this.WHITE.style.left = parseInt((this.winWidth - this.img.width) / 2) + 'px';
   	        }
        }  
    },
	
	setOpacity : function(obj) {
		obj.filters && obj.filters.alpha
		    ? obj.filters.alpha.opacity = effect.c * 100
			: obj.style.filter = 'alpha(opacity=' + effect.c * 100 + ');';
		
		obj.style.opacity = effect.c;	
	},
  
    appearance : function(url) {

        effect.c += 0.02;
	    this.setOpacity(effect.BG);
	        
		if(effect.c >= 0.8) {
	        effect.c = 50;
	        effect.setPicDiv(url);
	    }
	    else {	
	        setTimeout("effect.appearance('" + url + "')");	
	    }
    },
  
    setPicDiv : function(url) {
	    
		this.WHITE.appendChild(this.loadingPic);
        document.body.appendChild(this.WHITE);
        this.loadIMG(url);  
    },
  
    gogogo : function(url, title) {
        
		this.setDefault();
        this.getWinSize();
        this.setDiv(title);
        setTimeout("effect.appearance('" + url + "')");  
    }
  
};

var effect = new HelpeR();