 var $_fx_step_default = $.fx.step._default;

$.fx.step._default = function (fx)
{
    var m = $_fx_step_default(fx)
    
    if (fx.elem.flash)
        //alert(fx.elem.firstChild);
        fx.elem.firstChild.style[fx.prop] = fx.now + "px";
    
   return m;


};

function prehratVideo(co)
{
    
	var fv = document.getElementById('myflash' +  co );

        for (;fv; fv = fv.parentNode)
            if (fv.connectedmw)
            {
                
                fv.connectedmw.click();
                break;
            }
}

function mw_dias_file(left, top, sirka, vyska, odkaz, loaded, clicked)
{
    this.element = null;
    this.min_velikost = vyska;
    this.min_sirka = sirka;
    this.div = document.createElement('div');
    this.div.connectedmw = this;
    this.originalWidth = 0;
    this.originalHeight = 0
    this.originalLeft = left;
    this.originalTop = top;
    this.odkaz = odkaz;
    this.loaded = loaded;
    this.clicked = clicked;
    this._left = left;
    this._top = top;
    this._sirka= sirka;
    this._vyska = vyska;
    this.scroll = null;
    this.flash = false;

    if (typeof mw_dias_file.counter == 'undefined')
        mw_dias_file.counter=0;


    
}

mw_dias_file.prototype.load = function()
{
    var left = this._left;
    var top = this._top;
    var sirka = this._sirka;
    var vyska = this._vyska;
 
    var _this = this;
    if (this.odkaz.href.search(/(jpe?g$)|(gif$)|(png$)/i) > -1)
    {
     
        this.element = document.createElement('img');
        var eee = this.element;
        $(eee).bind('load', function()
        {


            _this.originalWidth = this.width;
            if (!_this.originalWidth)
                _this.originalWidth = this.getAttribute('width');
            _this.originalHeight = this.height;
            if (!_this.originalHeight)
                _this.originalHeight = this.getAttribute('height');
            eee.height = vyska;

            $(_this.div).animate({opacity: "1"}, 500,
            function()
            {
                $(_this.div).bind('click',
                function()
                {
                    if (_this.clicked)
                        _this.clicked(_this);

                });
 
            });
            var temp  = _this.div.offsetHeight;
            if (temp > _this.min_velikost)
                _this.min_velikost = temp;
            temp = _this.div.offsetWidth;
            if (temp > _this.min_sirka)
                _this.min_sirka = temp;

            _this.min_sirka =  _this.originalWidth /_this.originalHeight * _this.min_velikost;
            //alert($.dump({vyska: _this.originalHeight, sirka : _this.originalWidth, vel: _this.min_sirka}));
            //alert('ano');
            if (_this.loaded)
                _this.loaded();
        });
    }
    else if (this.odkaz.href.search(/(\.swf$)|(\.swf\?)/i) > -1)
    {
        var poc = ++mw_dias_file.counter;

        this.originalHeight = 200;
        this.originalWidth = 366;
        this.element = document.createElement('div');
        this.min_velikost = 100;
        this.min_sirka = 166;
        var m="";
		      	if (navigator.appVersion.indexOf("MSIE") == -1)
						{
						 m +=   '<div style="width:166px; height: 100px;overflow: hidden"><object '+
                                                        ' style="width:166px; height: 100px" ' +
							' id="myflash' + poc + '" ' +
							' style="position:relative; top:1px;" ' +
							' data="'+ this.odkaz.href +'&jakeid='+ poc +'&lang=' + lang +'" ' +
							/*' width="166" ' +
							' height="100" ' +*/
							'  '+
							' kteraCast="reference1" ' +
							' type="application/x-shockwave-flash" ' +
							' pluginspage="http://www.macromedia.com/go/getflashplayer" ' +
							' allowScriptAccess="always" /><div>' ;
							//div_obr.style.width  = "176px";
						//	alert(m);
						}
						 else
						{
						 m+=
							'<div style="width:166px; height: 100px"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '+
							'	codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ' +
							'	width="166"  ' +
							'	height="100"  ' +
							'	id="myflash' + poc + '" ' +
							'	style="position:relative;top:3px"> ' +
							' <param name="allowScriptAccess" value="sameDomain" /> ' +
							' <param name="movie" value="' + this.odkaz.href+ '&jakeid='+ poc + '&lang=' + lang + '" /> ' +
							' <param  name="kteraCast" value="reference1" /> ' +
							' <param name="quality" value="high" /> ' +
							'  ' +
							' <param name="allowScriptAccess" value="always" /> ' +
							' </object></div>' ;

						//	div_obr.style.width  = "178px";

					}
          this.element.innerHTML = m;
          this.element = this.element.firstChild;
          this.flash = true;

    }

    if (this.element)
    {

        $(this.div).css({
                    textAlign:'center',
                    position: 'absolute',
                    left: left + "px",
                    top: top + "px",
                    opacity: "0",
  	            borderStyle  : 'solid',
                    borderWidth  : '2px',
		    borderColor  : '#003F77',
                    backgroundColor: '#003F77'});

        this.div.appendChild(this.element);
        var span = document.createElement('p');
        $(span).css({color:'white', margin:"0px", padding:"0px", display: 'block', textAlign: 'center'});
        span.innerHTML =  this.odkaz.alt.replace(/[\s]+/g, '&nbsp;');
        this.div.appendChild(span);

        var body = document.getElementsByTagName('body');
        body = body[0];
        body.appendChild(_this.div);
    }
    //loadovani
    if (this.odkaz.href.search(/(jpe?g$)|(gif$)|(png$)/i) > -1)
    {
        this.element.src = this.odkaz.href;
    }
    else if (this.odkaz.href.search(/(\.swf$)|(\.swf?)/i) > -1)
    {
            $(this.div).css({opacity: 1})
            if (_this.loaded)
                _this.loaded();
    }

}


mw_dias_file.prototype.click = function()
{
    if (this.clicked)
        this.clicked(this);
}

mw_dias_file.prototype.vyska = function()
{
    return this.min_velikost;
}
mw_dias_file.prototype.top = function(v)
{
    
    if (v != undefined)
    {
        $(this.div).css({top: v + "px"});
        this.originalTop = v;
    }
    return this.originalTop;
}

mw_dias_file.prototype.sirka = function()
{
    return this.min_sirka;
}

mw_dias_file.prototype.left = function(v)
{
    if (v != undefined)
    {
        $(this.div).css({left: v + "px"});
        this.originalLeft = v;
    }
    return this.originalLeft;

}

function mw_dias_scroll(d, mt)
{
    var div = d;
    var min_top = mt;

    this.onScroll = function()
    {
        
        if (document.body.scrollTop == 0)
           bodys =  document.documentElement;
        var vyska = $(div).height();
        if (min_top + vyska < bodys.scrollTop)
        {
            
           $(div).css({top: bodys.scrollTop + 30 + "px"});
        }
        else
           $(div).css({top: min_top + "px"});
    }
    $(window).bind('scroll', this.onScroll)
}

mw_dias_scroll.prototype.removeScroll = function()
{
    
    $(window).unbind('scroll', this.onScroll);
}




mw_dias_file.prototype.move = function(left, min_top)
{
    
    var _this = this;
   
     
    if (left != undefined && min_top != undefined)
    {
        
        var m = min_top;
        var bodys2 = document.body;
        
        if (document.body.scrollTop == 0)
            bodys2 =  document.documentElement;

        if (bodys2.scrollTop > min_top )
            m = bodys2.scrollTop;
        $(this.div).animate({left: left + "px", top: m + 30 + "px"}, 500,
            function()
            {
               _this.scroll = new mw_dias_scroll(_this.div, min_top);
            });
            
        var v =  {height: this.originalHeight + "px" , width: this.originalWidth + "px" };

        if (this.flash)
        {
            this.element.flash = true;
            
        }
        //alert(this.element);
        $(this.element).animate( v, 500);

    }
    else
    {

        if (this.scroll)
            this.scroll.removeScroll();
        this.scroll = null;
        var off = $(this.div).offset();
        if (off.left != this.originalLeft || off.top != this.originalTop)
        {
            this.element.customAnimate = true;
            $(this.div).animate({left: this.originalLeft + "px", top: this.originalTop + "px"},500);
            var v =  {height: this.min_velikost + "px" , width: this.min_sirka + "px" };

            if (this.flash)
            {
                this.element.flash = true;
            }
            $(this.element).animate(v,500);
        }
    }
}

mw_dias_file.prototype.hide = function()
{
    var m = this.div;
    $(m).animate({opacity: "0"}, 500, function()
    {
       m.parentNode.removeChild(m);
    })
}

function mw_dias_loader(left, top, body)
{

    this.timer = 0;
    this.body = body;

    this.loader = document.createElement('div');
    $(this.loader).css(
     {
         display : 'block',
         left : left + 'px',
         top : top + 'px',
         position: 'absolute'
      });
      this.loader.innerHTML =
				"<div style='float:left;display:block;width:20px;height:20px; border-style:solid;border-width:1px;border-color:#003F77'></div>" +
				"<div style='position:relative; left:5px;float:left;display:block;width:20px;height:20px; border-style:solid;border-width:1px;border-color:#003F77'></div>" +
				"<div style='position:relative; left:10px;float:left;display:block;width:20px;height:20px; border-style:solid;border-width:1px;border-color:#003F77'></div>" +
				"<div style='position:relative; left:15px;float:left;display:block;width:20px;height:20px; border-style:solid;border-width:1px;border-color:#003F77'></div>";
       body.appendChild(this.loader);
       var counter = 0;
       _this = this;
       this.timer = setInterval(function()
       {
          var i = 0;
          $(_this.loader).find('div').each(function()
          {
              if (counter%4 == i)
                  this.style.backgroundColor = "#003F77";
              else
                  this.style.backgroundColor = "white";
              i++;
           });
           counter++;
         
        }, 500);
}
mw_dias_loader.prototype.stop = function()
{
    clearInterval(this.timer);
    var lo = this.loader;
    
    $(this.loader).animate( {opacity: "0"} , 500, function() {lo.parentNode.removeChild(lo);} );

}


function mw_dias(lk)
{
    var link = lk;


    var onClick = function()
    {
        var rodic = link.parentNode;
        var cara = $('#cara');
	var nabidka = $('.podnabidka');
        var leva_strana = $('#leva_strana');

 	var cara2 = document.createElement('img');
        cara2.src = 'cara2.jpg';
        cara2.style.display = 'none';
 


        var body = document.getElementsByTagName('body');
        body = body[0];
        //body.appendChild(prekryti_leva);
    	body.appendChild(cara2);


        var off = $(leva_strana).offset();

        $(cara2).css(
        {
            left: $(cara).offset().left + "px",
            top : $(cara).offset().top+ "px",
            width: $(cara).width()+ "px",
            height: $(cara).height()+ "px",
            display:'block',
            position: 'absolute'
            
       });
       var node  = rodic.firstChild;

       var to_load = new Array();
       var text = document.createElement('div');
       var temp = "";
       for (; node; node= node.nextSibling)
       {
          
            if (node.nodeName == 'A'
                && (node.getAttribute('href')+"").match(/((\.swf$)|(\.swf\?))|(((jpg)|(gif)|(png))$)/i))
            {
                to_load.push(
                    {href: "" + node.getAttribute('href'),
                     alt: "" +node.innerHTML});
                
            }
            else
            {
                if (node.nodeValue 
                    && node.nodeValue != null
                    && !(node.nodeValue + "").match(/^[^a-zA-ZáäčďéěíĺľňóôöŕšťúůüýřžÁÄČĎÉĚÍĹĽŇÓÔÖŔŠŤÚŮÜÝŘŽABCDEFGHIJKLMNOPQRSTUVWXYZ]+$/g))
                        temp += node.nodeValue + "<br>";
            }
       }

       
       text.innerHTML = "<strong>" + temp.replace(/&nbsp;/g, '').replace(/(-[\s]*)|(\s+$)/, '') + "</strong>"
       $(text).css( {
                    position : "absolute",
                    left : $(rodic).offset().left + "px",
                    margin : "0px",
		    padding : "0px",
		    top : $(rodic).offset().top + "px",
		    display : "block",
		    visibility : "visible"
       })
       var ahref = document.createElement('a');

       if (window.lang == 'en')
           ahref.innerHTML = '<< Back to page...';
       else if (window.lang == 'de')
           ahref.innerHTML = '<< Zurück in der Seite';
       else
           ahref.innerHTML = '<< Zpět na stránku...';
       ahref.setAttribute('href','#');
       text.appendChild(ahref);
       
       $(ahref).bind('click', function()
       {
            for (var i in to_load)
                to_load[i].hide();
            $(text).animate({opacity: "0"}, 500);
            $('#copyright').css({position: ''});
            $(cara2).animate({left: cara2.old_left + "px"}, 500,
                function()
                {
                    cara.css({ display: 'block'});
                    cara2.parentNode.removeChild(cara2);
                    text.parentNode.removeChild(text);
                });
            $(nabidka).css({display:''});
            $(leva_strana).css({display:'block'});
            nabidka.animate({opacity: "1"}, 500);
            leva_strana.animate({opacity: "1"}, 500);
            $(link).unbind('click', onClick);
            new mw_dias(link);
            return false;
       });

       body.appendChild(text);

       text.old_top = $(text).offset().top;

       var pozice_from_text = $(leva_strana).offset().top+30;

       $(text).animate({top: pozice_from_text + "px"}, 1000);
       body.appendChild(cara2);
       cara2.style.visibility = 'visible';
       cara2.old_left = cara.offset().left;
       var velikost = 200;

       temp = $(text).offset().left+
                  $(text).width()+10;
       if (velikost < temp)
           velikost = temp;

       pozice_from_text += $(text).height() + 10;
       var pta = pozice_from_text;
       pozice_from_text += 30;

       var loader = null;

       cara.css({display:'none'});
       $(nabidka ).animate( {opacity:"0"}, 500 ,function() { nabidka.css( {display: 'none'});});
       $(leva_strana).animate( {opacity:"0"}, 500, function() { leva_strana.css( {display: 'none'});});
       $(cara2).animate({left: velikost + "px"}, 500,
       function()
       {
           loader = new mw_dias_loader($(text).offset().left, pta, body)
           var pp = pozice_from_text ;
           var ll = $(text).offset().left;

           
           var nahrano = 0;

           var afterLoad = function()
           {
               nahrano--;
               if (!nahrano)
               {
                    loader.stop();
                    

                   var top = pozice_from_text ;

                   var left = $(cara2).offset().left;

                   for (var j in to_load)
                   {

                            to_load[j].top(top);
                            top += to_load[j].vyska() +30 ;

                            var tt = to_load[j].left() + to_load[j].sirka() +20;
                            if (left < tt)
                            {
                                 $(cara2).animate({left :tt + "px"}, 'fast');
                                left = tt;
                            }
                   }
                    $('#copyright').css({position:'absolute', top: top + "px"});

                }
           }

           var afterClick = function(w)
           {

                try
                {
                w.move($(cara2).offset().left + 20,
                       pozice_from_text);
                }
                catch (e)
                {
                    
                }

                for (var i in to_load)
                {
                    if (to_load[i] != w)
                    {
                        try
                        {
                            to_load[i].move();
                        }
                        catch (e)
                        {

                        }
                    }
                    
                }


           }

           nahrano = to_load.length;
           for(var i in to_load)
           {
               to_load[i] = new mw_dias_file(ll, pp, 50, 100, to_load[i],afterLoad, afterClick);
               pp += 105
           }
           for(var r in to_load)
           {
               to_load[r].load();
              
           }

       });
       
       
       return false;

    }


    $(link).bind('click', onClick);
}

