// JavaScript Document

var jsEffects = {

	queue : {},
	originalParams : {},
	
	// Nastaveni stylu
	setStyle : function(elm, key, value) { elm.style[key] = value; },
	
	// nastavi prulednost
	setOpacity : function (elm, op)
	{
	   elm.style.opacity = op;
	   elm.style.MozOpacity = op;
	   elm.style.filter = 'Alpha(opacity='+(op * 100)+')';
	},

	// zmeni pruhlednost
	changeOpacity : function (elm, inc)
	{
	   var newOp = U.getFloat(elm.style.opacity) + inc;

	   elm.style.opacity = newOp;
	   elm.style.MozOpacity = newOp;
	   elm.style.filter = 'Alpha(opacity='+(newOp * 100)+')';
	},
	
	// zmeni rozmer
	changeSize : function (elm, dimension, inc, metric)
	{
	   metric = !metric ? 'px' : metric;
		elm.style[dimension] = (U.getInt(elm.style[dimension]) + inc) + metric;
	},

	// zmeni pozici
	changeOffset : function (elm, side, inc, metric)
	{
	   metric = !metric ? 'px' : metric;
	   elm.style[side] = (U.getInt(elm.style[side]) + inc) + metric;
	},

	// testuje, je-li efekt ve fronte
	inQueue : function (elmUniqueId, effectName)
	{
	   if(typeof(this.queue[elmUniqueId]) != 'undefined')
	   {
	      return this.queue[elmUniqueId].effect == effectName;
	   }
	   else
	   {
			return false;
	   }
	},
	
	// zrusi efekt
	cancleEffect : function(uId, callback, effect)
	{
	   try {
			Interval.remove(uId + effect);
			delete this.queue[uId];
			if(callback)
				eval(callback);
		} catch(e) {}
	},
	
	
	// opona
	Curtain : {

		curtainIds : new Array(),
	   
	   create : function(color, parent, settings)
	   {
			var elm = document.createElement('DIV');

			var inc = 0;
			if(!parent) parent = document.body;

			parent.appendChild(elm);
			
			if(!color) color = 'black';

			if(settings == null) settings = {};
			if(typeof(settings['left']) == 'undefined') settings['left'] = 0;
			if(typeof(settings['top']) == 'undefined') settings['top'] = 0;

			elm.id = uId(elm);
			jsEffects.Curtain.curtainIds.unshift(uId(elm));
			elm.style.position = 'absolute';
			elm.style.left = settings.left + 'px';
			elm.style.top = settings.top + 'px';
			elm.style.backgroundColor = color;
			elm.style.zIndex = '1000';

			width = U.getWidth(parent);
			height = U.getHeight(parent);
			
			if(parent == document.body)
			{
			   width = width < U.getWindowWidth() ? U.getWindowWidth() : width;
				height = height < U.getWindowHeight() ? U.getWindowHeight() : height;
   		}

			elm.style.width = width + 'px';
			elm.style.height = height + 'px';

			jsEffects.setOpacity(elm, 0);
			jsEffects.fadeIn(elm.id, {speed: 5, inc: 0.3, target: 0.9 });
	   },

		destroy : function()
		{
		   if(jsEffects.Curtain.curtainIds.length)
			{
				var tmpId = jsEffects.Curtain.curtainIds.shift();
				var cl = '$(\''+tmpId+'\').parentNode.removeChild($(\''+tmpId+'\'));';

				jsEffects.fadeOut(tmpId, {speed: 5, inc: 0.3, callback: cl });
			   return true;
			}
			
			return null;
		},
		
		getId : function()
		{
		   return jsEffects.Curtain.curtainIds[jsEffects.Curtain.curtainIds.length - 1];
		},
		
		updateSize : function(width, height, parent)
		{
		   var tmpId = this.getId();

			width = width < parent.scrollWidth ? parent.scrollWidth : width;
			height = height < parent.scrollHeight ? parent.scrollHeight : height;
			height += 8;

			$(tmpId).style.width = width + 'px';
			$(tmpId).style.height = height + 'px';
		}
	},
	
	// necha objevit element
	fadeIn : function (elmId, settings, inProcess)
	{
		var elm = $(elmId);
		
		var inc = typeof settings.inc != 'undefined' ? settings.inc : 0.01;
		var speed = typeof settings.speed != 'undefined' ? settings.speed : 5;
		var target = typeof settings.target != 'undefined' ? settings.target : 1;
		var callback = typeof settings.callback != 'undefined' ? settings.callback : null;

		if(!inProcess)
		{
			if(this.inQueue(uId(elm), 'fadeOut')) this.cancleEffect(uId(elm), null, 'FadeOut');

			if(!this.inQueue(uId(elm), 'fadeIn'))
			{
			   this.queue[uId(elm)] = {
			      effect : 'fadeIn',
					interval : null
			   };

				var sett = '{ inc : '+inc+', speed : '+speed+', callback : "'+callback+'", target : '+target+' }';
			   //this.queue[uId(elm)].interval = window.setInterval('jsEffects.fadeIn("'+elmId+'", '+sett+', true)', speed);
			   Interval.add(uId(elm)+'FadeIn', 'jsEffects.fadeIn("'+elmId+'", '+sett+', true)', 1);
			}
			else
			{
			   return;
			}
		}
		else
		{
		   try
			{
			   if(U.getFloat(elm.style.opacity) + inc >= target)
			   {
					this.setOpacity(elm, target);
					this.cancleEffect(uId(elm), callback, 'FadeIn');
				}
				else
				{
				  	this.changeOpacity(elm, inc);
				}
			} catch(e){	}
		}
	},
	
	// necha zmizet element
	fadeOut : function (elmId, settings, inProcess)
	{
		var elm = $(elmId);
		
  		var inc = typeof settings.inc != 'undefined' ? settings.inc : 0.01;
		var speed = typeof settings.speed != 'undefined' ? settings.speed : 5;
		var target = typeof settings.target != 'undefined' ? settings.target : 0;
		var callback = typeof settings.callback != 'undefined' ? settings.callback : null;

		if(!inProcess)
		{
			if(this.inQueue(uId(elm), 'fadeIn')) this.cancleEffect(uId(elm), null, 'FadeIn');

			if(!this.inQueue(uId(elm), 'fadeOut'))
			{
			   this.queue[uId(elm)] = {
			      effect : 'fadeOut',
					interval : null
			   };

			   var op = parseFloat(elm.style.opacity);
			   op = isNaN(op) ? 1 : op;
		      this.setOpacity(elm, op);

				var sett = '{ inc : '+inc+', speed : '+speed+', callback : "'+callback+'", target : '+target+' }';
			   Interval.add(uId(elm)+'FadeOut', 'jsEffects.fadeOut("'+elmId+'", '+sett+', true)', 1);
			}
			else
			{
			   return;
			}
		}
		else
		{
		   if(U.getFloat(elm.style.opacity) - inc <= target)
		   {
				this.setOpacity(elm, target);
				this.cancleEffect(uId(elm), callback, 'FadeOut');
			}
			else
			{
			  	this.changeOpacity(elm, -inc);
			}
		}
	},
	

	end : null
}














/*
var jsEffects = {

	// zmensi element na nulovou velikost
	collapse : function (elmId, dir, speed, inProcess)
	{
	   var elm = $(elmId);
	   var setOriginalParams = true;
	
	   if(!inProcess)
	   {
	      if(this.inQueue(uId(elm), 'expand'))
	      {
	         this.cancleEffect(uId(elm));
	         setOriginalParams = false;
	      }

			if(!this.inQueue(uId(elm), 'collapse') && elm.style.display != 'hidden')
			{
			   this.queue[uId(elm)] = {
			      effect : 'collapse',
			      interval : null
			   };
			   
			   if(setOriginalParams)
			   {
			      if(typeof(this.originalParams[uId(elm)]) == 'undefined')
			         this.originalParams[uId(elm)] = {};
			   
				   this.originalParams[uId(elm)].width = this.getWidth(elm),
					this.originalParams[uId(elm)].height = this.getHeight(elm)
				   
				   elm.style.width = this.originalParams[uId(elm)].width;
			   	elm.style.height = this.originalParams[uId(elm)].height;
				}

			   //elm.style.overflow = 'hidden';
			   
			   this.queue[uId(elm)].interval = window.setInterval('jsEffects.collapse("'+elmId+'", "'+dir+'", '+speed+', true)', speed);
			}
			else
			{
				return;
			}
	   }
	   else
	   {
	      var k;
	      
  	      switch(dir)
	      {
				case 'N': case 'S': dimensionList = ['height']; break;
				case 'E': case 'W': dimensionList = ['width']; break;
				case 'NE': case 'SE': case 'NW': case 'SW': dimensionList = ['height','width']; break;
	      }
	      
	      if(dir.indexOf('E') != -1 && this.toNum(elm.style.width) > 1)
	         this.changeOffset(elm, 'left', 2);
			if(dir.indexOf('S') != -1 && this.toNum(elm.style.height) > 1)
				this.changeOffset(elm, 'top', 2);

			for(k in dimensionList)
			{
    			if(this.toNum(elm.style[dimensionList[k]]) <= 3)
            	this.setSize(elm, dimensionList[k], '1px');
		      else
			      this.changeSize(elm, dimensionList[k], -3);
			}
			
			if((dimensionList.length == 2 && this.toNum(elm.style.width) == 1 && this.toNum(elm.style.height) == 1) || (dimensionList.length == 1 && this.toNum(elm.style[dimensionList[0]]) == 1))
			{
			   elm.style.display = 'none';
				this.cancleEffect(uId(elm));
			}
	   }
	},
	
	// zvetsi element do puvodni velikosti
	expand : function (elmId, dir, speed, inProcess)
	{
		var elm = $(elmId);

		if(!inProcess)
	   {
	      if(this.inQueue(uId(elm), 'collapse'))
	      {
	         this.cancleEffect(uId(elm));
	      }
	   
			if(!this.inQueue(uId(elm), 'expand'))
			{
			   this.queue[uId(elm)] = {
			      effect : 'expand',
			      interval : null
			   };

				elm.style.display = '';

			   this.queue[uId(elm)].interval = window.setInterval('jsEffects.expand("'+elmId+'", "'+dir+'", '+speed+', true)', speed);
			}
			else
			{
				return;
			}
	   }
	   else
	   {
	      var dimension;
	      
	      var maxW = this.originalParams[uId(elm)].width;
	      var maxH = this.originalParams[uId(elm)].height;
	      
	      var cW = this.toNum(elm.style.width);
	      var cH = this.toNum(elm.style.height);

			switch(dir)
	      {
				case 'N': case 'S': dimensionList = ['height']; break;
				case 'E': case 'W': dimensionList = ['width']; break;
				case 'NE': case 'SE': case 'NW': case 'SW': dimensionList = ['height','width']; break;
	      }

	      if(dir.indexOf('E') != -1 && cW < maxW)
	         this.changeOffset(elm, 'left', -2);
			if(dir.indexOf('S') != -1 && cH < maxH)
				this.changeOffset(elm, 'top', -2);

			for(k in dimensionList)
			{
    			if(this.toNum(elm.style[dimensionList[k]]) >= this.originalParams[uId(elm)][dimensionList[k]])
            	this.setSize(elm, dimensionList[k], this.originalParams[uId(elm)][dimensionList[k]]+'px');
		      else
			      this.changeSize(elm, dimensionList[k], 2);
			}

			if((dimensionList.length == 2 && this.toNum(elm.style.width) == this.originalParams[uId(elm)].width && this.toNum(elm.style.height) == this.originalParams[uId(elm)].height) || (dimensionList.length == 1 && this.toNum(elm.style[dimensionList[0]]) == this.originalParams[uId(elm)][dimensionList[0]]))
			{
				this.cancleEffect(uId(elm));
			}
	   }
	},
	
	
	
	
	
	blb : ''
}

*/















