/*
# ------------------------------------------------------------------------
# JA Top Panel module
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license - PHP files are GNU/GPL V2. CSS / JS are Copyrighted Commercial,
# bound by Proprietary License of JoomlArt. For details on licensing, 
# Please Read Terms of Use at http://www.joomlart.com/terms_of_use.html.
# Author: JoomlArt.com
# Websites:  http://www.joomlart.com -  http://www.joomlancers.com
# Redistribution, Modification or Re-licensing of this file in part of full, 
# is bound by the License applied. 
# ------------------------------------------------------------------------
*/
var JAToppanel = new Class({	
	initialize: function(element, options) {
		this.options = $extend({
			duration: 1000,
			auto: 0,
			delay: 0,
			overlay: 0
		}, options || {});
		
		this.el = $(element);
		this.el.getParent().getParent().setStyle('position', 'relative');
		this.el.getParent().getParent().getParent().setStyle('position', 'relative');
		this.panel = this.el.getElement('div.ja-toppanel-panels');
		this.wraper = this.el.getElement('div.ja-toppanel-wraper');
		
		this.content = this.el.getElement('div.ja-toppanel-content');
		this.button = this.el.getElement('div.ja-toppanel-button-wraper');
		if($('ja-toppanel-Overlay')==null){
			this.overlay = new Element('div', {'id': 'ja-toppanel-Overlay'});	
			this.overlay.inject($(document.body));
		}
		
		this.overlay.setStyles({'display':'block', 'visibility':'hidden'});
		
		this.el.setStyle('display', 'block');
		this.button.getElement('div.ja-toppanel-button-subwap').setStyle('left', this.panel.offsetWidth/2 - this.button.getElement('div.ja-toppanel-button-subwap').offsetWidth/2);
		
		if (!this.myslider) {
			this.myslider = new Fx.Slide(this.wraper, {duration: this.options.duration, open:true});
		}		
		this.myslider.hide ();
		
		if(!this.overlayFx  && this.options.overlay){
			this.overlayFx = new Fx.Styles(this.overlay, {duration: 500});
		}
		
		if(this.options.auto){
			$clear(this.timer);
			this.timmer = this.openPanel.delay(this.options.delay, this);
		}
		
		this.button.getElement('div.ja-toppanel-button-subwap').addEvent('click', function(){
			this.myslider.toggle();
			
			$$("input[name='dontshowagain']").each(function(el){
				$(el.id).addEvent('click', function(){
					if(this.checked){
						Cookie.set('jatoppanel_dontshowagain'+this.value, 1, {duration: 3});
					} else {
						Cookie.remove('jatoppanel_dontshowagain'+this.value);
					}
				});
			});	
			
			if(this.options.overlay){
				if(this.overlay.getStyle('visibility')=='hidden'){
					this.overlayFx.start({
						'height': [0, window.getSize().scrollSize['y'] + this.content.offsetHeight],
						'opacity': [0, 0.7]
					});
				}
				else{
					this.overlayFx.start({
						'height': [this.overlay.offsetHeight, 0],
						'opacity': [0.7, 0]
					});
				}			
			}
		}.bind(this));
		
		this.close = this.content.getElement('span.ja-toppanel-close');
		if(this.close!=null){
			this.close.addEvent('click', function(){
				this.myslider.slideOut();
				this.myslider.slideIn();
				
				if(this.options.overlay){
					this.overlayFx.start({
						'height': [this.overlay.offsetHeight, 0],
						'opacity': [0.7, 0]
					});
				}
			}.bind(this));
		}
		
	},
	
	openPanel: function(){
		this.myslider.slideIn();
		this.myslider.slideOut();		
		if(this.options.overlay){
			this.overlayFx.start({
				'height': [0, window.getSize().scrollSize['y'] + this.content.offsetHeight],
				'opacity': [0, 0.7]
			});
		}
	}
});
