window.addEvent('domready', function() {
    Element.implement({
        toggle: function() {
            if (this.getStyle("opacity") == 0) {
				this.setStyle("display", "block");
				this.fade(0.9);
            } else {
				var tween = this.get("tween", {'property': 'opacity'}); 
				tween.start(0).chain(function(){ this.element.setStyle('display','none') });
            }
        },
        fadeOut: function() {
			var tween = this.get("tween", {'property': 'opacity'}); 
			tween.start(0).chain(function(){ this.element.setStyle('display','none') });
        },
       	fadeIn: function() {
			this.setStyle("display", "block");
			this.fade(0.9);
        },
        removeText: function() {
            this.value("");
        },
        addText: function() {
            this.value("Search");
        }
    });
    
    $('dropdown').addEvent('click', function() {
        $('dropdownMenu').toggle();
    });
    
    $('dropdown').addEvent('mouseenter', function() {
        $('dropdownMenu').fadeIn();
    });
    
    $('dropdownMenu').addEvent('mouseleave', function() {
        $('dropdownMenu').fadeOut();
    });
    
    $('searchBox').addEvent('click', function() {
        $('searchBox').removeText();
    });
    /*
    $('searchBox').addEvent('mouseleave', function() {
        $('searchBox').addText();
    });
    */

	// Accommodate the chapters table.
	if ($('chapter_table')) {
		new SortingTable( $('chapter_table'), {zebra: false});
		//$("thead").store("tip:text", "Stuff");
		
		$$('th.tooltip').each(function(element,index) { 
		      var content = element.get('abbr').split('::');
		      element.store('tip:title', content[0]);
		      element.store('tip:text', content[1]);
		});
		
		 var tooltip = new Tips('.tooltip',{ 
		      fixed: true, 
		      hideDelay: 1, 
		      showDelay: 0,
			  offsets: {'x': 0, 'y': -45},
			  onShow: function(toolTipElement){
				toolTipElement.fade(.9);
			  },
			  onHide: function(toolTipElement){
		      	toolTipElement.fade(0);
			  }
		 });
	}
	if ($('contentRight')) {
	    new ImageSlideShow({

	            imgUrls: [
		            "http://www.redonxi.com/mwot/includes/images/rotation_1.jpg",
		            "http://www.redonxi.com/mwot/includes/images/rotation_2.jpg",
		            "http://www.redonxi.com/mwot/includes/images/rotation_3.jpg",
		            "http://www.redonxi.com/mwot/includes/images/rotation_4.jpg",
		            "http://www.redonxi.com/mwot/includes/images/rotation_5.jpg",
		            "http://www.redonxi.com/mwot/includes/images/rotation_6.jpg"
	            ],
	            container: $('contentRight')
	    });
	}
});
