/* Author : Koryaka Arthur Vladimirovich - http://www.delacompa.com */
//console.profile(); 
var dl$ = function(id)
{
    return document.getElementById(id);
}     
 
var delacompa = function()
{               
    var that = this;

    this.detectCSS3 = function()
    {
        return function ()
        {
            return (typeof(document.body.style.borderRadius) !== undefined)?1:0;
        }    
    }();
    
    this.getByTag = function(name)
    { 
        return document.getElementsByTagName(name);
    };
    
    this.getPosition = function(el) 
    {
        var obj = el;
        var x = 0;
        var y = 0;
        while(el) 
        {
            x += el.offsetLeft;
            y += el.offsetTop;
            el = el.offsetParent;
        }
        return {x:x, y:y};
    };
    
    this.getBrowser = function()
    {
        var nav = navigator;
        var browserName=nav.appName;
        var userAgent = nav.userAgent;
        var version = nav.appVersion;
        var dtBrowser = 'Unknow Browser';
        var dtVersion = 0;
        if (browserName=="Microsoft Internet Explorer")
        {
            if (/MSIE (\d+\.\d+);/.test(userAgent))var dtVersion = new Number(RegExp.$1) 
            dtBrowser = 'IE';
        }
        else if(browserName =='Opera')
        {
            dtBrowser = 'Opera';
            dtVersion = version;
        }
        else
        {
            if (userAgent.indexOf('Firefox') !=-1)
            {
                if (/Firefox\/(\d+\.\d+)/.test(userAgent))var dtVersion = new Number(RegExp.$1) 
                dtBrowser = 'Firefox';    
            }
            else if(userAgent.indexOf('Chrome') !=-1)
            {
                if (/Chrome\/(\d+\.\d+)/g.test(userAgent))var dtVersion = new Number(RegExp.$1) 
                dtBrowser = 'Chrome';
            }
            else if(userAgent.indexOf('Safari') !=-1)
            {
                if (/Safari\/(\d+\.\d+)/g.test(userAgent))var dtVersion = new Number(RegExp.$1) 
                dtBrowser = 'Safari';
            }
        }
        return function()
        {
            return {name:dtBrowser,version:parseFloat(dtVersion)};
        };
    };
    
    this.getOffset = function()
    {
        var x=y=0;
        if(window.document.documentElement && window.document.documentElement.scrollTop) 
        {
            var y =window.document.documentElement.scrollTop;
        }
        else if(window.document.body && window.document.body.scrollTop) 
        {
            var y = window.document.body.scrollTop;
        }  
        return {x:x,y:y};        
    }; 
    
    this.getSize = function()
    {
        var offsetH = document.body.offsetHeight;
        var offsetW = document.body.offsetWidth;
        var bodyH = 0;
        if(typeof(window.innerHeight) != 'undefined')
        {
            var h = (offsetH > window.innerHeight)?offsetH:window.innerHeight;
            var w = (offsetW > window.innerWidth)?offsetW:window.innerWidth;
            bodyH = window.innerHeight; 
        }
        else if(document.documentElement && document.documentElement.clientHeight) 
        {
            var h = (offsetH > document.documentElement.clientHeight)?offsetH:document.documentElement.clientHeight;
            var w = (offsetW > document.documentElement.clientWidth)?offsetW:document.documentElement.clientWidth;
            bodyH = document.documentElement.clientHeight;
        } 
        else
        {
            var el = document.body.firstChild;
            var h = parseInt(el.offsetHeight);
            var w = parseInt(el.offsetWidth); 
            var bodyH = offsetH; 
        }
        return {h:h,w:w,bodyH:bodyH}; 
    };    
    
    this.getMouseCoor = function(e)
    {
        var e = e || window.event;
        var x = y = 0;
        if (document.attachEvent != null) 
        { 
            x = e.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
            y = e.clientY + document.documentElement.scrollTop + document.body.scrollTop;
        }
        if (!document.attachEvent && document.addEventListener) 
        { 
            x = e.clientX + window.scrollX;
            y = e.clientY + window.scrollY;
        }        
        return {x:x,y:y};
    };  
    
    this.getTarget = function(e)
    {
        var e = e || window.event;
        var target = e.target || e.srcElement;
        return target;    
    };
    
    this.stopEvent = function(e)
    {
        var event = e || window.event;
         if (event.stopPropagation) 
         {
            event.stopPropagation();
        } 
        else 
        {
            event.cancelBubble = true;
        } 
    };  

    this.preventEvent = function(e)
    {
        var event = e || window.event;
         if (event.preventDefault) 
         {    
             event.preventDefault()
        }
         else
         {
             event.returnValue= false;
         } 
    };  
    
    this.load = function(url,callback,chkObj)
    {
        //console.profile();
        if(typeof(url)=='array'||typeof(url)=='object')
        {
            var i = 0;
            while(i<url.length)
            {
                this.load(url[i],'','');
                i++;
            }
        }
        else
        {
            var browser = that.getBrowser().name;
            if(typeof(callback)=='undefined')callback='';
            if(typeof(chkObj)=='undefined')chkObj='';
            var type=url.substr(url.length-3,url.length);
            var sr=url.replace(/\//g,'\\/');
            var sr1Arr=sr.split('\\\/');
            var sr2Arr=sr1Arr[sr1Arr.length-1].split('.');
            var sr1=sr2Arr[0];
            var currScript=sr2Arr[0];
            var splSr1=sr1.split('-');
            var sr1L=splSr1[splSr1.length-1];
            var sr2=sr2Arr[1];
            var cachedScript=sr1.replace('-'+sr1L,'');
            if(type=='.js')
            {
                var script=document.createElement("script");
                script.type="text/javascript";
                script.src=url;
                var reg=new RegExp('src=.+'+currScript+'\.js|src=.+'+cachedScript+'\.js','g');
                var chkStr=reg.test(that.getByTag('html')[0].innerHTML);
            }
            else if(type=='css')
            {
                var script=document.createElement("link");
                script.href=url;script.rel='stylesheet';
                script.type="text/css";
                script.media='screen';
                var reg=new RegExp('href=.+'+currScript+'\.css|href=.+'+cachedScript+'\.css','g');
                var chkStr=reg.test(that.getByTag('html')[0].innerHTML);
            }
            function doInclude()
            {
                if(chkStr!=false)
                {
                    if(typeof(callback)=='function')callback();
                }
                else
                {
                    if(browser == 'IE')
                    {
                        script.onreadystatechange=function()
                        {
                            if(script.readyState=="loaded"||script.readyState=="complete")
                            {
                                script.onreadystatechange=null;
                                if(typeof(callback)=='function')callback();
                            }
                        }
                    }
                    else
                    {
                        script.onload=function()
                        {
                            if(typeof(callback)=='function')callback();
                        }
                    }
                    that.getByTag("head")[0].appendChild(script);
                }
            };
            if(chkObj.length!=0)
            {
                try
                {
                    if(typeof(eval(chkObj))==='object'||typeof(eval(chkObj))==='function')
                    {
                        if(browser == 'IE'  && chkStr==false)
                        {
                            setTimeout(function(){doInclude()},100);
                        }
                        else
                        {
                            doInclude();
                        }
                    }
                }
                catch(e)
                {
                    setTimeout(function(){this.load(url,callback,chkObj)},100);
                }
            }
            else
            {
                if(browser == 'IE' &&chkStr==false)
                {
                    setTimeout(function(){doInclude()},100);
                }
                else
                {
                    doInclude();
                }
            }
        }
        //console.profileEnd();
    };
    
    this.loader = function()
    {
        var that = this;
        this.wrapper = 'shadowBox';
        this.localDiv = 'Your Div Id';
        this.loaderDiv = 'loadingBox';
        this.position = 'position'; 
        this.oldResize = window.onresize;
        this.width = 0;
        this.height = 0;
        this.content = '';
        
        this.close = function()
        {
            if(dl$(this.wrapper))dl$(this.wrapper).parentNode.removeChild(dl$(this.wrapper));
            if(dl$(this.loaderDiv))dl$(this.loaderDiv).parentNode.removeChild(dl$(this.loaderDiv));
            document.body.style.overflow = 'auto';
            window.onresize = this.oldResize;    
        };
        
        this.init = function(params)
        {
            this.position = (typeof(params.position) != 'undefined')?params.position:'global';
            if(typeof(params.loaderId) != 'undefined') this.loaderDiv = params.loaderId;
            if(typeof(params.localDiv) != 'undefined') this.localDiv = params.localDiv;
            if(typeof(params.wrapperId) != 'undefined') this.wrapper = params.wrapperId;
            if(typeof(params.content) != 'undefined') this.content = (typeof(params.content) == 'object')?params.content.innerHTML:params.content;
            if(!dl$(this.wrapper))
            {
                var boxDiv = document.createElement('div');
                boxDiv.setAttribute('id',this.wrapper);
                document.body.appendChild(boxDiv);
            }
            dl$(this.wrapper).style.height = this.getSize().h+'px';
            
            if(!dl$(this.loaderDiv))
            {
                var loadinDiv = document.createElement('div');
                loadinDiv.setAttribute('id',this.loaderDiv);
                document.body.appendChild(loadinDiv);
            }
            this.width = dl$(this.loaderDiv).offsetWidth;
            this.height = dl$(this.loaderDiv).offsetHeight;
     
            if(this.position == 'local' && dl$(this.localDiv))
            {
                var divSW = dl$(this.localDiv).offsetWidth;
                var divSH = dl$(this.localDiv).offsetHeight; 
                var posX = that.getPosition(dl$(this.localDiv)).x;
                var posY = that.getPosition(dl$(this.localDiv)).y; 
                dl$(this.wrapper).style.width = divSW+'px';
                dl$(this.wrapper).style.height = divSH+'px';
                dl$(this.wrapper).style.left = posX +'px';
                dl$(this.wrapper).style.top = posY +'px';
                dl$(this.loaderDiv).style.left = posX + (divSW/2) - (this.width/2) + 'px';
                dl$(this.loaderDiv).style.top =  posY + (divSH/2) - (this.height/2) + 'px';
                if(this.content != '') dl$(this.loaderDiv).innerHTML = this.content; 
            }
            else
            {
                this.globalLoader();
                window.onresize = function()
                {
                    that.globalLoader();
                };
            }
        };
        
        this.globalLoader = function()
        {
            document.body.style.overflow = 'hidden';
            var shadowW = this.getSize().w;
            var shadowH = this.getSize().bodyH;      
            dl$(this.loaderDiv).style.left = ((shadowW/2)-(this.width/2)) +  'px';
            dl$(this.loaderDiv).style.top = ((shadowH/2)-(this.height/2)) + this.getOffset().y + 'px';
            if(this.content != '') dl$(this.loaderDiv).innerHTML = this.content; 
        };  
    };
    
    this.newEvent = function(el,ev,fn)
    {                          
        var element = (typeof(el)=='object')?el:dl$(el);
        var f = function(e)
        {
            return fn(e||window.event);
        };
        if(element.addEventListener)
        {
            element.addEventListener(ev, f, false);
        }
        else if (element.attachEvent)
        {
            element.attachEvent("on" + ev, f);
        }       
    };

    this.removeEvent = function(el,ev,fn)
    {
        var element = (typeof(el)=='object')?el:dl$(el); 
        if (element.removeEventListener)
        {
            element.removeEventListener(ev,fn,false);
        }
        else if(element.detachEvent)
        {
            element.detachEvent("on" + ev,fn)       
        }     
    };    
};       


var dl = new delacompa();  
dl.loader.prototype = dl;
dl.loader.prototype.constructor = dl.loader;  
var dlLoader = new dl.loader();
//console.profileEnd();

