/*
# ------------------------------------------------------------------------
# JA Cpanel module for Joomla 1.5
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

var JACPanel = new Class({
	initialize: function(cpid, options){
		//this.options = Object.extend({
		this.options = $extend({
			width: 0,
			height: 0,
			dir: 'down',
			status: 'hide',
			duration: 400
		}, options || {});
		this.cpanel = $(cpid);
		this.cpanel_switcher = $(cpid+'-switcher');
		if (!this.cpanel || !this.cpanel_switcher) return;
		if (!this.options.width) this.options.width = this.cpanel.offsetWidth;
		if (!this.options.height) this.options.height = this.cpanel.offsetHeight;
		this.cpanel.setStyles ({
			'height': this.options.height,
			'width': this.options.width,
			'overflow': 'hidden'
		});
		
		this.status = Cookie.get ('jacpanel-'+cpid);
		if (!this.status) this.status = this.options.status;
		if (this.status == 'hide') {
			if (this.options.dir=='down' || this.options.dir=='up') {
				this.cpanel.setStyle ('height', 0);
			} else {
				this.cpanel.setStyle ('width', 0);
			}
			this.cpanel_switcher.addClass('show');
		} else
			this.cpanel_switcher.addClass('hide');
		
		this.fx = new Fx.Styles (this.cpanel, {'duration': this.options.duration});
		
		this.cpanel_switcher.addEvent ('click', function(){
			if (this.status == 'hide') {
				this.status = 'show';
				this.fx.stop();
				var obj = {};
				if (this.options.dir=='down' || this.options.dir=='up') {
					obj.height = [0, this.options.height];
				} else {
					obj.width = [0, this.options.width];
				}
				obj.opacity = [0,1];
				this.fx.start (obj);
				this.cpanel_switcher.removeClass ('show');
				this.cpanel_switcher.addClass ('hide');
			} else {
				this.status = 'hide';
				this.fx.stop();
				var obj = {};
				if (this.options.dir=='down' || this.options.dir=='up') {
					obj.height = [this.options.height, 0];
				} else {
					obj.width = [this.options.width, 0];
				}
				obj.opacity = [1, 0];
				this.fx.start (obj);
				this.cpanel_switcher.removeClass ('hide');
				this.cpanel_switcher.addClass ('show');
			}
			return false;
		}.bind(this));
		this.cpanel.setStyle('visibility', 'visible');
	}
	
});
