///var colors = ["#8308eb","#1934ff","#44e6f9","#c560f9","#ff5151","#f9f11c","#0b0103","#677cb6","#11c780","#66fd66",
//    "#6f2b80","#ed46e7","#13b5de","#d7136f","#01a834","#0547a9","#ddb46c","#00bff9","#c884c2","#fff700","#ffa8d0",
//  "#946132","#ccb194","#f25858","#3e8d88"];
var colors = ["#8308eb","#1934ff","#18bfd3","#c560f9","#ff5151","#cbbb09","#0b0103","#677cb6","#0fbc79","#0ca40c","#6f2b80","#ed46e7","#13b5de","#d7136f","#47d508","#0547a9","#c5a124","#0eb2e4","#c09abd","#fa0427","#0290fd","#946132","#b39677","#f89090","#45a8a2"];
var usedColors = [];
var switchColor = function(element){
    $(element).set('tween', {duration: 'short'});
    var index = rand(0,colors.length);
    $(element).tween("color", colors[index]);
    usedColors.push(colors[index]);
    colors = colors.erase(colors[index]);
    if(colors.length == 0) {
      colors = usedColors.slice();
      usedColors.empty();
    }
}

var rand = function(min, max){
    var randomVal = Math.round(min + Math.random()*max);
    return randomVal;
}

var switchProject = function(toDo, direction){
    var p = new Array();
    if(!$defined(direction) || direction != "right") direction = "left";
    p[1] = $defined($("projekt-swf-1")) ? $("projekt-swf-1") : $("projekt-img-1");
    p[2] = $defined($("projekt-swf-2")) ? $("projekt-swf-2") : $("projekt-img-2");
    p[3] = $defined($("projekt-swf-3")) ? $("projekt-swf-3") : $("projekt-img-3");
    if(toDo == "switch"){
        if(direction == "left" ){
            var pr1 = $(p[1]).clone(true,true);
            p[1].setProperties({"id": p[3].get("id"),"height":p[3].getProperty("height"), "width":p[3].getProperty("width")});
            p[3].setProperties({"id": p[2].get("id"),"height":p[2].getProperty("height"), "width":p[2].getProperty("width")});
            p[2].setProperties({"id": pr1.get("id"),"height":pr1.getProperty("height"), "width":pr1.getProperty("width")});
            switchProject.delay(50, {}, "fadeIn");
        } else {
            var pr1 = $(p[3]).clone(true,true);            
            p[3].setProperties({"id": p[1].get("id"),"height":p[1].getProperty("height"), "width":p[1].getProperty("width")});
            p[1].setProperties({"id": p[2].get("id"),"height":p[2].getProperty("height"), "width":p[2].getProperty("width")});
            p[2].setProperties({"id": pr1.get("id"),"height":pr1.getProperty("height"), "width":pr1.getProperty("width")});
            switchProject.delay(50, {}, "fadeIn");
        }
    } else {
        var fade = "hide";
        if(toDo =="fadeIn") {
            fade = "show";
        } else {
            switchProject.delay(300, {}, ["switch", direction]);
        }
        p[1].fade.delay(0, p[1],fade);
        p[2].fade.delay(100, p[2],fade);
        p[3].fade.delay(200, p[3],fade);
    }
}

window.addEvent("domready", function(){
    $$("a").each(function(a){
        switchColor(a);
    });
    //alert($$(".projekt-img").length);
    if($$(".projekt-img").length >= 3){
        $$(".projekt-img").each(function(img){
            //img.setStyle("cursor", "pointer");
            try {
            img.addEvent("click", function(){

                if(this.get("id").contains("3")) switchProject('', "right");
                else switchProject('', "left");
            });
            } catch(err){}
        });
        $$(".projekt-a").each(function(a){
            a.setStyle("cursor", "pointer");
            a.addEvent("click", function(e){                
                e.stop();
                if(this.get("id").contains("3")) switchProject('', "right");
                else switchProject('', "left");
            });
        });
    }
});
