if(typeof Ajax_section_loader=='undefined') {
    var Ajax_section_loader = {};
}
/**************************** BUNDLE PRODUCT **************************/
Ajax_section_loader = Class.create();
Ajax_section_loader.prototype = {
    sections: [],
    
    initialize: function(){
        var that = this;
        
        $$('.ajax_box').each(function(elem){
            that.sections[that.sections.length] = $(elem).id;
        });
        this.requestContent();
    },
    
    requestContent: function(){
        var that = this;
        this.sections.each(function(elem){
            var link = $(elem).readAttribute('link');
            var curr_loc = $(elem).readAttribute('url');
            link += '?rand=' + Math.random();
            if(curr_loc)
            {
                link += '&curr=' + escape(curr_loc);
            }
            
            if(link.indexOf(location.protocol) == -1)
            {
                if(location.protocol == 'http:')
                {
                    replaceWith = 'https:';
                }
                else
                {
                    replaceWith = 'http:';
                }
                link = link.replace(replaceWith, location.protocol);
            }
            
            new Ajax.Request(link, {
                method: 'get',
                onSuccess: (function(transport){ 
                    that.updateContent(transport, elem);
                    setTimeout(function() {
                        $(elem).fire("section:loaded", { obj: elem });
                    }, 250);
                }).bind(this),
                onFailure: (function(transport){ 
                    that.handleError(transport); 
                }).bind(this)
            });
        });
    },
    
    updateContent: function(transport, elem){
        var update_elem = elem;
//        $(update_elem).setOpacity(0);
        $(update_elem).update(transport.responseText);
//        $(update_elem).appear({duration: 0.5});
    },
    
    handleError: function(transport){
        
    }
};
document.observe('dom:loaded', function () { new Ajax_section_loader(); });

