

Event.observe(window, 'load',initKH, false);

function initKH(){
     appendHrefScript();
}


fx.ElementScroll = Class.create();
fx.ElementScroll.prototype = Object.extend(new fx.Base(), {
    initialize: function(el, options) {
        this.el = el;
        this.iniMarginLeft = this.el.style.marginLeft;
        this.setOptions(options);
    },

    increase: function() {
        this.el.style.marginLeft = this.now + 'px';
    },

    toggle: function(){
        if (this.el.marginLeft > 0) this.custom(this.el.marginLeft, 0);
        else this.custom(0, this.iniMarginLeft);
    }
});

function showMorePics(){
        var clientTween = new fx.ElementScroll($('image_block_1'), {duration: 400, transition: fx.sinoidal});
        clientTween.custom(0, -600);
        $('more_link').hide();
        $('back_link').show();
}

function showLessPics(){
        var clientTween = new fx.ElementScroll($('image_block_1'), {duration: 400, transition: fx.sinoidal});
        clientTween.custom(-600, 0);
        $('more_link').show();
        $('back_link').hide();
}

function showMorePicsOld(){
    if(!Element.visible($('image_block_2'))){
           new Effect.BlindUp($('image_block_1'),{
                duration:0.3,
                afterFinish:function(){
                    new Effect.BlindDown($('image_block_2'), {duration:0.3});
                    $('more_link').innerHTML = 'Back';
                    $('more_link').className ="arrow_r";
                }
            });
    } else if(Element.visible($('image_block_2'))){
           new Effect.BlindUp($('image_block_2'),{
                duration:0.3,
                afterFinish:function(){
                    new Effect.BlindDown($('image_block_1'), {duration:0.3});
                    $('more_link').innerHTML = 'More';
                    $('more_link').className ="arrow";
                }
            });
    }
}


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 toggleSubnavi(element){

    $$(".sub_menu").each(function(e) {
       if(e.down(1).href != element.down(1).href)
            new Effect.BlindUp(e, {duration:0.5});

    });


    if(Element.visible(element)){
        new Effect.BlindUp(element, {duration:0.5});
    } else {
        new Effect.BlindDown(element, {duration:0.5});
    }
}


function changeState(event){
    var active = Event.element(event);
      $$('.navi_sub').each(function(element) {
               element.up().className = "";
               if(active == element.href)
                element.up().className = "nav_active";
      });
}

function changeState2(active){
      $$('.exlusive_button').each(function(element) {
               element.className = "exlusive_button";
               if(active == element)
                element.className = "exlusive_button active";
      });
}

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) {

        new Ajax.Updater(
            target,
            url,
            {   method:'get',
                asynchronous:true,
                evalScripts:true,
                beforeStart: function() {
                    initKH();
                    initLightbox();
                },
                onSuccess: function(){

                }
            }
        );

}


