/*
Element.removeClassName = Element.removeClass;
Element.addClassName = Element.addClass;
Fx.Styles = Fx.Morph;
Fx.Style = Fx.Tween;
*/
GingerNV = {};

/* Cheap tabs */
Pagination = {};
Pagination.current = 0;
Pagination.el = [];
Pagination.prev = function() {
    if (Pagination.current > 0) {
        Pagination.el[Pagination.current].removeClass('selected-tab');
        Pagination.current--;
        Pagination.el[Pagination.current].addClass('selected-tab');
        Pagination.setSection(Pagination.el[Pagination.current]);
        return true;
    }
    return false;
}
Pagination.next = function() {
    if (Pagination.current < Pagination.el.length-1) {
        Pagination.el[Pagination.current].removeClass('selected-tab');
        Pagination.current++;
        Pagination.el[Pagination.current].addClass('selected-tab');
        Pagination.setSection(Pagination.el[Pagination.current]);
        return true;
    }
    return false;
}
Pagination.setSection = function(el) {
    var id = el.className.match(/section-\S+/);
    if (id && id.length > 0) {
        $$('.side a.tab').each(function(elem){
            elem.removeClass('selected');
        });
        $(id[0]).addClass('selected');
    }
}
Pagination.goTo = function(i) {
    if (isNaN(i)) {
        var j = 0;
        Pagination.el.each(function(el){
            el.removeClass('selected-tab');
            if (el.id == i) {
                el.addClass('selected-tab');
                Pagination.setSection(el);
                Pagination.current = j;
                return true;
            }
            j++;
        });
    } else {
        if (i >= 0 && i <Pagination.el.length-1){
            Pagination.el.each(function(el){
                el.removeClass('selected-tab');
            });
            Pagination.el[i].addClass('selected-tab');
            Pagination.setSection(Pagination.el[i]);
            Pagination.current = i;
            return true;
        }
    }
    return false;
}

window.addEvent('domready', function(){
    /**
     * Squeezebox
     */
     /*
    SqueezeBox.initialize({
        size: {x: 640, y: 480},
        ajaxOptions: {
            method: 'get'
        }
    });
    $$('a.boxed').each(function(el) {
        el.addEvent('click', function(e) {
            new Event(e).stop();
            SqueezeBox.fromElement(el);
        });
    });
    */
    
    //Tabs
    $$('.side a.tab').each(function(elem){
        elem.addEvent('click', function(e){
            var i = elem.href.lastIndexOf("#") + 1;
            var id = elem.href.substr(i, elem.href.length-i);
            Pagination.goTo(id);
            new Event(e).stop();
        });
    });
    
    //Widgets
    Pagination.el = $$('.tabs div.tab');
    Pagination.current = 0;
    
    var HashLocationName = document.location.hash;
    HashLocationName = HashLocationName.replace("#","");
    if ('' != HashLocationName) {
        Pagination.goTo(HashLocationName);
    } else {
        Pagination.goTo(0);
    }
});