// Regularni vyrazy
var REGEXP_IE        = /MSIE/gi;
var REGEXP_IE6 		= /MSIE 6\.0/gi;
var REGEXP_IE7       = /MSIE 7\.0/gi;
var REGEXP_NS        = /Gecko/gi;
var REGEXP_OPERA     = /Opera/gi;
var REGEXP_CHROME    = /Chrome/gi;
var REGEXP_VISTA     = /Windows NT 6\.0/gi;
var REGEXP_NBSP 		= /([\w012345678910111213141516171819202122232425262728293031323334353637])&nbsp;([\w012345678910111213141516171819202122232425262728293031323334353637])/gi;
var REGEXP_EMAIL 		= /^(mailto:)?[a-zA-Z0-9_\.-]{1,50}@([a-z0-9-]{1,63}\.){1,}[a-z]{2,}$/;
var REGEXP_URL 		= /^((http|https|ftp):\/\/)?(([a-z0-9-]+\.)+[a-z]{2,})(\/|\/.+|)$/;

var isIE    	= navigator.userAgent.match(REGEXP_IE);
var isIE6		= navigator.userAgent.match(REGEXP_IE6);
var isIE7 		= navigator.userAgent.match(REGEXP_IE7);
var isNS   		= navigator.userAgent.match(REGEXP_NS);
var isOpera	 	= navigator.userAgent.match(REGEXP_OPERA);
var isChrome   = navigator.userAgent.match(REGEXP_CHROME);
var isVista 	= navigator.userAgent.match(REGEXP_VISTA);
var isXP    	= !isVista;

// klavesy
var KEY_BACKSPACE    = 8;
var KEY_ENTER		 	= 13;
var KEY_SHIFT		  	= 16;
var KEY_CTRL  			= 17;
var KEY_ALT   			= 18;
var KEY_ESC    		= 27;
var KEY_SPACE        = 32;
var KEY_LEFT   		= 37;
var KEY_UP     		= 38;
var KEY_RIGHT			= 39;
var KEY_DOWN			= 40;
var KEY_DEL    		= 46;
var KEY_AZ    			= [65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90];
var KEY_09     		= [48, 49, 50, 51, 52, 53, 54, 55, 56, 57];

// property uniqueID pro vsechny prohlizece =========================== //
																				  				//
function uId(elm)                                             				//
{                                                             				//
	if(!elm.uniqueID)                                          				//
	{                                                          				//
		var date = new Date();                                  				//
	   elm.uniqueID = 'E' + Math.ceil(date.getTime() * Math.random());	//
	}                                                          				//
																				  				//
	return elm.uniqueID;                                       				//
}                                                             				//
// ==================================================================== //

var $ = function(elmId)
{
	return document.getElementById(elmId);
}

U = {
	'getFncName' : function(fnc)
	{
		var fncString = fnc.toString();
		var match = /^function ([^\(]+)\(/.exec(fncString);

		if(typeof(match[1]) != 'undefined')
		   return match[1];
		else
		   return '';
	},

	'getInt' : function(val)
	{
 		try {
			val = parseInt(val.toString().replace(/^0*/, ''));
		} catch(e) {
			val = 0;
		}

		return isNaN(val) ? 0 : val;
	},
	
	'getFloat' : function(val)
	{
	   try {
			val = parseFloat(val.toString().replace(/^0*/, ''));
		} catch(e) {
			val = 0;
		}

		return isNaN(val) ? 0 : val;
	},

	'setEvent' : function(obj, event, fnc)
	{
		try {
			obj.attachEvent(event, fnc);
		} catch (e) {
			obj.setAttribute(event, this.getFncName(fnc)+'(event)');
		}
	},

	'resetEvent' : function(obj, event, fnc)
	{
	   try {
	      obj.detachEvent(event, fnc);
	   } catch (e) {
	      obj.setAttribute(event, '');
	   }
	},
	
	'getCookie' : function(name)
	{
		var value = null;

		cookies = document.cookie.split(/; ?/);
		for(id in cookies)
		{
			var pair = cookies[id].split(/=/);
	      if(pair[0] == name)
			   return pair[1];
		}

		return null;
	},
	
	'rgb2hex' : function(rgb)
	{
		var dec2hex = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'];

		var hex = '#';
		var tmp;

		if(rgb[0] > 255 || rgb[1] > 255 || rgb[2] > 255)
		   return null;

		for(i = 0; i < 3; i++)
		{
	 	   tmp = dec2hex[Math.floor(rgb[i] / 16)].toString();
		   tmp += dec2hex[rgb[i] % 16].toString();
			hex += tmp;
		}

		return hex;
	},
	
	// ziska sirku elementu
	'getWidth' : function(elm)
	{
	   try {
      	var w = document.defaultView.getComputedStyle(elm, '').getPropertyValue('width');
		}
	   catch(e) {
	   	var w = elm.offsetWidth;
		}

		return this.getInt(w);
	},

	// ziska vysku elementu
	'getHeight' : function(elm)
	{
	   try {
      	var h = document.defaultView.getComputedStyle(elm, '').getPropertyValue('height');
		}
	   catch(e) {
	   	var h = elm.offsetHeight;
		}

		return this.getInt(h);
	},
	
	'getWindowWidth' : function()
	{
		if(window.innerWidth)    /* NN4 a kompatibilni prohlizece */
	      return window.innerWidth;
	   else if(document.documentElement && document.documentElement.clientWidth) /* >= MSIE6 v std. rezimu */
	      return document.documentElement.clientWidth;
	   else if(document.body && document.body.clientWidth) /* starsi MSIE + MSIE6 v quirk rezimu */
	      return document.body.clientWidth;
	   else
	      return 0;
	},
	
	'getWindowHeight' : function()
	{
		if(window.innerHeight)    /* NN4 a kompatibilni prohlizece */
	      return window.innerHeight;
	   else if(document.documentElement && document.documentElement.clientHeight) /* >= MSIE6 v std. rezimu */
	      return document.documentElement.clientHeight;
	   else if(document.body && document.body.clientHeight) /* starsi MSIE + MSIE6 v quirk rezimu */
	      return document.body.clientHeight;
	   else
	      return 0;
	},
	
	'isChildrenOf' : function(object, parentTag, returnElement)
	{
		var parent;

		try {
		   parent = object.parentElement();
		} catch (e) {
			try {
			   parent = object.parentElement;
			} catch (e) {
			   return returnElement ? document.body : false;
			}
		}
		
		try {
		   parent.tagName;
		} catch(e) {
		   return returnElement ? document.body : false;
		}

		while(parent.tagName != 'BODY' && parent.tagName != parentTag)
		{
			parent = parent.parentElement;
		}

		if(parent.tagName == parentTag)
		   return returnElement ? parent : true;
		else
		   return returnElement ? parent : false;
	},
	
	centerElement : function(elm)
	{
	   width = U.getWindowWidth();
	   height = U.getWindowHeight();
	
	   elm.style.left = Math.round(width / 2 - this.getWidth(elm) / 2) + 'px';
	   elm.style.top = Math.round(height / 2 - this.getHeight(elm) / 2) + 'px';
	},

	showChildren : function(elm)
	{
		if(elm.childNodes.length)
		{
		   for(i = 0; i < elm.childNodes.length; i++)
		   {
		      if(elm.childNodes[i].childNodes.length)
					this.showChildren(elm.childNodes[i]);
				else
				{
				   try {
						elm.childNodes[i].style.display = '';
					} catch(e) {}
				}
		   }
		}
		
		elm.style.display = '';
	},
	
	hideChildren : function(elm)
	{
		if(elm.childNodes.length)
		{
		   for(i = 0; i < elm.childNodes.length; i++)
		   {
		      if(elm.childNodes[i].childNodes.length)
					this.hideChildren(elm.childNodes[i]);
				else
				{
				   try {
						elm.childNodes[i].style.display = 'none';
					} catch(e) {}
				}
		   }
		}

		elm.style.display = 'none';
	}
}

var Interval = {

	interval : 0,
	counter : 0,
	state : 'stoped',
	
	list : {},
	count : 0,
	
	add : function(id, callback, everyX)
	{
	   if(!id || !callback || typeof Interval.list[id] != 'undefined')
	      return;
	      
		if(!everyX) everyX = 1;
		
		Interval.list[id] = {
		   callback : callback,
		   everyX : everyX
		}
		
		Interval.count++;
		if(Interval.state == 'stoped')
		{
		   if(Interval.interval != 0)
		      window.clearInterval(Interval.interval);

			Interval.state = 'running';
			Interval.interval = window.setInterval('Interval.run()', 25);
		}
	},
	
   remove : function(id)
   {
   	if(typeof Interval.list[id] != 'undefined')
      {
	      delete Interval.list[id];
	      Interval.count--;
	   }
   },
	
	run : function()
	{
	   if(!Interval.count)
	   {
	      Interval.end(Interval.interval);
		}
		else
		{
		   Interval.counter++;
		   var ix;
		   for(ix in Interval.list)
		   {
				if(!(Interval.counter % Interval.list[ix].everyX))
		         eval(Interval.list[ix].callback);
		   }
		}
	},
	
	end : function(interval)
	{
		Interval.list = {};
	   Interval.count = 0;
	   Interval.couter = 0;
	   Interval.state = 'stoped';
	   
	   window.clearInterval(interval);
	   Interval.interval = 0;
	}
}





