/**
*
* Sliderbox and all the other 
* JS functions for the frontend
* 
* Requires mootools 
*
* @see mootools.js
*/
var sliders = {
	name: 'slider_obj',
	mySlide: [],
	close_but: [],
	
	init: function(){
		
		if(!document.getElementById){return false;}
		if(!document.getElementsByClassName){return false;}
		
		this.slideboxes = $ES('div.slide_box');
		this.slidebody = $ES('div.slide_body')
		
		if(this.slidebody.length == this.slideboxes.length){
			//initialize other functions
			this.slidebody.each( function(item, index){	
				 id = item.id; 	
				 this.createSliders(item, index);	
				 this.createButtons(item, index);
				 this.createPrintButton(item, index);
			}.bind(this) );
		}
		return true;
	},
	/**
	* Create the slider effect
	* for each box
	*
	*/
	createSliders: function(item, index){		
		this.mySlide[index] = new Fx.Slide(item);
		this.mySlide[index].hide();		
	},
	/**
	* Attach the event handler for the open and close button
	*
	*
	*/
	createButtons: function(item, index){
		//Make the close button 
		this.closer = this.slideboxes[index].getElementsByClassName('slide_but_close');
		
		//store them in an array so the text values can be changed
		this.close_but.push(this.closer);		
		
		this.closer.addEvent('click', function(e){
				this.toggleSlide(index);
		}.bind(this) );	    
	},
	/**
	* Create the print this posting behaviour
	*
	*/
	createPrintButton: function(item){
	 	buttons = document.getElementsByClassName('print_this');
	 	buttons.each(function(item){
	 		item.setProperty('target', '_blank');
	 	});
	},
	toggleSlide: function(id){
		
		//check the value of the links display string
		if(this.close_but[id][0].firstChild.nodeValue == "Summary"){
		  this.close_but[id][0].firstChild.nodeValue = "More Info";
		} else {
		  this.close_but[id][0].firstChild.nodeValue = "Summary";
		}

		//toggle the slider
		this.mySlide[id].toggle();
		return false;
	}

};

window.addEvent('domready', function(){
	sliders.init();
	
});    