//////////////////////////////////////////////////////////////
// js_slider
// By Alons
// Please Read the Terms of use at http://www.softaculous.com
// (c)Softaculous Inc.
//////////////////////////////////////////////////////////////

function slideitout(elid, endheight, inc, time){
	startheight = $(elid).offsetHeight + inc;
	if(startheight < endheight){
		diff = endheight - startheight;
		if(diff > inc){
			$(elid).style.height = startheight+"px";
			setTimeout('slideitout(\''+elid+'\', '+endheight+', '+inc+', '+time+');', time);
		}else{
			$(elid).style.height = endheight+"px";
		}
	}
};

function pullitin(elid, dec, time){
	height = $(elid).offsetHeight - dec;
	if(height > dec){
		$(elid).style.height = height+"px";
		setTimeout('pullitin(\''+elid+'\', '+dec+', '+time+');', time);
	}else{
		$(elid).style.height = "1px"; //A bug in IE 5.5
	}
};

function slider(){
	this.speed = 20;
	this.img_collapsed = imgurl+'collapsed.gif';
	this.img_expanded = imgurl+'expanded.gif';
	this.elements = new Array();
	
	this.slide = function(id){
		var height = $(id).offsetHeight;
		if(height > 1){
			this.collapse(id);
		}else{
			this.expand(id);
		}
	};
	
	this.expand = function(id){
		slideitout(id, $('t'+id).offsetHeight, this.speed, 1);
		$('i'+id).src = this.img_expanded;
		setcookie(id, '1', 365);
	};
	
	this.collapse = function(id){
		pullitin(id, this.speed, 1);
		$('i'+id).src = this.img_collapsed;
		removecookie(id);
	};
	
	//Init it
	this.init = function(){	
		var elements = this.elements;
		for(id in elements){
			if(getcookie(elements[id]) == 1){
				$(elements[id]).style.height = $('t'+elements[id]).offsetHeight+"px";
				$('i'+elements[id]).src = this.img_expanded;
			}
		}
	};
	
	this.expandAll = function(){
		var elements = this.elements;
		for(key in elements){
			id = elements[key];
			this.expand(id);
		}
	};
	
	this.collapseAll = function(){
		var elements = this.elements;
		for(key in elements){
			id = elements[key];
			this.collapse(id);
		}
	};
};