/*--------------------------------------------------------------

# Viyo - January 2009 (for Joomla 1.5)

# Copyright (C) 2007-2009 Gavick.com. All Rights Reserved.

# License: Copyrighted Commercial Software

# Website: http://www.gavick.com

# Support: support@gavick.com  

---------------------------------------------------------------*/



function OutOfOrder(){


    var $b = $(document.getElementsByTagName('body')[0]);

    if(Cookie.get('gk22_font')) $b.setStyle("font-size", Cookie.get('gk22_font'));

    else $b.setStyle("font-size", "62.5%");

    // smoothscroll init

    new SmoothScroll();

    // aniation classes - Fx.Height and Fx.Opacity

    Fx.Height = Fx.Style.extend({initialize: function(el, options){this.parent(el, 'height', options);this.element.setStyle('overflow', 'hidden');},toggle: function(){return (this.element.offsetHeight > 0) ? this.custom(this.element.offsetHeight, 0) : this.custom(0, this.element.scrollHeight);},show: function(){return this.set(this.element.scrollHeight);}});

    Fx.Opacity = Fx.Style.extend({initialize: function(el, options){this.now = 1;this.parent(el, 'opacity', options);},toggle: function(){return (this.now > 0) ? this.start(1, 0) : this.start(0, 1);},show: function(){return this.set(1);}});

    // font size switcher

    if($('font_minus_btn')){

        // reset font size

        $('font_reset_btn').addEvent("click", function(){

            $b.setStyle("font-size", "62.5%");    

            new Cookie.set('gk22_font',"62.5%",{duration: 200,path: "/"});

        });

        // increase font size

        $('font_plus_btn').addEvent("click", function(){

            if($b.getStyle("font-size").toFloat() < 75){

                $b.setStyle("font-size", $b.getStyle("font-size").toFloat() + 2.5 + "%");

                new Cookie.set('gk22_font',$b.getStyle("font-size").toFloat() + 2.5 + "%",{duration: 200,path: "/"});

            }

        });

        // decrease font size

        $('font_minus_btn').addEvent("click", function(){

            if($b.getStyle("font-size").toFloat() > 50){

                $b.setStyle("font-size", $b.getStyle("font-size").toFloat() - 2.5 + "%");

                new Cookie.set('gk22_font',$b.getStyle("font-size").toFloat() - 2.5 + "%",{duration: 200,path: "/"});

            }

        });

    }

    // login slide

    if($('login_btn')){

        var opened = false;

        $('userarea').setStyle("display","block");

        var ef = new Fx.Height('wrapper_userarea', {duration: 300, wait: true});

        ef.set(0);

        $('login_btn').addEvent("click", function(){

            ef.toggle();

            $('login_btn').innerHTML = "<span></span>" + ((opened) ? $GKGlobal["open"] : $GKGlobal["close"]);

            opened = !opened; 

        });

    }

    // slider in menu

    if($('slide_path')){

        var slide_anim = new Fx.Styles($('slide_knob'),{duration: 600, wait: false, transition: Fx.Transitions.Quint.easeInOut});

        var menu_div = $('horiz-menu');

        var pos = ($$('li.active')[0]) ? $$('li.active')[0].getPosition().x : $$('#horiz-menu li')[0].getPosition().x;

        var size = ($$('li.active')[0]) ? $$('li.active')[0].getSize().size.x : $$('#horiz-menu li')[0].getSize().size.x;

        // first step

        slide_anim.set({

            "margin-left" : (!window.ie) ? pos - menu_div.getPosition().x : pos,

            "width" : size - 4

        });

        // animation

        $$('li.level1').each(function(el){

            el.addEvent('mouseenter', function(){

                slide_anim.start({

                    "margin-left" : (!window.ie) ? el.getPosition().x - menu_div.getPosition().x : el.getPosition().x,

                    "width" : el.getSize().size.x - 4

                });

            });

        });

    }    

    // background switcher

    if($('stylearea')){

        $$('.bg_switcher').each(function(element,index){

            element.addEvent('click',function(event){

                var event = new Event(event);

                event.preventDefault();

                changeBg(index+1);

            });

        });

    }

}

// Function to change backgrouns

function changeBg(style){

    var $b = $(document.getElementsByTagName('body')[0]);

    //    

    if(style == 1)

    {

        $b.setStyle('background', '#e8f6fd url(\''+$template_path+'/images/style/backgrounds/bg_1_base.png\') repeat-x 0 0');

        $('wrapper_main').setStyle('background','transparent url(\''+$template_path+'/images/style/backgrounds/bg_1_main.jpg\') no-repeat center -30px'); 

        $('bottom_wrap_2').setStyle('background','#62B4D9 url(\''+$template_path+'/images/style/backgrounds/bottom_bg_1.png\') repeat-x  0 bottom');

    }else{

        $b.setStyle('background', '#e8f6fd url(\''+$template_path+'/images/style/backgrounds/bg_'+style+'.png\') repeat 0 0');

        $('wrapper_main').setStyle('background','none'); 

        $('bottom_wrap_2').setStyle('background','#62B4D9 url(\''+$template_path+'/images/style/backgrounds/bottom_bg_other.png\') repeat-x  0 bottom');    

    }

    // save config in cookie

    new Cookie.set('gk22_bg',style,{duration: 200,path: "/"});

}