///////////////////////////////////////////
/// BROWSERS EVENT MODEL FIX
/// CREATED BY MICHAEL KUSYN , @2003
/// v0.5  
/// Do not remove this lines
///////////////////////////////////////////


// function, which id doing capturing & bubbling of event
// *

function makeIE(event)
{

        /// Ktery element je cilem udalosti ?
	element = event.srcElement;

	// Pridejme objektu EVENT standardni parametry
	// *
	event.target = event.srcElement;
	event.relatedTarget = (event.type == 'mouseover' ? event.fromElement : event.type == 'mouseout' ? event.toElement : null);
	event.currentTarget = element;
	event.bubbles = true;
	event.cancelable = true;
	event.stop = false;
	event.preventDefault = function() { event.returnValue = false; return false;}
	event.stopPropagation = function() { event.stop = true; event.cancelBubble = true;}
	d = new Date()
	event.timeStamp = d.valueOf();

	toBubble = new Array();
	toCapture = new Array();		


        // Kterym elementum budeme ohlasovat vznik udalosti ?
	temp = element.parentNode;
	while(temp)
	{
		if(temp.bubbles[event.type])toBubble = toBubble.concat(temp.bubbles[event.type]);
		if(temp.captures[event.type])toCapture = toCapture.concat(temp.captures[event.type]);

		if(temp.nodeName == "HTML") {temp = document;}
		else {temp = temp.parentNode;}
	}


	/// Vyvolame fce zachytavane udalosti
	event.eventPhase=1;
	for(x=toCapture.length-1; (x>=0 && (event.stop==false || event.stop==true && event.currentTarget==toCapture[x])); x=x-2)
	{
		 event.currentTarget = toCapture[x];
		 toCapture[x-1](event);
	}

	/// Vyvolame fce na targetu
	event.eventPhase=2;
	if(element.bubbles[event.type])
	for(x=0; (x<element.bubbles[event.type].length && (event.stop==false || event.stop==true && event.currentTarget==element.bubbles[event.type][x+1])); x=x+2) 
	{
		event.currentTarget = element.bubbles[event.type][x+1];
		element.bubbles[event.type][x](event);	
	}

	/// Vyvolame fce bubblajici udalosti
	event.eventPhase=3;
	for(x=0; (x<toBubble.length && (event.stop==false || event.stop==true && event.currentTarget==toBubble[x+1])); x=x+2) 
	{
 		event.currentTarget = toBubble[x+1];
		toBubble[x](event);
	}

	// Nebublej at se tyto kroky zase neopakujou
	event.cancelBubble = true;
	return false;
}       
 

// Create new add/removeEventListener to all IE elements
// *

function fixElement(elm)
{if (elm.id!="flash")
{
	if(document.all && !document.addEventListener)
	{
	        /// Fix IE
		
		elm.captures = new Array();
		elm.bubbles  = new Array();
		elm.addEventListener = function(handle, fce, typ)
		{
			
			if(!this.captures[handle]) this.captures[handle]=new Array();
			if(!this.bubbles[handle]) this.bubbles[handle]=new Array();
			
			/// Fyzicky registruj posluchac
			if(this.captures[handle].length==0 && this.bubbles[handle].length==0) 
			eval("this.attachEvent(\"on\"+handle, makeIE);");


			/// Vloz do matice odkaz na funkci
                   	if(typ)
			{this.captures[handle][this.captures[handle].length] = fce; this.captures[handle][this.captures[handle].length] = this;}
			else 
			{this.bubbles[handle][this.bubbles[handle].length] = fce; this.bubbles[handle][this.bubbles[handle].length] = this;}

		}

		elm.removeEventListener = function(handle, fce, typ)
		{
			
			if(this.captures[handle] || this.bubbles[handle])  
			{
				(typ==true)? pole = this.captures[handle] : pole = this.bubbles[handle];
				
                                /// Najdi v radku nazev funkce kterou chces odsranit
				x = 0;
				while(pole[x]!=fce && x<pole.length)
				{
					x = x+2;
				}

                                /// Odstran funkce z matice
 				if(x<pole.length)
				{
					temp = new Array();
					temp = temp.concat(pole);
		
					temp[x] = "del"; temp[x+1] = "del";
					pole = new Array();					 
					
					z = 0;
					for(x=0; x<temp.length; ++x)
					if(temp[x]!="del")
					{pole[z] = temp[x];++z;}
				}

				(typ==true)? this.captures[handle]=pole : this.bubbles[handle]=pole;

                                /// Nejsou-li k danemu typu udalosti zadne prvky v maticich, zruz fyzicky posluchac
				if(this.captures[handle].length==0 && this.bubbles[handle].length==0) eval("this.detachEvent(\"on\"+handle, makeIE);");										
			}
		}
	}
	else
	{
	        /// Fix Mozilla

		elm.addEventListener2 = elm.addEventListener;
		elm.removeEventListener2 = elm.removeEventListener;
		
		elm.addEventListener = function(what, co, typ)
		{
  		 str = "" + co;
		 str = str.match(/function ([^(]+)/, str)[1];
                
		 if(typ)
		 {
	  		 eval("elm.temp"+str+"=new Function(\"event\",\"if( (event.target == event.currentTarget) ) {} else {"+str+"(event);}\");");
		 }
		 else
		 {
  			 eval("elm.temp"+str+"=new Function(\"event\",\""+str+"(event);\");");
		 }
  		       
		 eval("this.addEventListener2('"+what+"', elm.temp"+str+", typ);");
	 	 }
                
		elm.removeEventListener = function(what, co, typ)
		{
  			 str = "" + co;
			 str = str.match(/function ([^(]+)/, str)[1];

  		 eval("if(elm.temp"+str+"){this.removeEventListener2('"+what+"', elm.temp"+str+", typ);}");			
		}
	}
	}
}

function fixAllElements()
{
 	
        all = new Array();
	if(document.all) {q=document.all;} else {q = document.getElementsByTagName('*');}

	for(x=0; x<q.length; ++x)
	all[x] = q[x];
	all[all.length] = document;        
	for(x=0; x<all.length; ++x){
	fixElement(all[x]);   }


}

