/**
 *  financetv.SlideDialog
 *  Konstruktor pro slajdovací dialogová okna
 */

var studenta = window.studenta = window.studenta || {};

studenta.SlideDialog = function(options)
{
	this.options = $.extend({ 
		alignTo: null,
		axis: 'y',
		speedDown: 200,
		speedUp: 200,
		easeDown: 'linear',
		easeUp: 'linear'
	}, options);
	
	this.animProperty = this.options.axis == 'y' ? 'height' : 'width'; 	
};

studenta.SlideDialog.shown = null;

studenta.SlideDialog.prototype.init = function()
{
	var that = this;
	this.$element = $(this.options.element).css({ position: 'absolute', left: -9999, top: -9999 }).appendTo('body');
	this.$innerWrap = this.$element.find('.popover-box-inner-wrap');
	this.dims = {
		height: this.$innerWrap.outerHeight(true),
		width: this.$innerWrap.outerWidth(true)
	};
	this.$innerWrap.css({ position: 'absolute', bottom: '0', left: '0' }).css(this.dims);
	this.$element.find('.popover-close').bind('click', function(event){ that.hide(); return false; });
	this.$element.bind('contentChange', $.proxy(this.redraw, this));
	$(document).bind('click', $.proxy(this.documentClick, this));	
	if($.browser.msie)
	{
	/*
		this.$iframeMask = $('<iframe />');
		this.$iframeMask.appendTo(this.$element).css({ 
			position: 'absolute', 
			bottom: 0,
			left: 0,
			background: '#fff',
			border: '0',
			filter: 'alpha(opacity=0)', 
			opacity: 0
		}).css(this.dims);
	*/
	}
	
};

studenta.SlideDialog.prototype.documentClick = function(event)
{
	if($(event.target).closest('.popover-box').length == 0) this.hide();
};

studenta.SlideDialog.prototype.resize = function()
{
	this.$innerWrap.css({ width: 'auto', height: 'auto' });
	this.dims = {
		height: this.$innerWrap.outerHeight(true),
		width: this.$innerWrap.outerWidth(true)
	};
	this.$innerWrap.css(this.dims);
};

studenta.SlideDialog.prototype.redraw = function()
{
	this.resize();
	var css = {};
	css[this.animProperty] = this.dims[this.animProperty];	
	this.$element.css(css);
};

studenta.SlideDialog.prototype.show = function()
{
	if(studenta.SlideDialog.shown != null && studenta.SlideDialog.shown != this) studenta.SlideDialog.shown.hide();
	this.$element.css(this.dims);

	var anim = {};
	anim[this.animProperty] = this.dims[this.animProperty];
	
	var css = {};
	css[this.animProperty] = 0;
	
	this.$element.css(css).animate(anim, this.options.speedDown, this.options.easeDown);
	studenta.SlideDialog.shown = this;
};

studenta.SlideDialog.prototype.hide = function()
{
	var anim = {};
	anim[this.animProperty] = 0;

	this.$element.animate(anim, this.options.speedUp, this.options.easeUp);
	studenta.SlideDialog.shown = null;
};

studenta.SlideDialog.prototype.toggle = function()
{
	if(studenta.SlideDialog.shown == this) this.hide();
	else this.show();
};

