function addLoadEvent(func) 
{
    var oldonload = window.onload;
    if (typeof window.onload != 'function') 
    {
        window.onload = func;
    } 
    else 
    {
        window.onload = function() 
        {
            oldonload();
            func();
        }
    }
}

/*var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  //window.status =" X:"+ tempX +" Y:"+tempY
  //document.Show.MouseY.value = 
  return true
}*/
	var first=1;
	var smer_1=1;
	var oldx; 
	var stevec=0;
	var sirina=0;
	var stop_slider_g=1;
	function moveSlideshow(elementID,smer,interval) 
	{
		if (!document.getElementById)
			return false;
		final_x=slideshow_set.offsetWidth;
		// if the element does not exist we have nothing to do
		if (!document.getElementById(elementID))
			return false;
		var elem = document.getElementById(elementID);

		// the slideshow events stack up and the animation is not smooth anymore
		if (elem.movement) 
		{
			clearTimeout(elem.movement);
		}
		
		if(stop_slider_g==1)
		{
			stop_slider_g=0;
			return;
		}
		stevec++;
		if(stevec==50)
		{
			//alert(parseInt(elem.style.left)+":: "+-(sirina/2));
			stevec=0;
		}
		
		//�e je pri�el do konca na levi
		if(smer=="left")
			if(parseInt(elem.style.left)>0)
				elem.style.left = -(sirina/3)+ "px";
		
		//�e je pri�el do konca na desni
		if(smer=="right")
			if(parseInt(elem.style.left)<-((sirina/3)*2))
				elem.style.left = -(sirina/3)+ "px";	
		
		g=2;
		
		/*if(oldx<tempX)		
			g=g+10;
			
		if(oldx>tempX)		
			g=g-10;
			
			
		oldx=tempX;
		
		if(g>50)
		g=50;
		
		if(g<3)
		g=3;*/
		// current slideshow position
			
		if(smer=="right")
			elem.style.left = (parseInt(elem.style.left) - g)+ "px";
		else
			elem.style.left = (parseInt(elem.style.left) + g)+ "px";
		
		
		// and set up the event again after an interval
		var repeat = "moveSlideshow('"+elementID+"','"+smer+"',1)";
		elem.movement = setTimeout(repeat,interval);
	}

	function prepareSlideshow() 
	{
		// first lets make sure the browser understands the DOM methods we will be using
		if (!document.getElementsByTagName) 
			return false;
		if (!document.getElementById) 
			return false;

		// Make sure the elements exist
		if (!document.getElementById("slideshow")) 
			return false;
			
			//document.getElementById("slideshow_set").innerHTML=document.getElementById("slideshow_set").innerHTML+document.getElementById("slideshow_set").innerHTML+document.getElementById("slideshow_set").innerHTML;
		var slideshow = document.getElementById("slideshow");
		var wrapper = document.getElementById("slideshow_wrapper");
		wrapper.style.overflow = "hidden";

		// prepare the navigation bit we will be using
		// left
		var navigation = document.createElement("ul");
		navigation.setAttribute("id", "navigation");
		var li = document.createElement("li");
		var scroll_left = document.createElement("a");
		scroll_left.setAttribute("id", "scroll_left");
		scroll_left.href ="#";
		
		li.appendChild(scroll_left);
		navigation.appendChild(li);
		slideshow.insertBefore(navigation, wrapper);


		//right
		var li = document.createElement("li");
		var scroll_right = document.createElement("a");
		scroll_right.setAttribute("id", "scroll_right");
		scroll_right.href ="#";
		li.appendChild(scroll_right);
		navigation.appendChild(li);
		slideshow.insertBefore(navigation, wrapper);

		var slideshow_set = document.getElementById("slideshow_set");
		slideshow_set.style.display="block";
		slideshow_set.style.top = 0+"px";
		var li = slideshow_set.getElementsByTagName("li");
		sirina=0;
		for(i=0;i<li.length;i++)
			sirina=sirina+parseInt(li[i].offsetWidth);
			
		slideshow_set.style.left = -((sirina/3)+20)+"px";
	
	    // to get the max y position of the gallery image track we need to count all
		// the li items and multiply that number with 130
		var li = slideshow_set.getElementsByTagName("li");
		
		stevec=parseInt(li.length);
		for(i=0;i<li.length;i++)
			li[i].setAttribute("id", "li_"+i);

		// need the width of the gallery so that they do not scroll vertical
		slideshow_set.style.width = sirina + "px";


		// Attach onmouseover event for left
		scroll_left.onclick = function() {return false;}
		//scroll_left.onmouseout = function() {stop_slider_g=1;}
		scroll_left.onmouseover = function() 
		{
			//oldx=tempX;
			stop_slider_g=0;	
			smer_1=2;
			first=1;		
			moveSlideshow("slideshow_set","left",1);
			return false;
		}

		// Attach onmouseover event for right
		//li.onmouseout = function() {stop_slider_g=1;}
		scroll_right.onmouseover = function() 
		{
			//oldx=tempX;
			stop_slider_g=0;
			smer_1=1;
			first=1;
			moveSlideshow("slideshow_set","right");
			return false;
		}
		var body_set = document.getElementById("body");
		body_set.onmouseover = function() 
		{
			if(first==0)
			return;
			first=0;
			//oldx=tempX;
			stop_slider_g=0;
			if(smer_1==1)
			{
				moveSlideshow("slideshow_set","right");
				return false;
			}
			else
			{
			//oldx=tempX;
					
				moveSlideshow("slideshow_set","left",1);
				return false;
			}
			
		}
	}

	addLoadEvent(prepareSlideshow);
	
	
