Event.observe(window, 'load',initKH, false);

function initKH(){
    graphicalHeaders();
    initCoverFlow();
}

function graphicalHeaders(){
          $$(".graphical_header").each(
            function(element) {
                if("H1" == element.tagName)
                    element.style.backgroundImage = "url('image.php?header="+escape(element.innerHTML)+"')";
                if("H2" == element.tagName)
                    element.style.backgroundImage = "url('image.php?button="+escape(element.innerHTML)+"&color=000000&backcolor=DCEDD3&size=8&upper=1')";
                if("H3" == element.tagName)
                    element.style.backgroundImage = "url('image.php?button="+escape(element.innerHTML)+"&color=000000&size=9&upper=1')";
                if("SPAN" == element.tagName)
                    element.style.backgroundImage = "url('image.php?button="+escape(element.innerHTML)+"&color=000000&size=8&upper=1')";

            });
}

var flowstep = (63*5);
var flowtime = 0.8;

function initCoverFlow(){
    $$('.imageflowNext').each(function(element) {
        Event.observe(element, 'click',picsPrev, false);
        });
    $$('.imageflowPrev').each(function(element) {
      Event.observe(element, 'click',picsNext, false);
      });
}

function picsNext(event){
    movePics(event, 1);
}

function picsPrev(event){
    movePics(event, -1);
}

function movePics(event, amount){
    imagecontainer = $('filmstrip');
    position = parseFloat(imagecontainer.style.left || '0');
    desiredpos = position+(amount*flowstep);

    maxLeft = imagecontainer.up().getWidth()-calcWidth(imagecontainer)-flowstep;

    if((desiredpos <= 0) && (desiredpos > maxLeft)){
        moveByPix(imagecontainer, (amount*flowstep));
    }  else {
        moveByPix(imagecontainer, 0);
    }

}

function calcWidth(imagecontainer){
    var width = 0;
     imagecontainer.immediateDescendants().each(
                    function(el) {
                            width = width+el.getWidth();
                   });
      return  width;
}


function moveByPix(imagecontainer, pixels){
    new Effect.Move(imagecontainer, {x:pixels, y:0,duration:flowtime,
        beforeStart:deactivate,
        afterFinish:initCoverFlow,
        transition:Effect.Transitions.sinoidal
    });
}


function deactivate(){
    $$('.imageflowNext').each(function(element) {Event.stopObserving(element, 'click', false);});
    $$('.imageflowPrev').each(function(element) {Event.stopObserving(element, 'click', false);});
}



function appendHrefScript() {

    $$(".has_subnavi").each(
            function(element) {
                Event.observe(element.down(), "click",  function(event){
                    Event.stop(event);
                    var ul = element.down(1);
                    toggleSubnavi(ul);
                    return false;
                }, false);
    });
}



function SlideDown(element) {

   if($(element)) {
        new Effect.SlideDown(element, {duration:0.3});
   }
}

function formSubmit(form){
var target = form.parentNode.parentNode;
var params = Form.serialize($(form));
new Ajax.Updater(
    target, form.action,
    {   method:'post',
        asynchronous:true,
        evalScripts:true,
        onComplete: function() {
           // new Effect.Highlight(target, {duration:0.5,startcolor:'#cccccc'})
        },
        parameters:params});
return false;
}




function updateRight(event){

    var element = Event.element(event);

    if ("IMG" == element.tagName) {
        url = element.parentNode.href;
    } else {
        url = element;
    }

    Event.stop(event);
    var url = url+'?ajax=2';
    var target = $('extension');
    killDrags();

        new Ajax.Updater(
            target,
            url,
            {   method:'get',
                asynchronous:true,
                evalScripts:true,
                onComplete: function() {
                    target.hide();
                    new Effect.Appear(target, {duration:0.2});
                    initLightbox();
                }
            }
        );


}

function loadContent(event){

    var element = Event.element(event);

    if ("IMG" == element.tagName) {
        url = element.parentNode.href;
    } else {
        url = element;
    }

    if(url.href.indexOf("?")!==-1){
        var url = url+'&ajax=1';
    }else{
        var url = url+'?ajax=1';
    }


    Event.stop(event);
    
    var target = $('content');
    doAjax(target, url)


}

function doAjax(target, url) {

        $(target).hide();
        $('ajaxloader').show();
        new Ajax.Updater(
            target,
            url,
            {   method:'get',
                asynchronous:true,
                evalScripts:true,
                beforeStart: function() {

                },
                onSuccess: function(){
                $('ajaxloader').hide();
                   new Effect.Appear($(target), {duration:0.4});
                }
            }
        );

}

