var acEs=new Array(3);
var acSs=new Array(3);
var cEs=new Array(3);
$(document).ready(function(){
    setBack(SITE_BACKGROUND_SIZE);
    registerFunctions(new Array($(".m1 a"),$(".m2 a"),$(".m3 a")));
    window.setTimeout(function(){
        setEntryActive(0);
        checkSubMenu(1);
        checkSubMenu(2);
    },300)
});
function registerFunctions(a){
    for(i=0;i<a.length;i++){
        a[i].mouseover(function(){
            l=parseInt($(this).attr("rel"));
            $('#movingBoxL'+(l+1)).stop();
            cEs[l]=$(this);
            moveBox(cEs[l],acEs[l],200,l)
        });
        a[i].mouseout(function(){
            l=parseInt($(this).attr("rel"));
            $('#movingBoxL'+(l+1)).stop();
            moveBox(acEs[l],cEs[l],300,l);
        });
        a[i].click(function(){
            $('#movingBoxL1').addClass("boxload");
            window.location.href=$(this).attr('href');
            return false
        })
    }
}
function setEntryActive(l){
    if($('a#activeM'+(l+1)).length>0){
        acEs[l]=$('a#activeM'+(l+1));
        initBlock(l);
    }
}
function initBlock(l){
    pos=getPos(acEs[l]);
    $('#movingBoxL'+(l+1)).css({
        left:pos[1],
        display:'block'
    }).animate({
        top:pos[0]
    },10,function(){
        name=$('img:first-child',acEs[l]).attr('name');
        $('img:first-child',acEs[l]).attr('src',eval(name+"_h.src"));
    })
}
function initSubMenu(a,l){
    if($('a#activeM'+(l+1),a).length>0){
        setEntryActive(l);
    }else{
        acEs[l]=cEs[l]=$('.m'+(l+1)+':first-child a:first-child',a);
        initBlock(l);
        moveBox(acEs[l],cEs[l],0,l);
    }
}
function checkSubMenu(l){
    if($('a#activeM'+(l+1)).length>0){
        acSs[l-1]=$('a#activeM'+(l+1)).parent().parent("div.submenuframe");
        $('a#activeM'+(l+1)).parent().parent("div.submenuframe").slideDown(10,function(){
            initSubMenu($('a#activeM'+(l+1)).parent().parent("div.submenuframe"),l);
            for(i=0;i<l;i++) {
                initBlock(i);
            }
        })
    }
}
function moveBox(a,b,c,d){
    if(a&&b&&a.length==1&&b.length==1){
        name=$('img:first-child',b).attr('name');
        pos=getPos(a);
        $('img:first-child',b).attr('src',eval(name+"_n.src"));
        $('#movingBoxL'+(d+1)).animate({
            top:pos[0],
            left:pos[1]
        },c,function(){
            name=$('img:first-child',a).attr('name');
            $('img:first-child',a).attr('src',eval(name+"_h.src"));
        })
    }
}
function getPos(a){
    yP=$(a).position().top-($('#leftmenu').height()+$('#leftmenu').position().top);
    xP=$(a).position().left-($('#leftmenu').width()+$('#leftmenu').position().left);
    if(a.parent().parent("div.submenuframe").length>0){
        yP=(a.position().top-32)-($('#leftmenu').height()+$('#leftmenu').position().top);
    }
    return new Array(yP,xP);
}
function setBack(c){
    if(document.cookie.indexOf('backgroundNumber')==-1){
        rI=1+parseInt(Math.random()*(3-1+1));
        document.cookie="backgroundNumber="+rI+";path=/"
    }else{
        rIs=document.cookie.split(";");
        for(i=0;i<rIs.length;i++){
            if(rIs[i].indexOf("backgroundNumber")!=-1){
                valPair=rIs[i].split("=");
                rI=valPair[1]
            }
        }
    }
    sw=screen.width;
    sh=screen.height;
    if(sw>c){
        $.post('fileadmin/scripts/createimage.php',{
            image:"templates/main/images/background_"+rI+".jpg",
            sw:sw,
            sh:sh
        },function(a){
            if(a!=false){
                var b=document.body;
                b.style.backgroundImage='url('+a+')'
            }
        })
    }else{
        var d=document.body;
        d.style.backgroundImage='url(fileadmin/templates/main/images/background_'+rI+'.jpg)';
        d.style.backgroundRepeat='no-repeat'
    }
}
function over(a){
    return true
}
function out(a){
    return true
}