var sspeed = 500;
var bdis = -100;
var acl={
divholders: {},
divgroups: {},


show:function(divids){
	if (typeof divids=="object"){
		for (var i=0; i<divids.length; i++)
			this.showhide(divids[i], "show")
	}
	else
		this.showhide(divids, "show")
},

hide:function(divids){
	if (typeof divids=="object"){
		for (var i=0; i<divids.length; i++)
			this.showhide(divids[i], "hide")
	}
	else
		this.showhide(divids, "hide")
},

toggle:function(divid){
	this.showhide(divid, "toggle")
},

addDiv:function(divid, attrstring){
	this.divholders[divid]=({id: divid, $divref: null, attrs: attrstring})
	this.divholders[divid].getAttr=function(name){
		var attr=new RegExp(name+"=([^,]+)", "i")
		return (attr.test(this.attrs) && parseInt(RegExp.$1)!=0)? RegExp.$1 : null
	}
},

showhide:function(divid, action){
	var $divref=this.divholders[divid].$divref
	if (this.divholders[divid] && $divref.length==1){
		var targetgroup=this.divgroups[$divref.attr('groupname')]
		if ($divref.attr('groupname') && targetgroup.count>1 && (action=="show" || action=="toggle" && $divref.css('display')=='none')){
			if (targetgroup.lastactivedivid && targetgroup.lastactivedivid!=divid)
				this.slideengine(targetgroup.lastactivedivid, 'hide');
				this.slideengine(divid, 'show');
				targetgroup.lastactivedivid=divid;
		}
		else{
			this.slideengine(divid, action);
			//targetgroup.lastactivedivid=divid;	
		}
	}
},

slideengine:function(divid, action){
	var $divref=this.divholders[divid].$divref
	if (this.divholders[divid] && $divref.length==1){
		var animateSetting={height: action}
		if ($divref.attr('fade'))
			animateSetting.opacity=action
		$divref.animate(animateSetting,sspeed)
		return false;
	}
	
},

init:function(){
	var ac=this
	jQuery(document).ready(function($){
		jQuery.each(ac.divholders, function(){
			this.$divref=$('#'+this.id)
			var cssdisplay=this.getAttr('hide')? 'none' : null
			this.$divref.css({height: this.getAttr('height'), display: cssdisplay})
			this.$divref.attr({groupname: this.getAttr('group'), fade: this.getAttr('fade'), speed: this.getAttr('speed')})
			if (this.getAttr('group')){
				var targetgroup=ac.divgroups[this.getAttr('group')] || (ac.divgroups[this.getAttr('group')]={})
				targetgroup.count=(targetgroup.count||0)+1
				if (!targetgroup.lastactivedivid && this.$divref.css('display')!='none' || cssdisplay=="block")							
					targetgroup.lastactivedivid=this.id
				this.$divref.css({display:'none'})
			}
		})
		jQuery.each(ac.divgroups, function(){
			if (this.lastactivedivid)
				ac.divholders[this.lastactivedivid].$divref.show()
		})
		var $allcontrols=$('*[rel]').filter('[@rel^="collapse-"], [@rel^="expand-"], [@rel^="toggle-"]')
		var controlidentifiers=/(collapse-)|(expand-)|(toggle-)/
		$allcontrols.each(function(){
			$(this).click(function(){
				var relattr=this.getAttribute('rel')
				var divid=relattr.replace(controlidentifiers, '')
				var doaction=(relattr.indexOf("collapse-")!=-1)? "hide" : (relattr.indexOf("expand-")!=-1)? "show" : "toggle"
				return ac.showhide(divid, doaction)
			})
		})

	})
}
};

$(document).ready(function(){

	acl.addDiv('loginSlider', 'hide=1, fade=1');
	acl.init();

	$(".loginSignup").click(function(){acl.toggle('loginSlider')});
	
})

