function vytvorFlash(menomovie, width, height, id)
{
    //flesh = document.getElementById(kde);
    //flesh.innerHTML +=
    document.writeln("<object type='application/x-shockwave-flash' data='"+menomovie+"' width='"+width+"' height='"+height+"' id='"+id+"'><param name='movie' value='"+menomovie+"'><param name='quality' value='high'><param name='wmode' value='transparent'></object>");
}

function vytvorFlash2(menomovie, width, height, id)
{
    //flesh = document.getElementById(kde);
    //flesh.innerHTML +=
    document.writeln("<object type='application/x-shockwave-flash' data='"+menomovie+"' width='"+width+"' height='"+height+"' id='"+id+"' allowfullscree='true'><param name='movie' value='"+menomovie+"'><param name='quality' value='high'><param name='wmode' value='transparent'><param name='allowFullScreen' value='true' /><param name='allowScriptAccess' value='always' /></object>");
}

function vytvorFlashInElement(menomovie, width, height, id, eId)
{
    flesh = document.getElementById(eId);
    flesh.innerHTML = "<object type='application/x-shockwave-flash' data='"+menomovie+"' width='"+width+"' height='"+height+"' id='"+id+"'><param name='movie' value='"+menomovie+"' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><param name='allowFullScreen' value='true' /><param name='allowScriptAccess' value='always' /></object>";
}

function showPlayer(movie, playlist, width, height)
{
  document.writeln("<object type='application/x-shockwave-flash' data='"+movie+"?playlist_url="+playlist+"&autoload=true' width='"+width+"' height='"+height+"' id='player'>");
  document.writeln("<param name='movie' value='"+movie+"?playlist_url="+playlist+"&autoload=true' />");
  document.writeln("<param name='quality' value='high' />");
  document.writeln("</object>");
}

function urldecode(str)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = str;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
};

function createRequestObject() {
    var request_o;
    var browser = navigator.appName;
  	if(browser == "Microsoft Internet Explorer") {
  		request_o = new ActiveXObject("Microsoft.XMLHTTP");
  	} else {
  		request_o = new XMLHttpRequest();
  	}
  	return request_o;
}

function httpGET(url) {
	http.open('get', url);
	http.onreadystatechange = handleResults;
	http.send(null);
}

function formular(url) {
	http.open('get', url);
	http.onreadystatechange = handleResults;
	http.send(null);
}

function httpGET(action, vars, ajaxDivId) {
	http.open('get', action+'?'+vars);
	if (action=="kosik.php")
	   alert('Tovar bol vložený do košíka.');
	/* Define a function to call once a response has been received. */
	http.onreadystatechange = function(){
    if(http.readyState == 4) {
		  var response = http.responseText;
		  document.getElementById(ajaxDivId).innerHTML = response;
		  document.getElementById(ajaxDivId+"2").innerHTML = response;
		  if (response!="") prazdny = true;
		  else prazdny = false;
	  }
	  if((http.readyState == 1)&&(action=="kosik.php")) {
		  var response = "Loading..";
		  document.getElementById(ajaxDivId).innerHTML = response;
		  document.getElementById(ajaxDivId+"2").innerHTML = response;
	  }
  }
  /* Send the data. We use something other than null when we are sending using the POST	method. */
	http.send(null);
	var ajaxed = document.getElementById(ajaxDivId);
	alert("Tovar bol vložený do košíka.");
}

function handleResults() {
  var element = document.getElementById(printInto);
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4) {
		var response = http.responseText;
		element.innerHTML = response;
		var responses = response.split("\n");
		for(i=0;i<=responses.length-1;i++) {
		  if (responses[i]) {
		    if ((responses[i].search(".swf")>0) || (responses[i].indexOf("()")>0) || (responses[i].indexOf("\";")>0) || (responses[i].indexOf(");")>0))
		      eval(responses[i]);
		  }
    }
	}
}

function showSpanPos(parent,e,w,h)
{ // zobrazuje span len vpravo dole
    var imageSpan = document.getElementById(parent);
    var moz = false;
    //mouse position
  	var posx = 0;
  	var posy = 0;
  	if (!e) var e = window.event;
  	if (e.pageX || e.pageY) 	{
  		posx = e.pageX;
  		posy = e.pageY;
  	}
  	else if (e.clientX || e.clientY) 	{
  		posx = e.clientX + document.body.scrollLeft
  			+ document.documentElement.scrollLeft;
  		posy = e.clientY + document.body.scrollTop
  			+ document.documentElement.scrollTop;
  	}
    if (e.layerX || e.layerY) {
      posx = e.layerX;
      posy = e.layerY;
      moz = true;
    }
    
  	// posx and posy contain the mouse position relative to the document
    /*
    if (posx > (w+5+myScrLeft)) 
      posx = posx-(w+5);
    else
      posx = posx+5;
    if (posy > (h+5+myScrTop)) 
      posy = posy-(h+5);
    else
      posy = posy+5;*/
    
    posx = posx+15;
    posy = posy+15;
    
    imageSpan.style.display = "block";
    if (moz) {
      imageSpan.style.top = posy+"px";
      imageSpan.style.left = posx+"px";
    } else {
      imageSpan.style.top = posy;
      imageSpan.style.left = posx;
    }
}

function showSpan(parent,e,w,h)
{
    //var imageSpan = parent.getElementsByTagName('span');
    var imageSpan = document.getElementById(parent);
    var moz = false;
    //mouse position
  	var posx = 0;
  	var posy = 0;
  	if (!e) var e = window.event;
  	if (e.pageX || e.pageY) 	{
  		posx = e.pageX;
  		posy = e.pageY;
  	}
  	else if (e.clientX || e.clientY) 	{
  		posx = e.clientX + document.body.scrollLeft
  			+ document.documentElement.scrollLeft;
  		posy = e.clientY + document.body.scrollTop
  			+ document.documentElement.scrollTop;
  	}
    if (e.layerX || e.layerY) {
      posx = e.layerX;
      posy = e.layerY;
      moz = true;
    }
    
    var myScrLeft = 0;
    var myScrTop = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
      myScrTop = window.pageYOffset;
      myScrLeft = window.pageXOffset;
    } else {
      if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        myScrTop = document.body.scrollTop;
        myScrLeft = document.body.scrollLeft;
      } else {
        if(document.documentElement &&
            (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
          myScrTop = document.documentElement.scrollTop;
          myScrLeft = document.documentElement.scrollLeft;
        } else {
          myScrLeft = 0;
          myScrTop = 0;
        }
      }
    }
    // posx and posy contain the mouse position relative to the document
    if (posx > (w+20+myScrLeft)) 
      posx = posx-(w+20);
    else
      posx = posx+20;
    if (posy > (h+20+myScrTop)) 
      posy = posy-(h+20);
    else
      posy = posy+20;
      
    imageSpan.style.display = "block";
    if (moz) {
      imageSpan.style.top = posy+"px";
      imageSpan.style.left = (posx+200)+"px";
    } else {
      imageSpan.style.top = posy;
      imageSpan.style.left = posx;
    }
}

function hideSpan(parent)
{
    var imageSpan = document.getElementById(parent);
    imageSpan.style.display = "none";
    //var imageSpan = parent.getElementsByTagName('span');
    //imageSpan[0].style.display = "none";
}

/*var Lightbox = {

	init: function(options){
		this.options = $extend({
			resizeDuration: 400,
			resizeTransition: false,	// default transition
			initialWidth: 250,
			initialHeight: 250,
			animateCaption: true,
			showCounter: true
		}, options || {});

		this.anchors = [];
		$each(document.links, function(el){
			if (el.rel && el.rel.test(/^lightbox/i)){
				el.onclick = this.click.pass(el, this);
				this.anchors.push(el);
			}
		}, this);
		this.eventKeyDown = this.keyboardListener.bindAsEventListener(this);
		this.eventPosition = this.position.bind(this);

		this.overlay = new Element('div', {'id': 'lbOverlay'}).injectInside(document.body);

    //this.prevThumbs = new Element('div', {'id': 'lbPrevThumbs', 'styles': {'height': this.options.initialHeight, 'marginLeft': -(this.options.initialWidth/2), 'display': 'none'}}).injectInside(document.body);
    //this.nextThumbs = new Element('div', {'id': 'lbNextThumbs', 'styles': {'height': this.options.initialHeight, 'marginRight': -(this.options.initialWidth/2), 'display': 'none'}}).injectInside(document.body);
    //this.prevThumbsScroll = new Scroller('mousemove', {area: 150, velocity: 1});
		//this.nextThumbsScroll = new Scroller('mousemove', {area: 100, velocity: 1});
		//this.prevThumbs.addEvent('mouseover', this.prevThumbsScroll.start.bind(this.prevThumbsScroll));
		//this.prevThumbs.addEvent('mouseout', this.prevThumbsScroll.stop.bind(this.prevThumbsScroll));

		this.center = new Element('div', {'id': 'lbCenter', 'styles': {'width': this.options.initialWidth, 'height': this.options.initialHeight, 'marginLeft': -(this.options.initialWidth/2), 'display': 'none'}}).injectInside(document.body);
		this.image = new Element('div', {'id': 'lbImage'}).injectInside(this.center);
		this.prevLink = new Element('a', {'id': 'lbPrevLink', 'href': '#', 'styles': {'display': 'none'}}).injectInside(this.image);
		this.nextLink = this.prevLink.clone().setProperty('id', 'lbNextLink').injectInside(this.image);
		this.prevLink.onclick = this.previous.bind(this);
		this.nextLink.onclick = this.next.bind(this);

		this.bottomContainer = new Element('div', {'id': 'lbBottomContainer', 'styles': {'display': 'none'}}).injectInside(document.body);
		this.bottom = new Element('div', {'id': 'lbBottom'}).injectInside(this.bottomContainer);
		new Element('a', {'id': 'lbCloseLink', 'href': '#'}).injectInside(this.bottom).onclick = this.overlay.onclick = this.close.bind(this);
		this.caption = new Element('div', {'id': 'lbCaption'}).injectInside(this.bottom);
		this.number = new Element('div', {'id': 'lbNumber'}).injectInside(this.bottom);
		new Element('div', {'styles': {'clear': 'both'}}).injectInside(this.bottom);
    
		var nextEffect = this.nextEffect.bind(this);
		this.fx = {
			overlay: this.overlay.effect('opacity', {duration: 500}).hide(),
			resize: this.center.effects($extend({duration: this.options.resizeDuration, onComplete: nextEffect}, this.options.resizeTransition ? {transition: this.options.resizeTransition} : {})),
			image: this.image.effect('opacity', {duration: 500, onComplete: nextEffect}),
			bottom: this.bottom.effect('margin-top', {duration: 400, onComplete: nextEffect})
		};

		this.preloadPrev = new Image();
		this.preloadNext = new Image();
	},

	click: function(link){
		if (link.rel.length == 8) return this.show(link.href, link.title);

		var j, imageNum, images = [];
		this.anchors.each(function(el){
			if (el.rel == link.rel){
				for (j = 0; j < images.length; j++) if(images[j][0] == el.href) break;
				if (j == images.length){
					images.push([el.href, el.title]);
					if (el.href == link.href) imageNum = j;
				}
			}
		}, this);
		return this.open(images, imageNum);
	},

	show: function(url, title){
		return this.open([[url, title]], 0);
	},
	
	showimages: function(imageset,n){
		var j, images = [];
		this.anchors.each(function(el){
			if (el.rel == imageset){
				for (j = 0; j < images.length; j++) if(images[j][0] == el.href) break;
				if (j == images.length){
					images.push([el.href, el.title]);
				}
			}
		}, this);
		return this.open(images, n);
	},

	open: function(images, imageNum){
		this.images = images;
		this.position();
		this.setup(true);
		this.top = window.getScrollTop() + (window.getHeight() / 15);
		this.center.setStyles({top: this.top, display: ''});
		this.fx.overlay.start(0.8);
		return this.changeImage(imageNum);
	},

	position: function(){
		this.overlay.setStyles({'top': window.getScrollTop(), 'height': window.getHeight()});
	},

	setup: function(open){
		var elements = $A(document.getElementsByTagName('object'));
		elements.extend(document.getElementsByTagName(window.ie ? 'select' : 'embed'));
		elements.each(function(el){
			if (open) el.lbBackupStyle = el.style.visibility;
			el.style.visibility = open ? 'hidden' : el.lbBackupStyle;
		});
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', this.eventPosition);
		document[fn]('keydown', this.eventKeyDown);
		this.step = 0;
	},

	keyboardListener: function(event){
		switch (event.keyCode){
			case 27: case 88: case 67: this.close(); break;
			case 37: case 80: this.previous(); break;	
			case 39: case 78: this.next();
		}
	},

	previous: function(){
		return this.changeImage(this.activeImage-1);
	},

	next: function(){
		return this.changeImage(this.activeImage+1);
	},
	
	showImage: function(num){
		return this.changeImage(num);
	},

	changeImage: function(imageNum){
		if (this.step || (imageNum < 0) || (imageNum >= this.images.length)) return false;
		this.step = 1;
		this.activeImage = imageNum;

		this.bottomContainer.style.display = this.prevLink.style.display = this.nextLink.style.display = 'none';
		this.fx.image.hide();
		this.center.className = 'lbLoading';

		this.preload = new Image();
		this.preload.onload = this.nextEffect.bind(this);
		this.preload.src = this.images[imageNum][0];
		return false;
	},

	nextEffect: function(){
		switch (this.step++){
		case 1:
			this.center.className = '';
			this.image.style.backgroundImage = 'url('+this.images[this.activeImage][0]+')';
			this.image.style.width = this.bottom.style.width = this.preload.width+'px';
			this.image.style.height = this.prevLink.style.height = this.nextLink.style.height = this.preload.height+'px';

			this.caption.setHTML(this.images[this.activeImage][1] || '');
			this.number.setHTML((!this.options.showCounter || (this.images.length == 1)) ? '' : 'Foto '+(this.activeImage/1+1)+' / '+this.images.length);
			
      var lbRef = this;
			//this.prevThumbs.empty();
			
			if (this.activeImage) this.preloadPrev.src = this.images[this.activeImage-1][0];
			if (this.activeImage != (this.images.length - 1)) this.preloadNext.src = this.images[this.activeImage][0];

			if (this.center.clientHeight != this.image.offsetHeight){
				this.fx.resize.start({height: this.image.offsetHeight});
				//this.prevThumbs.setStyles({height: this.image.offsetHeight});
				//this.nextThumbs.setStyles({height: this.image.offsetHeight});
				break;
			}
			this.step++;
		case 2:
		  //this.fx.prevThumbs.set(-this.image.offsetWidth/2);
			//this.fx.nextThumbs.set(-this.image.offsetWidth/2);
			if (this.center.clientWidth != this.image.offsetWidth){
				this.fx.resize.start({width: this.image.offsetWidth, marginLeft: -this.image.offsetWidth/2});
				//this.prevThumbs.setStyles({marginLeft: -this.image.offsetWidth/2-this.thumbWidth-30});
				break;
			}
			//this.fx.prevThumbs.set(-this.image.offsetWidth/2);
			this.step++;
		case 3:
			this.bottomContainer.setStyles({top: this.top + this.center.clientHeight, height: 0, marginLeft: this.center.style.marginLeft, display: ''});
			this.fx.image.start(1);
			break;
		case 4:
			if (this.options.animateCaption){
				this.fx.bottom.set(-this.bottom.offsetHeight);
				this.bottomContainer.style.height = '';
				this.fx.bottom.start(0);
				break;
			}
			this.bottomContainer.style.height = '';
		case 5:
			if (this.activeImage != (this.images.length - 1)) {
        this.nextLink.style.display = '';
        //this.nextThumbs.style.display = '';
        //this.fx.nextThumbs.start(-this.image.offsetWidth/2-this.nthumbWidth-30);
      }
			if (this.activeImage > 0) {
			  this.prevLink.style.display = '';
        //this.prevThumbs.style.display = '';
        //this.fx.prevThumbs.start(-this.image.offsetWidth/2-this.thumbWidth-30);
      }
			this.step = 0;
		}
	},

	close: function(){
		if (this.step < 0) return;
		this.step = -1;
		if (this.preload){
			this.preload.onload = Class.empty;
			this.preload = null;
		}
		for (var f in this.fx) this.fx[f].stop();
		this.center.style.display = this.bottomContainer.style.display = 'none';
		this.fx.overlay.chain(this.setup.pass(false, this)).start(0);
		return false;
	}
};*/

