/**
 * Project: STUDIO SEIDEL
 * 
 * Javascripts for project-pages
 * 
 * @author Andreas Prockl <ap@okapi.de>
 * @version 1.0
 *
 */


/*
 * Read More Toggler 
 * Pages: Projects
 */

var TogglerSeeMore = new Class({
	Implements: [Chain, Options],
	
	options: {
		buttons: {
			close:						"btn-close",						// close-Button (.btn-close)
			togglemore:				"toggle-content"				// btn f�r auf- und zuklappen (.toggle-content)
		},
		boxes: {
			container:				"switch-container"			// Container, der auf-/zugeklappt wird (#head-teaser-more)
		},
		delays: {
			afterSlideOut:		400,
			beforeSlideIn:		200
		},
		text: {
			open:					"read more",
			close:				"less"
		}
	},
	
	elements: {
		buttons: {
			close:						null,
			togglemore:				null
		},
		boxes: {
			container:				null
		}
	},

	target: null,


	initialize: function(options) {
		this.setOptions(options);
		
		this.elements.buttons.close					= $$("." + this.options.buttons.close);
		this.elements.buttons.togglemore		= $$("." + this.options.buttons.togglemore);
		
		this.elements.boxes.container				= $$("." + this.options.boxes.container);

	
		// Links austauschen
		for( i in this.elements.buttons )
		{
			this.elements.buttons[i].each(
				function( item )
				{
					item.href = "javascript:void(0);"		
				}
			);
		};

		// Funktionen an Events binden
		this.elements.buttons.close.addEvent("click", this.hide.bind(this));
		this.elements.buttons.togglemore.addEvent("click", this.toggle.bind(this));
		

		// Startzustand herstellen
		this.elements.boxes.container.setStyle("display", "none");
		this.elements.boxes.container.slide("out");

	},

	toggle: function(event) {
   	this.target = event.target;
		var checkBtnText = this.elements.buttons.togglemore.get('html');
		
		if( checkBtnText == this.options.text.open ) {
			this.show();
		}
		else
		{
			this.hide();
		}
  },

	show: function() {
		this.elements.buttons.togglemore.set( 'html', this.options.text.close );
		
		this.elements.boxes.container.setStyle("display", "block").slide("in");
		this.callChain();
  },

	hide: function() {
		this.elements.buttons.togglemore.set( 'html', this.options.text.open );
		this.elements.boxes.container.slide("out");
		this.callChain.delay(this.options.delays.afterSlideOut, this);
		
		
		/* IE 6 & 7 Bug-Fix */
		
		/*
		var fixIsNeeded = function() {
			return ((Browser.Engine.name == "trident" && Browser.Engine.version == 4) ||
			(Browser.Engine.name == "trident" && Browser.Engine.version == 5));
		};
		var target = $$(".switch-container")[0];
		
		if (fixIsNeeded())
		{
			target.setStyle("display", target.getStyle("display") == "none" ? "inline" : "none");
		}
		*/
	}
});


