// -------------------------------------------
// new handlers
// -------------------------------------------
var imagePermuter = new Object();


imagePermuter.dynInitFromValue = 1.0;
imagePermuter.dynInitToValue = 0.1;


/**
 * init the dynbox for all dynamic pictures
 */
imagePermuter.initDynbox = function(){
    //get all divs with rel="dynbox7" and class="imageContainer"
    var elems = document.getElementsByTagName("div");
    if(elems != null){
        for(var i=0; i < elems.length; i++){
            var div = elems[i];
            var relAttribute = String(div.getAttribute('rel'));
            if(relAttribute != "null"){
                imagePermuter.initDynPlay(relAttribute);            
                //alert(relAttribute);    
            }
        }
    }
}

/**
 * init the image playing
 */   
imagePermuter.initDynPlay = function(id){
    //get all the images
    var containerId = id + "Container";
    if($(containerId) != null){
        var links = $(containerId).getElementsByTagName("a");
        if(links!=null){
            imagePermuter.dynPlay(id, links, 0, imagePermuter.dynInitFromValue, imagePermuter.dynInitToValue);
        }        
    }
}

/**
 * execute the rotation
 */
imagePermuter.dynPlay = function(id, links, beginWith, from, to){
    if(id != null && links != null){
        if(beginWith == links.length){
            beginWith = 0;
        }  
        var playerId = id + "Player";
        var imageId = id + "Image";
        new Effect.Opacity(
            playerId, 
            { 
                duration: 3.0, 
                transition: Effect.Transitions.linear, 
                from: from, 
                to: to,
                beforeStart: function(){},
                afterFinish: function(){
                    //handle next iteraction
                    //case 1 => 0
                    //go to next picture
                    if(from > to){
                        imagePermuter.dynPlay(id, links, beginWith+1, imagePermuter.dynInitToValue, imagePermuter.dynInitFromValue);
                        if((beginWith+1) == links.length){
                            $(imageId).src = links[0].href;
                        }else{
                            $(imageId).src = links[beginWith+1].href;
                        }  
                       
                        
                    //case 0 => 1                    
                    //keep picture but change effect
                    }else{                     
                       imagePermuter.dynPlay(id, links, beginWith, imagePermuter.dynInitFromValue, imagePermuter.dynInitToValue);
                    }
                }
            }
        );
    }
}


 

