var sc = null;
var origLIs = [];
var links = [];
var newLISet = [];

function createOnClick(linkImg) {
    return function(evt) {
        evt.stop();
        $('showcase').hide();
        newLISet = $A(origLIs);
        var i=origLIs.length;
        while(newLISet.first().origIndex!=linkImg.origIndex && i-- > 0) { // das geklickte ist nicht am anfang, => shift und push (hinten anfuegen)
            newLISet.push(newLISet.shift());
        } 
        newLISet.each(function(li) {
                li.setStyle({'height':'166px','width':'250px'});
                            li.stopObserving();
            });
        showCaseAfter();
    }
}
    
function showCaseAfter() {
    $('showcase').show();
    loadShowcase(newLISet, {initialDelay: 0.1});
}

function loadShowcase(lis, opts) {
    var options = {
      duration: 1, 
      ratio:0.2, 
      size:11
    };
    if(opts) Object.extend(options, opts);
    $$('a.controls').each(function(el) { el.stopObserving() });
    sc = new Showcase.Horizontal(lis, $$('a.controls'), options);
    
}
FastInit.addOnLoad( function() {
        links = $$('#externlinks li a');
        origLIs = $$('#showcase li');
        loadShowcase(origLIs);
        for(var i=0; i< links.length; i++) {
            var linkImg =  origLIs[i];
            linkImg.origIndex = i;
            links[i].observe('click', createOnClick(linkImg));
        }
    });

