/**************************************************************

        Script          : Page Loader
        Version         : 1.1
        Authors         : Samuel Birch
        Desc            : load pages via AJAX.
        Licence         : Open Source MIT Licence

**************************************************************/

var pageLoader = new Class({
                                                          
        getOptions: function(){
                return {
                        links: '.pageLoad',
                        loadInTo: 'ajaxsite',
                        loadFrom: 'site',
                        _onStart: $empty,
                        _onComplete: $empty
                };
        },

        initialize: function(options){
        
                this.setOptions(this.getOptions(), options);
                
                this.links = $$(this.options.links);
                this.links.each(function(el,i){
                        el.addEvent('click',function(e){
                                if(e != undefined){
                                        new Event(e).stop();
                                }
                                this.start(el);
                        }.bind(this));
                }.bind(this));
        },
        
        setContent: function(html){
                var temp = new Element('div').set({
                        'id': 'temp',
                        'styles': {
                                'display': 'none'
                        },
                        'html': html
                }).inject(document.body);
                
                var newEl = $('temp').getElement('#'+this.options.loadFrom);
                newEl.replaces($(this.options.loadInTo));
                newEl.set('id', this.options.loadInTo);
                temp.destroy();
                
        },
        
        start: function(el, page){
				$('content').setStyle('background-image', 'url(image/loader.gif)');
				this.page = page;
                this.options._onStart();
								this.setHashAndTitle(el.id);
								
                this.content = new Request.HTML({
                                                                method: 'get',
                                                                onComplete: this.complete.bind(this),
                                                                autoCancel: true
                                                        }).get(el.href);
        },
        
        complete: function(tree, els, html, js){
				$('content').setStyle('background-image', '');
                this.setContent(html);
                this.options._onComplete();
				buildAccordion();
				if(this.page == 'Kontakt') {
					new FormCheck('kontaktForm');
				}
        },

	
		setHashAndTitle: function(page){
			window.location.hash = "#"+page;
			document.title = "Online Cross :: " + page; 
		}
});
pageLoader.implement(new Events);
pageLoader.implement(new Options);


/*************************************************************/

