var mooHistory = new Class ({
	Extends : general,
	Implements: [Options, Events],
	options:  {
			onComplete: function(el){},
			onLoading: function(){},
			update: ['content_center'],
			exclude: [],
			baseTitle: '',
			dateiname:'ajax_content.php',
			parameters:'',
			idtag:'content_center',
			extension: '/',
			evalScripts: true,
			alwaysStart: false
		
	},
	initialize: function(options){
		this.setOptions(options);
		this.webHost = window.location.host+this.options.extension;
		this.strip = ['http://'+this.webHost,'http://www.'+this.webHost,'#','index.html','index.php']
		if(this.options.alwaysStart != false && location.hash == (''&&'#'))location.hash = '#'+this.options.alwaysStart;
		
		this.historyCurrentHash = location.hash;
		
		if(Browser.Engine.trident) { // Wenn Browser IE
			if (this.historyCurrentHash == '') {
				this.historyCurrentHash = '#';
			}
			// add hidden iframe for IE
			this.ihistory = new Element('iframe').setStyle('display','none').set('id','ajaxHistory').injectInside(document.body);
			var iframe = this.ihistory.contentWindow.document;
			iframe.open();
			iframe.close();
			iframe.location.hash = this.historyCurrentHash;
			
		}else if (Browser.Engine.webkit420) {
			alert('test');
			this.historyBackStack = []; 	// etablish back/forward stacks
			this.historyBackStack.length = history.length;
			this.historyForwardStack = [];
			this.isFirst = true;
		}

		this.historyCheck.bind(this).periodical(20); // Überprüfung der URL
	},
	
	historyCallback: function(hash){
		if(hash) {
			var buffer = new Element('div').setStyle('display','none').injectBefore(document.body.getFirst());
		}	
	},


	historyAddHistory: function(hash) {
		this.historyBackStack.push(hash);
	
		this.historyForwardStack.length = 0; // clear forwardStack (true click occured)
		this.isFirst = true;
	},
	
	historyCheck: function(){
		if(Browser.Engine.trident) {
			var ihistory = $('ajaxHistory');
			var iframe = this.ihistory.contentDocument || this.ihistory.contentWindow.document;
			var current_hash = iframe.location.hash;
		
			if(current_hash != this.historyCurrentHash) {
				location.hash = current_hash;
				this.historyCurrentHash = current_hash;
				
				var divHash = current_hash.match('divID=([^&]*)');
					if($chk(divHash)){
						var updateDiv = divHash[1];	
					}else{
						var updateDiv = this.options.idtag;
					}
				var updateDiv = this.getElement(updateDiv);
				
				updateDiv.setStyles({'visibility' : 'hidden','opacity' : '0'});
				result = this.ajaxNew(current_hash.substring(1),updateDiv );
				result.addEvent('onComplete',function(){
						this.ajaxEffect(updateDiv);
				}.bind(this));	
			}
		} else { // Hier Firefox
			var current_hash = location.hash;
		
			if(current_hash != this.historyCurrentHash) {
				
				this.historyCurrentHash = current_hash;
				if(current_hash != ''){
					
					var divHash = current_hash.match('divID=([^&]*)');
					if($chk(divHash)){
						var updateDiv = divHash[1];	
					}else{
						var updateDiv = this.options.idtag;
					}
					
					var updateDiv = this.getElement(updateDiv);
					
					var tabHash = current_hash.match('tab=([^&]*)');
					if($chk(tabHash)){
						$$('.myTabs ul li').each(function(item){
							if(item.get('lang').contains('tab='+tabHash[1])){
								item.addClass('tabs_active');
								item.removeClass('tabs_normal');						
							}else{
								item.removeClass('tabs_active');
								item.addClass('tabs_normal');						
							}
						}.bind(this));
					}
				
				
					updateDiv.setStyles({'visibility' : 'hidden','opacity' : 0});
					
					$$('.new_window').dispose(); // Falls ein Fenster existiert
					result = this.ajax(current_hash,updateDiv);
					
					result.addEvent('onComplete',function(){
						this.ajaxEffect(updateDiv);
					}.bind(this));
					
					
				}
			}else{
				if(window.location.hash.contains('#')){
					//console.log('ist aktu');
				}
			}
		}
	},
	historyLoad: function(hash){
	
		var newhash;
		
		if (Browser.Engine.webkit) {
			newhash = hash;
		}else {
			newhash = '#' + hash;
			newhash = location.hash;
		}
		
	
		
		if(Browser.Engine.trident) {
			var ihistory = $('ajaxHistory');
			var iframe = this.ihistory.contentWindow.document;
			iframe.open();
			iframe.close();
			iframe.location.hash = newhash;
		}
	}
});



