var _layout = new Object();

_layout.IE = dojo.isIE;
_layout.IE6 = dojo.isIE==6?true:false;
_layout.userIconsType='big';

var dScroll;

_layout.seoScroll = function(direction, object) {
    if(_layout.seoScrollInterval) {
        clearInterval(_layout.seoScrollInterval);
    }
    var divs = object.offsetParent.getElementsByTagName('div');
    for(var a = 0; a<divs.length; a++) {
        if(divs[a].className=="overflowed") {
            _layout.seoScrollDiv = divs[a];
            break;
        }
    }
    if(_layout.seoScrollDiv) {
        _layout.seoScrollInterval = setInterval('_layout.seoLinksScroll('+direction+')', 25);   
    }
}

_layout.seoLinksScroll = function(direction) {
    if(_layout.seoScrollDiv) {
            if(direction) {
                _layout.seoScrollDiv.scrollTop=_layout.seoScrollDiv.scrollTop+1;
            } else {
                _layout.seoScrollDiv.scrollTop=_layout.seoScrollDiv.scrollTop-1;
            }
    }
}

_layout.seoStop = function() {
    _layout.seoScrollDiv = null;
    clearInterval(_layout.seoScrollInterval);
}

_layout.userIconsScroll = function(e) {
    if(_layout.userIconsType!='big') { return false; }
    if(!e) { var e = window.event; }

    var object = e.srcElement?e.srcElement:null;

    var userIcons = document.getElementById('userIconsBig');

    if(!userIcons) { return false; }

    var divs = userIcons.getElementsByTagName('div');

    for(var a = 0; a<divs.length; a++) {
        if(divs[a].className=="scroll") {
            var scrollDiv = divs[a];
        }
        if(divs[a].className=="icons") {
            var iconsDiv = divs[a];
        }
    }
    
    if(iconsDiv) {
        if(iconsDiv.style.top!="50%") {
            iconsDiv.style.top='50%';
            iconsDiv.style.display='block';
        }
    }

    if(scrollDiv) {
        if(scrollDiv.style.height="200%") {
            scrollDiv.style.height="200%";
        }
        var y = _layout.positionToElement(userIcons, object)[1];

        if(!object) {
            object=document.documentElement?document.documentElement:document.body;
        } else {
            if(!object.scrollTop) {
                object=document.documentElement?document.documentElement:document.body;
            }
            if(!object.scrollTop) {
                object=document.body;
            }
        }

        if(object.scrollTop>y) {
            _layout.userIconsScrollTop = (userIcons.scrollHeight/2)-object.scrollTop+y;
            if(_layout.userIconsType=='big') {
                userIcons.scrollTop=_layout.userIconsScrollTop;
            }
        } else {
            _layout.userIconsScrollTop = userIcons.scrollHeight;
            if(_layout.userIconsType=='big') {
                userIcons.scrollTop=_layout.userIconsScrollTop;
            }
        }

    }
}

_layout.userIconsMinimize = function(userid) {
    if(!_layout.userIconsSmall) {
        _layout.userIconsBig = document.getElementById('userIconsBig');
        _layout.userIconsSmall = document.getElementById('userIconsSmall');
    }

    var onSuccess = function() {
        _layout.userIconsBig.style.display='none';
        _layout.userIconsSmall.style.display='block';
    }

    _layout.userIconsInterval = setInterval('_layout.userIconsAnimation(0,'+onSuccess+')', 25);

    _layout.userIconsType = 'small';
    if(userid!=undefined) Storage.set('menu'+userid,'small');
    
}

_layout.userIconsMaximize = function(userid) {
    if(!_layout.userIconsSmall) {
        _layout.userIconsBig = document.getElementById('userIconsBig');
        _layout.userIconsSmall = document.getElementById('userIconsSmall');
    }

    var onSuccess = function() {
        _layout.userIconsBig.style.display='block';
        _layout.userIconsSmall.style.display='none';
    }

    _layout.userIconsInterval = setInterval('_layout.userIconsAnimation(1,'+onSuccess+')', 25);

    _layout.userIconsType = 'big';
    if(userid!=undefined) Storage.set('menu'+userid,'big');
}

_layout.userIconsAnimation = function(direction, onSuccess) {
    /* if(!_layout.userIconsBig) { return false; }

    if(_layout.userIconsBig.style.display!='block') {
        _layout.userIconsBig.style.display='block';
    }

    if(direction) {
        var dest = _layout.userIconsScrollTop?_layout.userIconsScrollTop:_layout.userIconsBig.offsetHeight;
        var from = 0;
    } else {
        var dest = 0;
        var from = _layout.userIconsScrollTop?_layout.userIconsScrollTop:_layout.userIconsBig.offsetHeight;
        if(!_layout.userIconsBig.scrollTop) {
            _layout.userIconsBig.scrollTop=_layout.userIconsBig.offsetHeight;
        }
    }

    var diff =  Math.round((_layout.userIconsBig.scrollTop - dest)*0.11);
	if(diff<1) { diff=1; }

    if(_layout.userIconsBig.scrollTop+diff>dest) {
        var sT = _layout.userIconsBig.scrollTop-diff;
        if(sT<=dest) {
            onSuccess();
            clearInterval(_layout.userIconsInterval);
            sT=dest;
            _layout.userIconsBig.scrollTop=sT;
            return;
        }
        _layout.userIconsBig.scrollTop=sT;
    } else  {
        var sT = _layout.userIconsBig.scrollTop+diff;

        //alert(sT + ' ' + diff + ' ' + dest);
        if(sT>=dest) {
            onSuccess();
            clearInterval(_layout.userIconsInterval);
            sT=dest;
            _layout.userIconsBig.scrollTop=sT;
            return;
        }
        _layout.userIconsBig.scrollTop=sT;
    } */

	onSuccess();
	clearInterval(_layout.userIconsInterval);
}

_layout.positionToElement = function(src, trg) {
    var vars = [src.offsetLeft, src.offsetTop];
    while(src = src.offsetParent) {
        vars[0] = vars[0]+src.offsetLeft;
        vars[1] = vars[1]+src.offsetTop;
        if(src==trg) {
            break;
        }
    }
    return vars;
}

_layout.showMenu = function(type, object) {
    if(!type) { return; }

    var m = document.getElementById('menu_'+type);

    if(!m) { return; }

    clearTimeout(this.menuTimeout);
    this.hideSelMenu();

    this.menuSelected=m;
    this.menuButton=object;

    m.onmouseover=function() {
        clearTimeout(_layout.menuTimeout);
    }

    m.onmouseout=function() {
        _layout.menuTimeout=setTimeout('_layout.hideSelMenu()', 250);
    }

    object.oldClassName=object.className;

    object.className=object.className+' selected';

    m.style.left=object.offsetLeft+'px';
    m.style.display='block';
}

_layout.hideMenu = function() {
    this.menuTimeout=setTimeout('_layout.hideSelMenu()', 250);
}

_layout.hideSelMenu = function() {
    if(this.menuSelected) {
        this.menuSelected.style.display='none';
        this.menuButton.className=this.menuButton.oldClassName;
    }
}

_layout.boxVisibility = function(object,userId,boxId) {
	var isOff = 0;
    var mF = object.offsetParent.offsetParent;
    var mFp = mF.parentNode;
    var divs = mF.getElementsByTagName('div');
    for(var a = 0; a<divs.length; a++) {
        if(divs[a].className=="frContent") {
            var mFc = divs[a];
            break;
        }
    }

    if(!mFc) { return; }

   if(mFc.offsetHeight) {
        mFc.style.display='none';
        dojo.byId('box'+boxId+'TP').style.backgroundColor = "transparent";
        isOff=1;
    } else {
        mFc.style.display='block';
        dojo.byId('box'+boxId+'TP').style.backgroundColor = dojo.byId('box'+boxId+'Content').style.backgroundColor;
    }

    if(this.IE) {
        mFp.style.display='none';
        mFp.style.display='block';
    }
	if(userId != undefined && boxId !=undefined)
	{	
		
		var boxes = Storage.get('boxes'+userId);
		if(boxes!= undefined)
		{	
			if(boxes=="" && isOff) {
				Storage.set('boxes'+userId,boxId);
				return; 
			} 
			else {
				arrBoxes = boxes.split('.');
				for(var i=0;i<arrBoxes.length;i++)
				{ 
					if(arrBoxes[i]==boxId) {
						if(!isOff) arrBoxes.splice(i,1);
						break;
					}	
				}
				if(isOff) arrBoxes.push(boxId);
				Storage.set('boxes'+userId,arrBoxes.join('.'));
				
			}
				
		}
		else 
		{
			if(isOff) Storage.set('boxes'+userId,boxId); 
		}
	}
}

_layout.userBarBoxShow = function(object, title, content, resizable, onResize) {
    if(this.userBarBoxSelected==object) {
        this.userBarBoxHide();
        this.userBarBoxSelected=null;
        return;
    }
        
    if(this.userBarBoxSelected) {
        this.userBarBoxSelected.className=this.userBarBoxSelected.oldClassName;
    }
    
    this.userBarBoxSelected = object;
    object.oldClassName=object.className;
    object.className=object.className+'_selected';

    var fB = document.getElementById('functionBox');
    if(fB == null || fB == undefined) return false;

    fB.style.top = 0;
    fB.style.left = 0;
    fB.style.width = 'auto';

    if(fB.content) {
        fB.parentNode.insertBefore(fB.content, null);
        fB.content.style.display='none';
        fB.content=null;
    }

    /* Searching for layers */

    if(!fB.titleDiv || !fB.contentDiv || !fB.resizeDiv) {
        var divs = fB.getElementsByTagName('div');

        for(var a = 0; a<divs.length; a++) {
            if(divs[a].className=="fbTitle") {
                fB.titleDiv = divs[a];
                fB.titleDivT = divs[a+1];
            }
            if(divs[a].className=="fbContent") {
                fB.containerDiv = divs[a-1];
                fB.contentDiv = divs[a];
            }
            if(divs[a].className=="fbResize") {
                fB.resizeDiv = divs[a];
            }
        }
    }

    fB.contentDiv.style.height='auto';
    

    if(!resizable) {
        if(fB.dScroll) {
            fB.dScroll.style.display='none';
        }
        fB.resizeDiv.style.display='none';
        fB.contentDiv.className='fbContent';
    } else {
        fB.resizeDiv.style.display='block';

        var onChangeFunction = function() {
            if(fB.dScroll.style.display=="none") {
                if(fB.defaultWidth) {
                    fB.style.width=fB.defaultWidth+'px';
                } else {
                    fB.style.width='auto';
                }
                fB.style.left=parseFloat(fB.style.left)+parseFloat(_layout.getStyle(fB.dScroll, 'width')) + 'px';
            } else {
                if(fB.style.width=="auto" || !fB.style.width) {
                    var w = fB.offsetWidth;
                } else {
                    var w = parseFloat(fB.style.width);
                }
                fB.style.width=w+parseFloat(_layout.getStyle(fB.dScroll, 'width')) + 'px';
                fB.style.left=parseFloat(fB.style.left)-parseFloat(_layout.getStyle(fB.dScroll, 'width')) + 'px';
            }
        }

        fB.dScroll = this.createScroll(fB.contentDiv, onChangeFunction);
    }
    
    if(title) {
        fB.titleDiv.style.display='block';
        fB.titleDivT.innerHTML=title;
    } else {
        fB.titleDiv.style.display='none';
    }

    fB.style.display='block';
    fB.style.visibility='hidden';

    if(typeof(content)=='string') {
        content = document.getElementById(content);
    }
    if(typeof(content)=='object' && content) {
        fB.contentDiv.innerHTML = '';
        fB.contentDiv.insertBefore(content, null);
        content.style.display='block';
        content.style.position='relative';
        fB.content=content;
    } else {
        fB.contentDiv.innerHTML = 'Nie ma takiego obiektu!';
    }

    if(_layout.IE) {
        var oldFCw = fB.contentDiv.offsetWidth;
        fB.contentDiv.style.display='inline';
        var fCw = fB.contentDiv.offsetWidth;
        var fBw = fB.offsetWidth;
        var fWr = fBw-oldFCw;
        fB.contentDiv.style.display='block';
        fB.style.width=fCw+fWr+'px';
        fB.defaultWidth=fCw+fWr;
    }

    var oL = object.offsetLeft;

    if(object.offsetParent.className=="functionButtons") {
        oL = this.positionToElement(object, fB.offsetParent)[0];
    }

    oL = oL - 9;

    if(oL+fB.offsetWidth>fB.offsetParent.offsetWidth) {
        oL = fB.offsetParent.offsetWidth-fB.offsetWidth;
    }

    if(oL<0) {
        oL = 0;
    }

    var oT = -(fB.offsetHeight);

    if(oT<-(fB.offsetParent.offsetTop)) {
        fB.contentDiv.style.height = fB.offsetParent.offsetTop-100+'px';
        fB.contentDiv.style.overflow = 'hidden';
        oT = -(fB.offsetHeight);
    } else {
        fB.contentDiv.style.height = 'auto';
        fB.contentDiv.style.overflow = 'hidden';
    }

    fB.style.top = oT+'px';
    fB.style.left=oL+'px';
    fB.style.visibility='visible';

    if(_layout.IE6 && !fB.content.imgReloaded) {
        var fBe = fB.getElementsByTagName('*');
        
        var images = [];
        for(var a = 0; a<fBe.length; a++) {
            var bg = _layout.getStyle(fBe[a], 'backgroundImage');
            if(bg!="none") {
                bg = bg.replace('url("', '');
                bg = bg.replace('")', '');
                if(bg) {
                    var d = new Date();
                    
                    images[a] = new Image();
                    images[a].src=bg + "?" + d.getDate();
                    images[a].content = fBe[a];

                    images[a].onload = function() {
                        var bgImg = "url('" + this.src + "')";
                        this.content.style.backgroundImage=bgImg;
                    }
                    
                }
            }
        }
        fB.content.imgReloaded = true;
        
    }
    

    /* Making stCnMn closing the userBarFunctions */
    var stCnMn = document.getElementById('stCnMn');

    if(stCnMn.onmousedown) {
        stCnMn.oldOnClick=stCnMn.onmousedown;
    }

    stCnMn.onmousedown=function() {
        _layout.userBarBoxHide();
    }
    /* End */

    if(onResize) {
        this.userBarOnResize=onResize;
    }

    if(fB.dScroll && resizable) {
        fB.dScroll.checkBarHeight(fB.dScroll.onChangeFunction);
    }
}

_layout.userBarBoxHide = function() {
    if(this.userBarBoxSelected) {
        this.userBarBoxSelected.className=this.userBarBoxSelected.oldClassName;
    }
    this.userBarBoxSelected=null;
    var fB = document.getElementById('functionBox');
    fB.style.display='none';
    if(fB.content) {
        fB.parentNode.insertBefore(fB.content, null);
        fB.content.style.display='none';
        
        fB.content=null;
    }
    if(this.userBarOnResize) {
        this.userBarOnResize=null;
    }
    if(fB.dScroll) {
        fB.dScroll.style.display='none';
    }
    /* Making stCnMn closing the userBarFunctions */
    var stCnMn = document.getElementById('stCnMn');
    stCnMn.onclick=null;
    if(stCnMn.oldOnClick) {
        stCnMn.onmousedown=stCnMn.oldOnClick;
    }
}

_layout.userBarBoxResize = function(object) {
    var fB = document.getElementById('functionBox');

    fB.contentDiv.scrollTop=0;

    this.mouseLastY = null;

    document.onmousemove=this.userBarBoxResizing;
    document.onmouseup = this.userBarBoxStopResize;

}

_layout.userBarBoxResizing = function(e) {
    var fB = document.getElementById('functionBox');
    if(!e) { e = window.event; }

    if (e.clientX) {
           tempY = e.clientY;
    } else {
           tempY = e.pageY;
    }

    if(tempY<=0) {
        document.onmousemove='';
        return;
    }

    if(this.mouseLastY) {
        var t = this.mouseLastY-tempY;
    } else {
        var t = 0;
    }

    var h = fB.contentDiv.offsetHeight+t;

    if(h<0) { return false; }

    var t = parseFloat(fB.style.top)-t;

    fB.style.top=t+'px';
    fB.contentDiv.style.height=h+'px';

    this.mouseLastY = tempY;

    if(this.userBarOnResize) {
        this.userBarOnResize();
    }

    if(fB.dScroll) {
        fB.dScroll.checkBarHeight(fB.dScroll.onChangeFunction);
    }

    return false;
}

_layout.userBarBoxStopResize = function(e) {
    document.onmousemove = null;
    this.mouseLastY=null;

    return false;
}

_layout.userBarStartButton = function(object, content) {
    this.userBarBoxShow(object, null, content);
}

_layout.userBarFriends = function(object, title, content) {
    this.userBarBoxShow(object, title, content, true);
}

_layout.userBarDescription = function(object, title, content) {
    this.userBarBoxShow(object, title, content);
}

_layout.userBarMood = function(object, title, content) {
    this.userBarBoxShow(object, title, content, true);
}

_layout.userBarNotebook = function(object, title, content) {

    var onResize = function() {
    }

    this.userBarBoxShow(object, title, content, false);
}

_layout.getStyle  = function(el,styleProp)
{  
    if(typeof(el)=='string') {
        var x = document.getElementById(el);
    } else {
        x = el;
    }
    
	if (x.currentStyle) {
		var y = x.currentStyle[styleProp];
    } else if (window.getComputedStyle) {
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
    }
	return y;
}

_layout.createScroll = function(object, onChange) {
    /* Searching for dScroll */
    var divs = object.parentNode.getElementsByTagName('div');
    
    for(var a = 0; a<divs.length; a++) {
        if(divs[a].className=="dScroll") {
            var s = divs[a];
            return s;
        }
    }
    var s = document.createElement('div');
    s.className="dScroll";
    s.onChangeFunction=onChange;

    s.checkBarHeight = function(onChange) {
        var h = object.scrollHeight;

        var el = s.getElementsByTagName('*');

        for(var a = 0; a<el.length; a++) {
            if(el[a].className=="up") {
                s.upDiv = el[a];
            }
            if(el[a].className=="down") {
                s.downDiv = el[a];
            }
            if(el[a].className=="bar") {
                s.barDiv = el[a];
            }
        }

        var l = (object.offsetHeight/h);

        if(!l) { return; }

        if(l>=1) {
            if(s.style.display=="block") {
                s.style.display='none';
                if(onChange) {
                    onChange();
                }
            }
            return;
        } else {
            if(s.style.display=="none") {
                s.style.display='block';
                if(onChange) {
                    onChange();
                }
            }
        }

        if(s.barDiv.style.height=="") {
            s.minBarHeight=s.barDiv.offsetHeight;
        }

        var p = s.downDiv.offsetTop - s.upDiv.offsetTop - s.upDiv.offsetHeight;
        var minT = s.upDiv.offsetTop + s.upDiv.offsetHeight;

        //s.contentHeight = h;
        s.contentHeight = object.scrollHeight;
        s.containerHeight = object.offsetHeight;

        var bH = p*l;
        if(bH >= s.minBarHeight) {
            s.barDiv.style.height = bH+'px';
        }

        var t = minT + Math.floor(p*(object.scrollTop/s.contentHeight));
        s.barDiv.style.top=t+'px';
    }

    s.scrollUp = function(e) {
        dScroll = s;
        clearInterval(s.scrollInterval);
        s.scrollInterval = setInterval('dScroll.scrollObject(1)', 25);
    }

    s.scrollDown = function(e) {
        dScroll = s;
        clearInterval(s.scrollInterval);
        s.scrollInterval = setInterval('dScroll.scrollObject(0)', 25);
    }

    s.scrollClear = function(e) {
        clearInterval(s.scrollInterval);
    }

    s.scrollObject = function(direction) {
        var p = s.downDiv.offsetTop - s.upDiv.offsetTop - s.upDiv.offsetHeight;
        var minT = s.upDiv.offsetTop + s.upDiv.offsetHeight;
        var maxT = s.downDiv.offsetTop;

        var l = (object.scrollTop/s.contentHeight);

        if(direction) {
            this.scrolledObject.scrollTop=this.scrolledObject.scrollTop-10;
        } else {
            this.scrolledObject.scrollTop=this.scrolledObject.scrollTop+10;
        }

        var t = minT + Math.floor(p*l);
        s.barDiv.style.top = t+'px';
    }

    s.scrollBarMove = function() {
        document.onmousemove=s.scrollBarMoveing;
        document.onmouseup=s.scrollBarClear;
        return false;
    }

    s.scrollBarMoveing = function(e) {
        if(!e) { e = window.event; }

        if (e.clientX) {
           var tempY = e.clientY;
        } else {
           var tempY = e.pageY;
        }

        if(s.mouseBarY) {
            var sR = tempY - s.mouseBarY;
        } else {
            var sR = 0;
        }

        var p = s.downDiv.offsetTop - s.upDiv.offsetTop;
        var minT = s.upDiv.offsetTop + s.upDiv.offsetHeight;
        var maxT = s.downDiv.offsetTop-s.barDiv.offsetHeight;

        var l = (object.scrollTop/s.contentHeight);

        var t = parseFloat(s.barDiv.style.top)+sR;

        if(t<=minT) {
            t=minT;
        }


        if(t>=maxT) {
            t=maxT;
        }

        s.barDiv.style.top=t+'px';

        s.mouseBarY = tempY;

        var wW = (t-minT)/(maxT-minT);

        sT = Math.round((s.contentHeight-s.scrolledObject.offsetHeight)*wW);

        fB = document.getElementById('functionBox');

        s.scrolledObject.scrollTop = sT;
        
        return false;
    }

    s.scrollBarClear = function(e) {
        document.onmousemove='';
        document.onmouseup='';
        s.mouseBarY = false;
    }
    
    var a1 = document.createElement('a');
    a1.className='up';
    a1.href="javascript:void(0)";
    a1.onmousedown=s.scrollUp;
    a1.onmouseup=s.scrollClear;

    var a2 = document.createElement('a');
    a2.className='down';
    a2.href="javascript:void(0)";
    a2.onmousedown=s.scrollDown;
    a2.onmouseup=s.scrollClear;

    var a3 = document.createElement('a');
    a3.className='bar';
    a3.href="javascript:void(0)";
    a3.onmousedown=s.scrollBarMove;
    s.scrollBarDiv = a3;
    
    s.appendChild(a1);
    s.appendChild(a2);
    s.appendChild(a3);

    object.parentNode.appendChild(s);

    s.scrolledObject = object;

    s.style.display='none';

    return s;
}

_layout.screenResize = function() {
    _layout.userBarBoxHide();
}

_layout.initialize = function() {
    if(_layout.IE6) {
        _layout.ieBgFix();
    }
}

_layout.ieBgFix = function() {
    var stCnMn = document.getElementById('stCnMn');
    var stCn = document.getElementById('stCn');
    var ieBg = document.getElementById('ieBg');

    var fD = document.createElement('div');

    var oH = stCnMn.scrollHeight;

    var i = Math.round(oH/512);

    for(var a = 0; a<i; a++) {
        var bg1 = document.createElement('div');
        bg1.className='bgPng';
        
        bg1.style.marginTop = '-60px';
        bg1.id='bgPng'+a;
        bg1.style.height=Math.round(100/i)+1+'%';
        bg1.style.top=a*(Math.round(100/i)+1)+'%';

        var wW = document.getElementById('wdCheck').offsetWidth;

        if(wW>1536) {
            bg1.style.width=wW+'px';
            bg1.style.left=0;
            bg1.style.marginLeft = 0;
        }

        ieBg.appendChild(bg1);
        
    }

}

_layout.ieBgFixOld = function () {
    var bgPng = document.getElementById('bgPng');
    var stTop = document.getElementById('stTop');
    bgPng.style.background='none';

    var oH = bgPng.offsetHeight+stTop.offsetHeight;

    var i = Math.round(oH/512);

    for(var a = 0; a<i; a++) {
        var bg1 = document.createElement('div');
        bg1.className='bgPngIE';
        bg1.style.top=a*512+'px';

        if(bgPng.offsetWidth>1536) {
            bg1.style.width='100%';
            bg1.style.marginLeft=0;
            bg1.style.left=0;
        }

        bgPng.appendChild(bg1);
    }

}


_layout.textAreaLimit = function(object, limit, countObject) {
    if(typeof(countObject)=="string") {
        countObject = document.getElementById(countObject);
    }

    if(object.value.length>limit) {
        object.value=object.value.substr(0, limit);
    }

    countObject.innerHTML = limit-object.value.length;
    
    return false;
}

_layout.onlyNumeric = function(e, object) {
    /* if(!e) { e = window.event; } */

    var chr = e.keyCode;

    if(!chr) { chr=e.which; }

    if((chr>=48 && chr<=57) || chr==8 || chr==9 || chr==37 || chr==46 || chr==116) {
        return true;
    } else {
        return false;
    }
}

_layout.checkBoxBg = function(object, className) {
    if(object.checked) {
        object.parentNode.className=className + ' ' + className + '_selected';
    } else {
        object.parentNode.className=className;
    }
}

_layout.checkBoxBgAll = function(object, check, className) {
    if(typeof(object)=='string') {
        object = document.getElementById(object);
    }
    
    if(!object) { return; }

    var i = object.getElementsByTagName('input');

    for(var a = 0; a<i.length; a++) {
        if(i[a].type=="checkbox") {
            if(check) {
                i[a].checked=1;
            } else {
                i[a].checked=0;
            }
            if(!className) {
                className = i[a].parentNode.className;
            }
            this.checkBoxBg(i[a], className);
        }
    }
}

_layout.printPng = function(image_src,w,h,title,cssClassName){
	_title=(title==undefined||title=='')?'':'title="'+title+'"';
	_css=(cssClassName==undefined||cssClassName=='')?'':'class="'+cssClassName+'"';
	if(_layout.IE6){
		image_text='<span '+_title+' '+_css+' style="width: '+w+'px; height: '+h+'px; display:inline-block; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+image_src+'\', sizingMethod=\'scale\')"></span>'
		document.write(image_text);
	}else{
		document.write('<img src="'+image_src+'" width="'+w+'" height="'+h+'" '+_title+' '+_css+' />');
	}
}

_layout.minimalizeBoxes = function(userId)
{	
	//Storage.del('boxes'+userId);
	var boxes = Storage.get('boxes'+userId);
	if(boxes!= undefined && boxes!="")
	{	
		arrBoxes = boxes.split('.');
		for(var i=0;i<arrBoxes.length;i++)
		{ 
			//console.debug('box'+arrBoxes[i]+'Content');
			if(document.getElementById('box'+arrBoxes[i]+'Content')) {
				document.getElementById('box'+arrBoxes[i]+'Content').style.display='none';
				dojo.byId('box'+arrBoxes[i]+'TP').style.backgroundColor = "transparent";
			}
		}
	} 
}

_layout.setMenuLocation = function(userid)
{
	if(userid!=undefined) var mm = Storage.get('menu'+userid);
    if(mm=='small') {
    	document.getElementById('userIconsBig').style.display="none";
        document.getElementById('userIconsSmall').style.display="block";
    }
    else 
    {
    	document.getElementById('userIconsBig').style.display="block";
        document.getElementById('userIconsSmall').style.display="none";
    }
}

_layout.userLargePhoto = function(e) {
    if(!e) { e = window.event; }

    

    var src = e.srcElement?e.srcElement:e.target;

    if(!src) { return; }

    var o = document.getElementById('userLP');
    var stCnMn = document.getElementById('stCnMn');

    if(!o) {
        var o = document.createElement('img');
        o.id="userLP";
        o.style.border='1px solid #000';
        o.style.background='#444444';
        o.style.display='none';
        o.style.position = 'absolute';
        o.style.top = 0;
        o.style.left = 0;
        o.style.width='100px';
        o.style.height='140px';
        o.style.zIndex=999;
        stCnMn.appendChild(o);
    }

    if(src.getAttribute('nolarge')) {
            return;
        }

    if(src.nodeName=="A") {
        if(src.href.indexOf('/p/')>-1) {
            link_s=src.href.split('/');
			id=link_s[5];
			dir_id=id-(id%1000);
			dir_id=dir_id/1000+'/';
			link_s='http://img2.epuls.pl/members/photo/'+dir_id+id+'_b.jpg';
                        o.src='';
                        o.src=link_s;
                        o.style.display='block';

                        var stTop = document.getElementById('stTop');

                        if(e.pageX) {
                            var scrL = stCnMn.scrollLeft?stCnMn.scrollLeft:0;
                            var scrT = stCnMn.scrollTop?stCnMn.scrollTop:0;
                            var x = e.pageX+scrL;
                            var y = e.pageY+scrT;
                            
                        } else {
                            var scrL = stCnMn.scrollLeft?stCnMn.scrollLeft:document.getElementsByTagName('html')[0].scrollLeft;
                            var scrT = stCnMn.scrollTop?stCnMn.scrollTop:document.getElementsByTagName('html')[0].scrollTop;
                            var x = e.clientX + scrL;
                            var y = e.clientY + scrT;
                        }

                        if(stTop) {
                            var oldY = y;
                            y = y - stTop.offsetHeight;

                        }

                        o.style.top=y + 10 + 'px';
                        o.style.left=x + 10+ 'px';

                        src.onmouseout = function() {
                            o.style.display='none';
                            document.onmousemove=null;
                            this.sel=0;
                        }

                        src.sel=1;

                        document.onmousemove = function(e) {
                            var o = document.getElementById('userLP');
                            var stCnMn = document.getElementById('stCnMn');
                            if(!e) { e = window.event; }

                            var src = e.srcElement?e.srcElement:e.target;

                            var stTop = document.getElementById('stTop');

                            if(!src) { return; }

                            if(e.pageX) {
                                var scrL = stCnMn.scrollLeft?stCnMn.scrollLeft:0;
                            var scrT = stCnMn.scrollTop?stCnMn.scrollTop:0;
                            var x = e.pageX+scrL;
                            var y = e.pageY+scrT;
                            } else {
                                var scrL = stCnMn.scrollLeft?stCnMn.scrollLeft:document.getElementsByTagName('html')[0].scrollLeft;
                            var scrT = stCnMn.scrollTop?stCnMn.scrollTop:document.getElementsByTagName('html')[0].scrollTop;
                            var x = e.clientX + scrL;
                            var y = e.clientY + scrT;
                            }

                            if(stTop) {
                            var oldY = y;
                            y = y - stTop.offsetHeight;

                        }

                            o.style.top=y+10+'px';
                            o.style.left=x+10+'px';
                        }

                        return false;
        }
    }

    if(src.nodeName=="IMG") {
        var link = new String(src.src);
        
        if(link.indexOf('members/photo')!=-1 || link.indexOf('lay/avatars')!=-1){
                        link_s=link.replace(/_s/g,"_b");
                        if(src.width>=100) { return true; }
                        o.src='';
                        o.src=link_s;
                        o.style.display='block';


                        var stTop = document.getElementById('stTop');

                        if(e.pageX) {
                            var scrL = stCnMn.scrollLeft?stCnMn.scrollLeft:0;
                            var scrT = stCnMn.scrollTop?stCnMn.scrollTop:0;
                            var x = e.pageX+scrL;
                            var y = e.pageY+scrT;
                        } else {
                            var scrL = stCnMn.scrollLeft?stCnMn.scrollLeft:document.getElementsByTagName('html')[0].scrollLeft;
                            var scrT = stCnMn.scrollTop?stCnMn.scrollTop:document.getElementsByTagName('html')[0].scrollTop;
                            var x = e.clientX + scrL;
                            var y = e.clientY + scrT;
                        }


                        if(stTop) {
                            var oldY = y;
                            y = y - stTop.offsetHeight;
                        }


                        o.style.top=y + 10 + 'px';
                        o.style.left=x + 10+ 'px';

                        src.onmouseout = function() {
                            o.style.display='none';
                            document.onmousemove=null;
                        }


                        document.onmousemove = function(e) {
                            var o = document.getElementById('userLP');
                            var stCnMn = document.getElementById('stCnMn');
                            if(!e) { e = window.event; }

                            var stTop = document.getElementById('stTop');

                            if(e.pageX) {
                                var scrL = stCnMn.scrollLeft?stCnMn.scrollLeft:0;
                            var scrT = stCnMn.scrollTop?stCnMn.scrollTop:0;
                            var x = e.pageX+scrL;
                            var y = e.pageY+scrT;
                                
                            } else {
                                var scrL = stCnMn.scrollLeft?stCnMn.scrollLeft:document.getElementsByTagName('html')[0].scrollLeft;
                            var scrT = stCnMn.scrollTop?stCnMn.scrollTop:document.getElementsByTagName('html')[0].scrollTop;
                            var x = e.clientX + scrL;
                            var y = e.clientY + scrT;
                            }

                            if(stTop) {
                                var oldY = y;
                                y = y - stTop.offsetHeight;
                            }
                            
                            o.style.top=y+10+'px';
                            o.style.left=x+10+'px';
                        }

                        return false;
        } else {
            document.onmousemove=null;
        }

    }
}

_layout.changeBgColor = function(object, color) {
    var stCnMn = document.getElementById('stCnMn');
    var cB = document.getElementById('colorBlock');

    if(stCnMn) {
        document.body.style.background=color;
        cB.style.backgroundColor=color;
        document.cookie = 'epBgColor=""; expires=Fri, 29 Aug 1999 20:47:11 UTC; path=/;';
        document.cookie = 'epBgColor='+color+'; domain=.epuls.pl; path=/; expires=Fri, 29 Aug 2029 20:47:11 UTC';
    }

    _layout.colorPickerObject = object;
}

_layout.showMainCP = function(object) {
    var mC = document.getElementById('mainColorPicker');

    var stCnMn = document.getElementById('stCnMn');
    var stTop = document.getElementById('stTop');

    if(!mC.showed) {
        mC.style.height='auto';
        mC.style.visibility='visible';

        stCnMn.onclick=function() {
            _layout.showMainCP();
        };

        if(stTop) {
            /* stTop.onclick=function() {
                _layout.showMainCP();
            }; */
        }

        mC.showed=1;
    } else {
        mC.style.height='1px';
        mC.style.visibility='hidden';

        stCnMn.onclick=null;

        if(stTop) {
            stTop.onclick=null;
        }

        mC.showed=0;
    }
}

_layout.changeCp = function(color) {
    var mC = document.getElementById('mnCp');

    mC.value=color;
    
    if(_layout.colorPickerObject) {
        _layout.colorPickerObject.value=color;
        _layout.colorPickerObject.startup();
    }
}

_layout.moods = true;
_layout.loadMoods = function(obj) {
	if(_layout.moods) {
		var target = dojo.byId("functionsAjaxMood");
		var orig = dojo.byId("functionsMood");
		var xhrArgs = {
			url: "/6/service/home/moods",
			handleAs: "text",
			load: function(data){
				_layout.userBarBoxHide();
				_layout.userBarBoxSelected=null;
				target.innerHTML = data;
				orig.innerHTML = data;
				_layout.moods = false;
				_layout.userBarMood(obj, 'Ustaw nastrój', 'functionsAjaxMood');
			},
			error: function(error){
			target.innerHTML = "An unexpected error occurred: " + error;
			}
	    }
		dojo.xhrGet(xhrArgs);
	}
}
_layout.loadMoodsOld = function(obj) {
	if(_layout.friends) {
		var target = dojo.byId("functionsAjaxMood");
		var orig = dojo.byId("functionsMood");
		var req = mint.Request();
		req.method = "GET";
		req.AddParam("mint", 1);
		req.OnSuccess = function()
		{
			_layout.userBarBoxHide();
			_layout.userBarBoxSelected=null;
			target.innerHTML = this.responseText;
			orig.innerHTML = this.responseText;
			_layout.moods = false;
			_layout.userBarMood(obj, 'Ustaw nastrój', 'functionsAjaxMood');
		}
		req.Send('/6/service/home/moods');
	}
}

_layout.friends = true;
_layout.loadFriends = function(obj) {
	if(_layout.friends) {
		var target = dojo.byId("functionsAjaxFriends");
		var orig = dojo.byId("functionsFriends");
		var xhrArgs = {
			url: "/6/service/home/friends",
			handleAs: "text",
			load: function(data){
				_layout.userBarBoxHide();
				_layout.userBarBoxSelected=null;
				target.innerHTML = data;
				orig.innerHTML = data;
				_layout.friends = false;
				_layout.userBarFriends(obj, 'Kumple online', 'functionsAjaxFriends');
			},
			error: function(error){
			target.innerHTML = "An unexpected error occurred: " + error;
			}
	    }
		dojo.xhrGet(xhrArgs);
	}
}
_layout.loadFriendsOld = function(obj) {
	if(_layout.friends) {
		var target = dojo.byId("functionsAjaxFriends");
		var orig = dojo.byId("functionsFriends");
		var req = mint.Request();
		req.method = "GET";
		req.AddParam("mint", 1);
		req.OnSuccess = function()
		{
			_layout.userBarBoxHide();
			_layout.userBarBoxSelected=null;
			target.innerHTML = this.responseText;
			orig.innerHTML = this.responseText;
			_layout.friends = false;
			_layout.userBarFriends(obj, 'Kumple online', 'functionsAjaxFriends');
		}
		req.Send('/6/service/home/friends');
	}
}

_layout.showFtTags = function(object, cat) {
    var c = document.getElementById('ft_'+cat);

     if(_layout.seoTagSelected!=c) {
        _layout.hideFtTags();
        clearTimeout(_layout.seoTagTimeout);
    }

    if(c && object) {
        c.style.visibility='hidden';
        c.style.display='block';

        var dd = c.getElementsByTagName('div');

        for(var a = 0; a<dd.length; a++) {
            if(dd[a].className=="arr") {
                var arr = dd[a];
                break;
            }
        }

        var op = _layout.positionToElement(object, null);
        var cp = _layout.positionToElement(c.offsetParent, null);

        var t = op[1]-cp[1]-c.offsetHeight;
        var arl = op[0]-cp[0];

        c.style.top=t+'px';
        arr.style.left=arl+'px';
        
        c.style.visibility='visible';

        _layout.seoTagSelected = c;

        c.onmouseover = function() {
            clearTimeout(_layout.seoTagTimeout);
        }

        c.onmouseout = function() {
            _layout.seoTagTimeout=setTimeout('_layout.hideFtTags()', 100);
        }

        object.onmouseout = function() {
            _layout.seoTagTimeout=setTimeout('_layout.hideFtTags()', 100);
        }
    }
}

_layout.hideFtTags = function() {
    if(_layout.seoTagSelected) {
        _layout.seoTagSelected.style.display='none';
    }
}

_layout.setBackgroundFile = function(input) {
    if(_layout.changeBgTimeout) {
        clearTimeout(_layout.changeBgTimeout);
    }
    var url=input.value;
    _layout.changeBgTimeout=setTimeout('_layout.changeBackgroundFile("'+url+'")', 500);
}

_layout.changeBackgroundFile = function(url) {
    var oldBg = document.getElementById('bgDiv');
    var bg = oldBg?oldBg:document.getElementById('stCnMn');
    var cB = document.getElementById('colorBlock');

    if(!url) {
        bg.style.backgroundImage='';
        cB.style.backgroundImage='';
        document.cookie = 'epBgFile=; domain=.epuls.pl; path=/; expires=Fri, 29 Aug 2029 20:47:11 UTC';
        return;
    }

    var pl = dojo.query('#mainColorPicker .preload_file');
    pl[0].style.visibility='visible';
    if(url.indexOf('http://')!=-1 && url.indexOf('http://')<1) {
        
        var img = new Image();
        img.onload=function() {
            bg.style.backgroundImage='url('+url+')';
            bg.style.backgroundPosition='50% 0';
            cB.style.backgroundImage='url('+url+')';
            cB.style.backgroundPosition='50% 50%';
            pl[0].style.visibility='hidden';
            document.cookie = 'epBgFile='+url+'; domain=.epuls.pl; path=/; expires=Fri, 29 Aug 2029 20:47:11 UTC';
        }
        img.onerror=function() {
            bg.style.backgroundImage='';
            cB.style.backgroundImage='';
            pl[0].style.visibility='hidden';
            document.cookie = 'epBgFile=; domain=.epuls.pl; path=/; expires=Fri, 29 Aug 2029 20:47:11 UTC';
        }
        img.src = url;
    }
}


_layout.showBackgroundFile = function(object) {
    var fd = dojo.query('#mainColorPicker .file');
    if(fd[0].style.display=="block") {
        fd[0].style.display='none';
        object.className='';
    } else {
        fd[0].style.display='block';
        object.className='selected';
    }
}

_layout.showLoginForm = function() {
    var lF = document.getElementById('loginFormDiv');
    var logF = document.getElementById('loggedDiv');
    var logIc = document.getElementById('loginIcons');
    var fL = document.getElementById('formLogin');

    if(logIc) { logIc.style.display="none"; }
    logF.style.display="none";
    lF.style.display="block";

    fL.strUserLogin.focus();
    
}