// Copyright 2007 Alex Leykin
// Main web-application class. Initializes when the window loads.
var Rules = { 
    '.internalLink': function(el) {
        Event.observe(el, 'click', function(e) {
//	        Effect.Fade('key-point', {
//		        afterFinish:function(effect){new Ajax.Updater('key-point', el, {asynchronous:true, evalScripts:true});}, 
//		        duration: 0.2,
//		        queue:'front'} );
            //Effect.Fade('key-point',{duration:0.5});
            new Ajax.Updater('key-point', el, {asynchronous:true, evalScripts:true});
	        browserHistory.put(el);
            Event.stop(e);		            
        });
    }
    /*,
    
    '.trigger': function(el) {
        Event.observe(el, 'mouseover', function(e) {
            toolTip('Just a test', 150);
        });
        Event.observe(el, 'mouseout', function(e) {
            toolTip();
        });        
    }
    */
}

var application = Class.create();
application.prototype = {	
	initialize : function() {		
		// initialize behaviours
		Behaviour.register(Rules);
		
		// initialize tooltips
		Tooltip.setup();
		
		// initialize responders
		Ajax.Responders.register({
			onCreate: function() {
			    if ($('key-point') && Ajax.activeRequestCount > 0)
                    ;//Effect.Fade('key-point',{duration:0.5,queue:'end'});
			},
			onComplete: function() {
				if($('key-point') && Ajax.activeRequestCount == 0)
				    Behaviour.apply(Rules);		
					Tooltip.setup(); //collapse all tooltips in the document loaded into 'key-point'												    				    
					//Effect.Appear('key-point',{duration: 0.5});	
			}
		});		

		browserHistory = new historyStack("browserHistory", "");				
		browserHistory.onBrowserAddressChanged = function(){			
		    new Ajax.Updater('key-point', this.current, {asynchronous:true, evalScripts:true});
		};
				
		// load first page
//		if (!browserHistory.current) {
//		    alert(browserHistory.current);
//		    browserHistory.put('about.php');
//		}
        //alert(document.location.hash);
        //browserHistory.removeHash(document.location.hash)
		
		new Ajax.Updater('key-point', 'about.php', {asynchronous:true, evalScripts:true});
	}
}

Event.observe(window, "load", function(event) {new application()});

