
var currentPopup=false;
window.windowloaded=false;


function clickcomponentobject(sid) {
    if(window.activecomponent) {
        window.activecomponent.style.display='none';
    }
    window.activecomponent=document.getElementById(sid);
    window.activecomponent.style.display='';
}
function clickHeadLine(object) {
    if(!window.initReady) return;
    window.newactiveheadline=document.getElementById(object.id.replace('line','text'));
    if(window.newactiveheadline==window.activeheadline) {
        /*window.activeheadline.style.display='none';
        window.activeheadline=false;*/
        return; 
    }  
    if(window.activeheadline) {
        window.activeheadline.style.display='none';
    }
    window.activeheadline=window.newactiveheadline;
    window.activeheadline.style.display='';
}
function clickCalendarobject(object,e) {
    if(!window.initReady) return;
    showPopup('modules/components/minicontainer_calendar/popup.php?date='+object.id,e);
}
function initPicturecomponentRandom(elem) {
    window.rpicElem=elem;
    window.rpicElem.style.position="relative";
    window.rpicStartOffsetX=window.rpicElem.offsetLeft;
    if(!window.rpicCurrent)  window.rpicCurrent=0;

    if(window.rpicElem.firstChild.childNodes.length>0){
        window.rpics=new Array(window.rpicElem.firstChild.childNodes.length);
        window.rpicsObjs=new Array(window.rpicElem.firstChild.childNodes.length);
        for(var i=0;i<window.rpicElem.firstChild.childNodes.length;i++) {
            window.rpics[i]=window.rpicElem.firstChild.childNodes[i].offsetWidth;
            window.rpicsObjs[i]=window.rpicElem.firstChild.childNodes[i];
        }
    }
}
function picturecomponentClick(page,objid,nr,e) {
    if(!window.initReady) return;
    if(!e) e=event;
    px=isIE?e.clientX:e.pageX;
//    showPopup("components/pictures/picdetail.php?id=" + nr,e,false,true);
    top.location="?id="+page+"&img_id="+nr+"#object"+objid;
}
function picturecomponentRandomMDown(e) {
    if(window.disableDragRandom) return;
    if(!window.initReady||!isIE) return;

    window.rpicStartPos=isIE?e.clientX:e.pageX;
    window.rpicNewX=0;
    document.onmousemove=function(e) {
        window.rpicMovePos=isIE?event.clientX:e.pageX;
        window.rpicNewX=(window.rpicMovePos - window.rpicStartPos); /*ging de muis naar links of rechts (window.rpicNewX<0 is naar links en zorgt voor een volgend plaatje, window.rpicNewX>0 is naar rechts en zorgt voor vorig plaatje)*/

        /*vorige of volgende lanceren */
        if(window.rpicNewX<0) randomVolgende();
        if(window.rpicNewX>0) randomVorige(); 

        document.onmousemove=null;
    }
    document.onmouseup=function(e) {
        document.onmousemove=null;
    }
}

function randomVolgende() {
    if(!window.initReady) return;
    if(!window.rpicElem) return;
    if(window.isGoing) return;
    window.isGoing=true;

    if(!window.rpicElem.style.left)window.rpicElem.style.left=0;
    window.rpicStartOffsetX=parseInt(window.rpicElem.style.left);

    /*bijna bij het einde... haal nieuwe*/
    if(!window.minimumRpics) window.minimumRpics=1;
    while(window.rpicCurrent>=window.rpics.length-window.minimumRpics) {
        firstImg=window.rpicElem.firstChild.firstChild;
        /*haal eerste weg als er meer dan window.maximumRpics plaatjes zijn*/
        if(window.rpics.length>=window.maximumRpics) {
            /*****Door verwijderen aan voorkant moet alles opschuiven*****/
                /*container uitlijnen*/
                window.rpicElem.style.left=window.rpicStartOffsetX + firstImg.offsetWidth;
                /*nieuwe start van container*/
                window.rpicStartOffsetX=window.rpicElem.offsetLeft;
                /*huidige plaats schuift een op*/
                window.rpicCurrent--; 

            /*verwijder*/
            window.rpicElem.firstChild.removeChild(firstImg);

            /*breedtes aanpassen*/
            window.rpics.shift();
            window.rpicsObjs.shift();

       }

        /*maak nieuwe*/
        var newimg=firstImg.cloneNode(true);
        newimg.setAttribute("onload","");
        newimg.onload=function(){};
        newimg.setAttribute("width","");
        newimg.setAttribute("height",firstImg.getAttribute("height"));
        iim=rpc(WEBSITE_HTTP+"modules/components/pictures/getrandompic.php");
        newimg.src=iim.split(",")[0];
        newimg.className=newimg.className.split(" ")[0] +" "+ iim.split(",")[1] +" "+ iim.split(",")[2] +" "+ iim.split(",")[3];

        //newimg.setAttribute("width","picturecomponentClick('"+newimg.src+"',event);");
        if(isIE) newimg.removeAttribute("width");

        /*voeg nieuwe toe*/
        window.rpicElem.firstChild.appendChild(newimg);

        /*breedtes aanpassen*/
        window.rpics.push(newimg.offsetWidth);
        window.rpicsObjs.push(newimg);
        /*clear mem*/
        firstImg=null;
    }

    window.rpicCurrent++; 

    top.runner.clear();
    top.runner.onready=function(r) {
        window.isGoing=false;
        window.rpicElem.style.left=window.rpicStartOffsetX - (window.rpicsObjs[window.rpicCurrent - 1].offsetWidth);
    }
    top.runner.addFunction(function(r) {
        var x=window.rpicStartOffsetX - (window.rpicsObjs[window.rpicCurrent - 1].offsetWidth / r.steps * r.step);
        if(x) window.rpicElem.style.left=x;
    });
    top.runner.start(window.rpicsObjs[window.rpicCurrent - 1].offsetWidth/10,26,true);
}
function randomVorige() {
    if(!window.initReady) return;
    if(window.isGoing) return;
    window.isGoing=true;
    if(!window.rpicElem.style.left)window.rpicElem.style.left=0;
    window.rpicStartOffsetX=parseInt(window.rpicElem.style.left);

    /*bij het begin... haal nieuwe*/
    if(window.rpicCurrent==0) {
        lastImg=window.rpicElem.firstChild.lastChild;
        /*haal eerste weg als er meer dan window.maximumRpics plaatjes zijn*/
        if(window.rpics.length>=window.maximumRpics) {

            /*verwijder*/
            window.rpicElem.firstChild.removeChild(lastImg);

            /*breedtes aanpassen*/
            window.rpics.pop();
            window.rpicsObjs.pop();
        }

        /*maak nieuwe*/
        newimg=lastImg.cloneNode(true);
        newimg.setAttribute("onload","");
        newimg.onload=function(){};
        iim=rpc(WEBSITE_HTTP+"modules/components/pictures/getrandompic.php");
        newimg.src=iim.split(",")[0];
        newimg.className=newimg.className.split(" ")[0] +" "+ iim.split(",")[1];

        //newimg.setAttribute("width","picturecomponentClick('"+newimg.src+"',event);");
        if(isIE) newimg.removeAttribute("width");

        /*voeg nieuwe toe*/
        window.rpicElem.firstChild.insertBefore(newimg,window.rpicElem.firstChild.firstChild);


        /*****Door nieuwe aan voorkant moet alles opschuiven*****/
            /*container uitlijnen*/
            window.rpicElem.style.left=window.rpicStartOffsetX - newimg.offsetWidth;
            /*nieuwe start van container*/
            window.rpicStartOffsetX=window.rpicElem.offsetLeft;
            /*huidige plaats schuift een op*/
            window.rpicCurrent++; 

        /*breedtes aanpassen*/
        window.rpics.unshift(newimg.offsetWidth);
        window.rpicsObjs.unshift(newimg);
        /*clear mem*/
        lastImg=null;
    }

    window.rpicCurrent--; 

    top.runner.clear();
    top.runner.onready=function(r) {
        window.isGoing=false;
        window.rpicElem.style.left=window.rpicStartOffsetX + (window.rpicsObjs[window.rpicCurrent].offsetWidth);
    }
    top.runner.addFunction(function(r) {
        window.rpicElem.style.left=window.rpicStartOffsetX + (window.rpicsObjs[window.rpicCurrent].offsetWidth / r.steps * r.step);
    });
    top.runner.start(window.rpicsObjs[window.rpicCurrent].offsetWidth/10,26,true);
}
function picturecomponentTopMOver(elem) {
    if(!window.initReady) return;
    cont=elem.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
    elem.style.width=elem.offsetWidth + elem.offsetWidth/4;
    elem.style.height=elem.offsetHeight + elem.offsetHeight/4;
    cont.style.zIndex="10";
}
function picturecomponentTopMOut(elem) {
    if(!window.initReady) return;
    cont=elem.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
    elem.style.width=elem.offsetWidth - elem.offsetWidth/5;
    elem.style.height=elem.offsetHeight - elem.offsetHeight/5;
    cont.style.zIndex="";
}
function setSelectstart() {
    if(top.location.href.toString().split("admin").length>1) return false;
    if(isIE) {
        try { document.execCommand('BackgroundImageCache', false, true);} catch(e) {};
        document.body.onselectstart=function() {
            return false;
        }
    }
    else if(typeof document.body.style.MozUserSelect!="undefined") {
        document.body.style.MozUserSelect="none";
    }
}
function init() {
    if((location.href+"")!=(location.href+"").replace("#","")) location="#"+(location.href+"").split("#")[1];
    window.bsl=new BorderStyleList();
    window.bsl.add("border1","/modules/interfaces/hardcorepower/js/borderstyle/1.htm");
    window.bsl.add("border2","/modules/interfaces/hardcorepower/js/borderstyle/2.htm");
    setTimeout("window.bsl.setOnAll(document.body);",1000);
    window.minimumRpics=5;
    window.maximumRpics=10;
    window.disableDragRandom=true;
    
/*
    setSelectstart();
*/  window.initReady=true;
    if(document.getElementById("rpicContainer")) initPicturecomponentRandom(document.getElementById("rpicContainer"));
    window.attachEvent("onbeforeunload",fcRemoveChart);
    
    setTimeout("randomVolgende();",3000);
    var anchs=document.getElementsByTagName("a");
    for(var i=0;i<anchs.length;i++) {
        if(anchs[i].href.indexOf("http")>=0 && anchs[i].href.indexOf(top.WEBSITE_HTTP)<0)
            anchs[i].target="_blank";
        else if(anchs[i].href.indexOf("#")<0 && anchs[i].href!="javascript://") anchs[i].target="_top";
    }
}

function fcRemoveChart() {
    var arr = document.all.tags("embed");
    if (arr && arr.length) {
        for (var i=arr.length-1; 0<=i; i--) {
            arr[i].parentNode.removeChild(arr[i]);
        }
    }
}

function loadInfoImage(objectid,imgid) {
    str=rpc(WEBSITE_HTTP+"modules/components/pictures/info.php?object_id="+objectid+"&img_id="+imgid);
    if(document.getElementById("pics"+objectid))document.getElementById("pics"+objectid).innerHTML=str;
    else if(top.document.getElementById("pics"+objectid))top.document.getElementById("pics"+objectid).innerHTML=str;
    else if(top.document.getElementById("inframe")&&top.document.getElementById("inframe").contentWindow&&top.document.getElementById("inframe").contentWindow.document.getElementById("pics"+objectid))top.document.getElementById("inframe").contentWindow.document.getElementById("pics"+objectid).innerHTML=str;
    else return loadInfoImageIntern(objectid,imgid);
}

function loadInfoImageIntern(objectid,imgid) {
    document.getElementById("infoPic"+objectid).innerHTML=rpc(WEBSITE_HTTP+"modules/components/pictures/info.php?intern=1&object_id="+objectid+"&img_id="+imgid);
    setanchor(objectid);
}

function setanchor(objectid) {
    fr=(document.getElementById("inframe"))?document.getElementById("inframe").contentWindow:top;
    fr.location=(""+fr.location).split("#")[0]+"#object";
    setTimeout('fr.location=(""+fr.location).split("#")[0]+"#object'+objectid+'";',1000);
}




function showPopup(surl,e,positionfromright,big) {
    iwidth=(big?800:400);
    iheight=(big?660:400);
    if(window.isGoing) {
        closePopup();
        return showPopup(surl,e,positionfromright,big);
    }
    window.isGoing=true;
    hideSelects();

 //   document.body.style.overflow="hidden";
//    var pop=document.body.appendChild(document.createElement("div"));
//    pop.style.position="absolute";
//    pop.style.cursor="pointer";
//    pop.style.top=(0+(window.document.body&&window.document.body.scrollTop?window.document.body.scrollTop:0))+"px";
//    pop.style.left="0px";
//    pop.onclick=new Function("closePopup();");
//    pop.style.width="100%";
//    pop.style.height="100%";
    //document.body.getElementsByTagName("div")[0].offsetHeight;
//    pop.style.display="none";
//    pop.style.backgroundColor="black";
//    pop.style.backgroundImage="url('interfaces/hardcorepower/images/popupbg.png')";

    var inpop=document.body.appendChild(document.createElement("img"));
    inpop.style.position="absolute";
    inpop.style.cursor="pointer";
    inpop.onclick=new Function("closePopup();");
    if(!positionfromright) {
        inpop.style.top=((isIE?e.clientY+document.body.scrollTop:e.pageY))+"px";
        inpop.style.left=((isIE?e.clientX+document.body.scrollLeft:e.pageX))+"px";
    }
    else {
        inpop.style.top=((isIE?e.clientY+document.body.scrollTop:e.pageY) - 10)+"px";
        inpop.style.left=((isIE?e.clientX+document.body.scrollLeft:e.pageX) - 10)+"px";
    }
    window.ol=inpop.offsetLeft;
    window.ot=inpop.offsetTop;

    screenwidth=isIE?document.body.clientWidth:document.body.clientWidth;
    if(!positionfromright&& (iwidth + ol - (iwidth/1000*105) + (iwidth/10000*125) > screenwidth + 100)) positionfromright=true;
    if(positionfromright&& (ol - (iwidth/1000*925) + (iwidth/10000*125) < 0 - 100)) positionfromright=false;

    inpop.style.marginLeft="1";
    inpop.style.width="10px";
    inpop.style.height="10px";
    inpop.style.color="#a7a099";
    inpop.id="inpop";

    var inpop2=document.body.appendChild(document.createElement("iframe"));
    inpop2.setAttribute('frameBorder','no');
    inpop2.setAttribute('allowTransparency','yes');
    inpop2.style.position="absolute";
    inpop2.id="inpop2";
    inpop2.style.display="none";

    
    if(isMOZ) {
        //pop.onmousedown= function(e) {
        //    if(e.button==1) {
        //        e.preventDefault();
        //        e.cancelBubble=true;
        //        return false;
        //    }
        //}
        inpop.onmousedown= function(e) {
            if(e.button==1) {
                e.preventDefault();
                e.cancelBubble=true;
                return false;
            }
        }
        window.oldkeydown=document.onkeydown;
        document.onkeydown=function(e) {
            if(e.which==37||e.which==38||e.which==39||e.which==40) {
                e.preventDefault();
                e.cancelBubble=true;
                return false;
            }
        }
//        pop.style.opacity="0.3";
    }
//    else pop.style.filter="alpha(opacity=30)";

//    window.activePopup=pop;
    window.activePopup2=inpop2;
    window.activePopup3=inpop;
    window.activePopup3.src=WEBSITE_HTTP+"modules/interfaces/hardcorepower/images/"+(positionfromright?"r":"")+"popup.png";



    window.surl=surl;
    window.runner.clear();
    window.runner.onready=function (r) {
        setTimeout("finishPopup('"+surl+"',"+(positionfromright)+","+(big)+");",100);
        r.clear();
    }
    window.runner.addFunction(function(r) {
        if(!positionfromright) {
            window.px=(iwidth/1000*105)/r.steps * (r.step);
            window.py=(iheight/10000*9825)/r.steps * (r.step);
        }
        else if(positionfromright) {
            window.px=(iwidth/1000*925)/r.steps * (r.step);
            window.py=(iheight/1000*967)/r.steps * (r.step);
        }
        pxw=(iwidth)/r.steps * (r.step);
        pxh=(iheight)/r.steps * (r.step);
        window.activePopup3.style.left=(ol - px + (iwidth/10000*125))+"px";
        window.activePopup3.style.top=(ot - py + (iheight/10000*125))+"px";
        window.activePopup3.style.width=pxw+"px";
        window.activePopup3.style.height=pxh+"px";


        if(positionfromright) {
            window.px=(iwidth/100*90);
            window.py=(iheight/100*85);
        }


        if(r.step>=r.steps) r.run=false;
    });
    window.runner.start(20,10,true);

}
function finishPopup(surl,fromright,big) {
    iwidth=(big?800:400);
    iheight=(big?660:400);

//    window.activePopup.style.top=document.body.scrollTop;
//    window.activePopup.style.display="";
    window.activePopup3.style.width=iwidth+"px";
    window.activePopup3.style.left=(ol - px)+"px";
    window.activePopup3.style.top=(ot - py)+"px";

    window.activePopup2.style.display="";
    window.activePopup2.src=surl;
    window.activePopup2.style.width=(iwidth/1000*875) + "px";
    window.activePopup2.style.height=(iheight/100*57) + "px";
    window.activePopup2.style.left=(ol - px + (iwidth/10000*625))+"px";
    window.activePopup2.style.top=(ot - py + (iheight/10000*625))+"px";
}

function closePopup() { 
//    document.body.style.overflow="";
    removeEmbedsFromPopup();
    if(window.oldkeydown) document.onkeydown=window.oldkeydown;
    if(window.onclosepopup) window.onclosepopup();
    window.onclosepopup=null;
    showSelects();
//    if(window.activePopup&&window.activePopup.parentNode) window.activePopup.parentNode.removeChild(window.activePopup);
    if(window.activePopup3&&window.activePopup2.parentNode) window.activePopup2.parentNode.removeChild(window.activePopup2);
    if(window.activePopup3&&window.activePopup3.parentNode) window.activePopup3.parentNode.removeChild(window.activePopup3);
    if(window.popupclose&&window.popupclose.parentNode) window.popupclose.parentNode.removeChild(window.popupclose);
//    window.activePopup=false;
    window.activePopup2=false;
    window.activePopup3=false;
    window.popupclose=false;
    window.isGoing=false;
}




function setImg(url,anchor) {
    top.closePopup();
    top.activeRtObject.addHTML("<img src='"+url+"'/>");
    
}
function setFlash(url,anchor) {
    top.closePopup();
    _flash(url);

    location=(""+location).split("#")[0]+"#object";
    setTimeout('location=(""+location).split("#")[0]+"#'+anchor+'";',100);
}

top.maak_detail=function() {
    objid=top.selected_object.id.replace("object","");
    eval(rpc(WEBSITE_HTTP+"modules/tasks/detailpage_maken/setdetailpage.php?id="+objid));
}

top.setpics=[];
top.finsetpic=function(t,spath) {
    for(var i=0;i<top.setpics.length&&top.setpics[i];i++) {
        top.setpics[i].t.src=top.setpics[i].path;
    }
}
top.setpic=function(t,path) {
    if(top.settingpics) clearTimeout(top.settingpics);
    top.setpics.push({t:t,path:path});
    t.onload=null;
    top.settingpics=setTimeout(top.finsetpic,2500);
}
