/*
	Show/Hide Toggler class v.1.2
	Dmitriy Abragamov
	Purpose: Creates a sliding open/close effect on the given element, triggered by click on the specified toggle element
	Arguments: [TriggerElementId]*, [TargetElementId]*, [OpenStateTextOfTriggerElement], [SpeedOfSlideInPixels]
	Example: 	var toggleRw = new Toggler("rw_trigger", "rw_additional", "&raquo;&nbsp;Close", 25);
*/

function addEvent(obj, evnt, funcRef, captureBool){
				if(document.attachEvent){
						obj.attachEvent('on'+evnt, funcRef);
					}else{
							obj.addEventListener(evnt, funcRef, captureBool);
						}
		}
function createBind(obj, method, arg){
				return function(){
							var ar = arg || arguments;
								return method.call(obj, ar);
							}
			}
	function Toggler(triggerElId, targetElId, trOpenVal, speed){
					this.triggerEl = (typeof(triggerElId) == "string")?document.getElementById(triggerElId):triggerElId;
					this.triggerEl.targetEl = (typeof(targetElId) == "string")?document.getElementById(targetElId):targetElId;
					this.triggerEl.targetHeight = this.triggerEl.targetEl.offsetHeight;
					this.triggerEl.targetState = 0;/*closed*/
					if(trOpenVal){
						this.triggerEl.openVal = trOpenVal;
						this.triggerEl.closedVal = this.triggerEl.innerHTML;
					}
					this.triggerEl.slideOpen = this.slideOpen;
					this.triggerEl.slideClose = this.slideClose;
					(speed)?this.triggerEl.speed = speed:this.triggerEl.speed = 50;
					this.init();
				}
			Toggler.prototype.init = function(){
					addEvent(this.triggerEl, 'click', this.toggle, false);
					this.triggerEl.targetEl.style.display = "none";
				}
			Toggler.prototype.slideOpen = function(){
					this.targetEl.style.height = "0px";
					this.targetEl.style.display = "block";
					
					var obj = this;
					var sigma = 0;
					var finalHeight = obj.targetHeight;
					var x = window.setInterval(function(){
								sigma += obj.speed;

								obj.targetEl.style.height = sigma + "px";
								if(sigma >= (finalHeight - obj.speed)){
										obj.targetEl.style.height = finalHeight + "px";
										window.clearInterval(x);
										
										if(obj.openVal){
											obj.innerHTML = obj.openVal;
										}
										obj.targetState = 1;
									}
							},5);
				}
			Toggler.prototype.slideClose = function(){				
					var obj = this;
					var sigma = obj.targetHeight;
					var finalHeight = 0;
					var x = window.setInterval(function(){
								sigma -= obj.speed;

								if(sigma<0)sigma=0;
								obj.targetEl.style.height = sigma.toString() + "px";

								if(sigma <= (finalHeight + obj.speed)){
										obj.targetEl.style.height = finalHeight + "px";
										window.clearInterval(x);
										obj.targetEl.style.display = "none";
										
										if(obj.closedVal){
											obj.innerHTML = obj.closedVal;
										}
										obj.targetState = 0;
									}
							},5);
				}
			Toggler.prototype.toggle = function(){
					var obj;
					if(window.attachEvent && typeof this.targetState == "undefined"){
							var e = e || event;
							obj = e.srcElement;
						}else{
								obj = this;
						}
						try{
						(obj.targetState)?obj.slideClose():obj.slideOpen();
					}catch(err){
							
						}
				}