/*
 * Multimedia Objects
 * Author: Lukas Pesl
 * Version: 0.1
 * 
 */   

var addthis_config = {
ui_click: true
}; 

multimediaObjects = {
	
	installVideo : function(params, useFakePlayer)
	{
		var defaults = {
			playerSwf : "http://img.ihned.cz/img/videoplayer/videoplayer_i17.swf?v178",
			divId : '',
			width: 600,
			height: 338,
			flashVersion: "10.1.0",
			expressInstall: "/img/videoplayer/i11/expressInstall.swf",
			ads : true, 
			autoplay : useFakePlayer,
			//autoplay : true,
			disableParentClick : false, 
			
			flashvars : {
				config: 'i11/config.xml',
				skin: 'i11/skin_$width$.xml', // 'i11/skin_600.xml'
			
				adverts: 'i11/a.xml',
				playlist: 'i11/playlist.xml',
				
				streamHigh1: '',
				altstreamHigh1: '',
				streamMedium1: '',
				altstreamMedium1: '',
				streamLow1: '',
				altstreamLow1: '',
				imagefile1: ''
			},
			params : {
				quality: 'high',
				allowScriptAccess: 'always',
				allowFullScreen: 'true',
				wmode: 'transparent'
			}		
		};

		var params = $.extend(true, defaults, params);

		if (!params.ads)
		{
			params.flashvars.adverts = 'i11/a_no.xml';
		}
		if (!params.autoplay)
		{
			params.flashvars.playlist = 'i11/playlist_noautoplay.xml';
		}
		params.flashvars.skin = params.flashvars.skin.replace('$width$',params.width);

		var f = function() {swfobject.embedSWF(params.playerSwf, params.divId, params.width, params.height, params.flashVersion, params.expressInstall, params.flashvars, params.params)};
		
		if (useFakePlayer)
		{
			var arrowHeight = 48;
			var arrowWidth = 80;
			var obj = $('#' + params.divId);
			var left = (obj.actual('width') / 2) - (arrowWidth/ 2); 
			var top = (obj.actual('height') / 2) - (arrowHeight / 2); 
			var html = '<div style="left:' + left + 'px; top: ' + top + 'px;" class="play-ico-new pngfix"></div>';
			obj.click(function(e){
		    if (!/webkit/.test( navigator.userAgent.toLowerCase()))
					obj.parent('A').mousedown(function(e){e.preventDefault()});
				noRotation = true;
				var transparentTitle = obj.parent('A').siblings('.title.pngfix').hide();
				var transparentTitle = obj.siblings('.title.pngfix').hide();
				f();
				return false;
			}).append(html).css({position: 'relative'});

		}
		 else
		{
			f();
		}
		if (params.disableParentClick) 
			$('#' + params.divId).parent('A').click(function(){return false;});
	},

	installExternalVideo : function(params, useFakePlayer, info, elementId)
	{
		var defaults = {};
		var params = $.extend(true, defaults, params);

		var f = function() { $('#' + params.divId).html(params.embed).find('embed, object');  if (!info && params.width)  $('#' + params.divId).width(params.width).height(params.height); };
		
		if (useFakePlayer)
		{
			var arrowHeight = 48;
			var arrowWidth = 80;
			var obj = $('#' + params.divId);
			var left = ((params.width || obj.actual('width')) / 2) - (arrowWidth/ 2); 
			var top = ((params.height || obj.actual('height')) / 2) - (arrowHeight / 2); 
			var html = '<div style="left:' + left + 'px; top: ' + top + 'px;" class="play-ico-new pngfix"></div>';
			obj.click(function(){
				noRotation = true;
				f();
				return false;
			}).append(html).css({position: 'relative'});

		}
		 else
		{
			f();
      if (info)
      {
        if (!elementId)
        {
          var max = 
      		'<div class="maximize" style="float: left; width: 100%;">' +
      		  '<img src="/img/11_0/mikony/maximize.png" title="Zvětšit" alt="Zvětšit" style="cursor: pointer; float: right; margin: 15px -114px 15px 0; _display: inline;">' +
      		'</div>';

          var $div = $('#' + params.divId).append(max);
         	//$('embed, object', $div).width(params.width).height(params.height);
    		}

        var maxInfographic = function(obj)
        {
        	var o = obj.parent().clone();
        	$('.maximize', o).remove();
        	//$('embed, object', o).width(1000).height(676);
          //$('embed, object', o).width(params.width).height(params.height);
		    	$('embed, object', o).width(params.width).height(params.height).css({margin: '15px'});
        	return o.html();
        }
    		var opts = {'dataSelector' : maxInfographic};
        $('.maximize', $div).modalWindow(opts);
      }
		}
		if (params.disableParentClick) 
			$('#' + params.divId).parent().click(function(){return false;});

	},
	
	installInfographic : function(params, elementId)
	{
		multimediaObjects.installExternalVideo(params, elementId, true, elementId);

		//multimediaObjects.installExternalVideo(params, false, true, elementId);
		//multimediaObjects.installExternalVideo(params, useFakePlayer, true);
	},

	installSingleInfographic : function(params)
	{
  		if (($(params.parentDivId).html() != ''))
  		{
				className =  'second';
				banner = '';				
			} else
			{
				className =  '';
				banner = '';				
				//banner = '<div id="r-big"><span id="r-big-ozn">reklama</span>' + $('<div>').append($('#col3-article #r-big object').clone()).remove().html() + '</div>';
			}

			var galleryDescription = params.galleryDescription ? params.galleryDescription.replace(/(<([^>]+)>)/ig,"").replace(/"/ig, '&quot;').replace(/</ig, '&lt;').replace(/>/ig, '&gt;') : ''; 
      var embed = params.embed ? params.embed.replace(/\n/ig,"").replace(/\t/ig, '') : '';
      
      var socUrl = window.location.href.replace(window.location.hash, '') + '#' + (params.multimediaUrl ? '' : 'infografika-') + 'gi$galleryId$';
			var soc =  
			
			'<div class="addthis_toolbox addthis_default_style" addthis:title="$galleryName$" addthis:description="' + galleryDescription + '" addthis:url="' + socUrl + '">' +
      '<a class="addthis_button_google_plusone" g:plusone:size="medium"></a>' +
			'<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>' +
			'<a class="addthis_button_tweet"></a>' +
			'<a class="addthis_counter addthis_pill_style"></a>' +
			'</div>' +
			'\<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4db1357d709d5410"\>\</script\>';

      var related = params.relevantLinks ? params.relevantLinks : '';

      var html = '<div class="pngfix otv infographics infootv ' + className + '" id="gi$galleryId$">' +
  		'<div class="l">' +
    		'<div class="animation">' +
      		'<div id="ig' + params.galleryId + '">' +
      		  embed +
      		'</div>' +
    		'</div>' +

        soc +

    		'<div class="info">' +
      		'<div class="maximize">' +
      		  '<img src="/img/11_0/mikony/maximize.png" title="Zvětšit" alt="Zvětšit" style="cursor: pointer">' +
      		'</div>' +
    		'</div>' +

  		'</div>' +
  		'<div class="r">' +
        '<div class="content">' +
          '<a class="h1" href="#">$galleryName$</a>' +
	        '<span class="article-date" href="#"></span>' +
	        '<a class="discussion" href="#">Diskuze (?)</a>' +
          '<h2 class="h2">$galleryDescription$</h2>' +
          related +
        '</div>' +
        banner + 
  		'</div>' +
  	'</div>';

		$.each(params, function(key, val){
        html = html.replace(new RegExp('\\$' + key + '\\$', 'g'), val == null ? '' : val);
    });

    $div = $(html).appendTo(params.parentDivId);

    if (params.multimediaUrl) 
    {
      $('.heading').hide();
      $('#head').addClass('photohead');
			discussionLink = params.articleLink + '#diskuze';
			discussionCount = params.discussionCount;
      $('.content .article-date', $div).html(params.articleDate);
    } else
    {
			discussionLink = params.articleLink + '#diskuze';
			discussionCount = params.discussionCount;
      $('.content .article-date', $div).html(params.articleDate);
    }

    if (params.discussionLink)
      discussionLink = params.discussionLink; 
    
    $('.content A.h1', $div).attr('href', params.articleLink);
    if (discussionLink && discussionCount != '' && (params.multimediaUrl || $('A#comm-url').css('display')=='block')) /* $('A#comm-url:visible').length != 0 */
    {
      $('.content A.discussion', $div).attr('href', discussionLink)
                                      .html($('.content A.discussion', $div).html().replace('?', discussionCount))
                                      .before('&nbsp;<span class="date-disc-deli" style="color: #96C2E4">|</span>&nbsp;&nbsp;');
    }
    else
    {
      $('.content A.discussion', $div).css('display', 'none');
    }
    $('.content ul li:gt(1)', $div).css('display', 'none');

    var maxInfographic = function(obj)
    {
    	//var o = obj.parent().prev().clone();
    	var o = obj.parent().siblings('.animation').children('div').clone();
    	//$('embed, object', o).width(1000).height(676);
    	$('embed, object', o).width(params.width).height(params.height).css({margin: '15px'});
    	return o.html();
    }
		var opts = {'dataSelector' : maxInfographic};
    $('.maximize', $div).modalWindow(opts);
	},

	installSingleExternalVideo : function(params)
	{
      var turnOffLights = '';
  		if (($(params.parentDivId).html() != ''))
  		{
				className =  'second';
				banner = '';				
				iframe = '';				
			} else
			{
				className =  '';
				banner = '';				

        if (params.respekt)
        {
          iframe = '<iframe style="sdisplay: none" src="" id="gallery-iframe" width="300" height="300" frameborder="0" scrolling="no"></iframe>';
          turnOffLights = '<a class="lightSwitcher pngfix" href="#">Zhasnout světlo</a>';
        }
        else
        {
          iframe = '';
        }
				//banner = '<div id="r-big"><span id="r-big-ozn">reklama</span>' + $('<div>').append($('#col3-article #r-big object').clone()).remove().html() + '</div>';
			}

			if (params.bigVideo)
			{
				authorName = '<span>' + params.authorName + '</span>';
				authorImage = '<div class="authorImage">' + params.authorImage + '</div>';
			} else
			{
				authorName = '';
				authorImage = '';
			}

			var socUrl = window.location.href.replace(window.location.hash, '') + '#' + (params.multimediaUrl ? '' : 'vide-') + '#video-gv$galleryId$';
			var soc = 
			
			'<div class="addthis_toolbox addthis_default_style" addthis:title="$galleryName$" addthis:description="$galleryDescription$" addthis:url="' + socUrl + '">' +
      '<a class="addthis_button_google_plusone" g:plusone:size="medium"></a>' +
			'<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>' +
			'<a class="addthis_button_tweet"></a>' +
			'<a class="addthis_counter addthis_pill_style"></a>' +
			'</div>' +
			'\<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4db1357d709d5410"\>\</script\>';

      
			var embedHtml = params.embed;
			if (params.autoplay)
			{
				var embed = $(params.embed).wrap('<div>').parent(); 

	      var eO = $('EMBED', embed);

        if (eO.length == 0)
        {
          embedHtml = params.embed.replace(/version=3/g, 'version=3&autoplay=1'); 
        } else
        {
          $('embed', embed).attr('src', $('embed', embed).attr('src') + '&autoplay=1');
  	      embedHtml = embed.html();
	      }
      }
			
      var related = params.relevantLinks ? params.relevantLinks : '';

			var html = '<div class="pngfix otv video videootv ' + className + '" id="gv$galleryId$">' +
  		'<div class="l">' +
    		'<div class="animation">' +
      		'<div id="vg' + params.galleryId + '">' +
      		  embedHtml +
      		'</div>' +
      		'<!--<div class="info">' +
        		'<div class="l">' +
              '<div class="thumb-author">autor: '+ (params.author == null ? '' : params.author) +'</div>' +
        		'</div>' +
      		'</div>-->' +
	   		'</div>' +
      soc + 
  		'</div>' +
  		'<div class="r">' +
        '<div class="content">' +
          '<a class="h1" href="#">$galleryName$</a>' +
	        '<span class="article-date" href="#"></span>' +
	        '<a class="discussion" href="#">Diskuze (?)</a>' +
          authorImage +
					'<h2 class="h2">' + authorName + '$galleryDescription$</h2>' +
          related +
        '</div>' +
        banner + 
  		'</div>' +
  	'</div>';

		$.each(params, function(key, val){
        html = html.replace(new RegExp('\\$' + key + '\\$', 'g'), val == null ? '' : val);
    });

    $div = $(html).appendTo(params.parentDivId);

    if (turnOffLights)
    {
      if ($("#shadow").length == 0)
      {
        var shadow = '<div id="shadow" class="pngfix"></div>';
        $('body').prepend(shadow);
        $(".mm-ow-slot").hide();
        $("#shadow").click(function(){
          $('.lightSwitcher').click();
        });
      }
      
      $(turnOffLights).click(function(){
         $("#shadow").css("height", $(document).height()).toggle();
         if ($("#shadow").is(":hidden"))
             $(this).html("Zhasnout světlo").removeClass("turnedOff");
          else
             $(this).html("Rozsvítit světlo").addClass("turnedOff");
         return false;
       //}).prependTo($div.parent()).css({'margin' : '10px 0 -20px 25px', 'color' : '#007CA5'});
       }).insertBefore('.animation', $div).css({'margin' : '-15px 0 13px', 'color' : '#007CA5', 'position' : 'relative'});
     }

    if (params.multimediaUrl) 
    {
      $('#head').addClass('photohead');
      $('.heading').hide();
			discussionLink = params.articleLink + '#diskuze';
			discussionCount = params.discussionCount;
      $('.content .article-date', $div).html(params.articleDate);
    } else
    {
			//discussionLink = params.articleLink + '#diskuze';
      discussionLink = $('#comm-url').attr('href');
			discussionCount = params.discussionCount;
      $('.content .article-date', $div).html(params.articleDate);
    }

    if (params.respekt)
    {
      var frameUrl = params.respekt? 'http://respekt.ihned.cz/?p=RM0000_big' : 'http://multimedia.ihned.cz/?m=big'; 
      frameUrl += '&rn=' + Math.random(); 
      $('#gallery-iframe', $div).attr('src', frameUrl).show();
    }

    if (params.discussionLink)
      discussionLink = params.discussionLink; 

    $('.content A.h1', $div).attr('href', params.articleLink);
    if (discussionLink && discussionCount != '' && (params.multimediaUrl || $('A#comm-url').css('display')=='block')) /* $('A#comm-url:visible').length != 0 */
    {
      $('.content A.discussion', $div).attr('href', discussionLink)
                                      .html($('.content A.discussion', $div).html().replace('?', discussionCount))
                                      .before('&nbsp;<span class="date-disc-deli" style="color: #96C2E4">|</span>&nbsp;&nbsp;');
    }
    else
    {
      $('.content A.discussion', $div).css('display', 'none');
    }
    $('.content ul li:gt(1)', $div).css('display', 'none');

	},

	installSingleVideo : function(params)
	{
      var turnOffLights = '';
  		if (($(params.parentDivId).html() != ''))
  		{
				className =  'second';
				banner = '';				
				iframe = '';				
			} else
			{
				className =  '';
				banner = '';				
				//banner = '<div id="r-big"><span id="r-big-ozn">reklama</span>' + $('<div>').append($('#col3-article #r-big object').clone()).remove().html() + '</div>';
        if (params.respekt)
        {
          iframe = '<iframe style="sdisplay: none" src="" id="gallery-iframe" width="300" height="300" frameborder="0" scrolling="no"></iframe>';
          turnOffLights = '<a class="lightSwitcher pngfix" href="#">Zhasnout světlo</a>';
        }
        else
        {
          iframe = '';
        }
			}
			
			if (params.bigVideo)
			{
				authorName = '<span>' + params.authorName + '</span>';
				authorImage = '<div class="authorImage">' + params.authorImage + '</div>';
			} else
			{
				authorName = '';
				authorImage = '';
			}

			var socUrl = window.location.href.replace(window.location.hash, '') + '#' + (params.multimediaUrl ? '' : 'video-') + 'gv$galleryId$'; 
			var soc = 
			
			'<div class="addthis_toolbox addthis_default_style" addthis:title="$galleryName$" addthis:description="$galleryDescription$" addthis:url="' + socUrl + '">' +
      '<a class="addthis_button_google_plusone" g:plusone:size="medium"></a>' +
			'<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>' +
			'<a class="addthis_button_tweet"></a>' +
			'<a class="addthis_counter addthis_pill_style"></a>' +
			'</div>' +
			'\<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4db1357d709d5410"\>\</script\>';

      var related = params.relevantLinks ? params.relevantLinks : '';

      var html = '<div class="pngfix otv video videootv ' + className + '" id="gv$galleryId$">' +
  		'<div class="l">' +
    		'<div class="animation">' +
      		'<div id="vg' + params.galleryId + '">' +
      		'</div>' +
      		'<!--<div class="info">' +
        		'<div class="l">' +
              '<div class="thumb-author">autor: '+ params.author +'</div>' +
        		'</div>' +
      		'</div>-->' +
    		'</div>' +
      soc + 
  		'</div>' +
  		'<div class="r">' +
        '<div class="content">' +
          '<a class="h1" href="#">$galleryName$</a>' +
	        '<span class="article-date" href="#"></span>' +
	        '<a class="discussion" href="#">Diskuze (?)</a>' +
          authorImage +
					'<h2 class="h2">' + authorName + '$galleryDescription$</h2>' +
          related +
          iframe + 
        '</div>' +
        banner + 
  		'</div>' +
  	'</div>';

		$.each(params, function(key, val){
        html = html.replace(new RegExp('\\$' + key + '\\$', 'g'), val == null ? '' : val);
    });

    $div = $(html).appendTo(params.parentDivId);

    if (turnOffLights)
    {
      if ($("#shadow").length == 0)
      {
        var shadow = '<div id="shadow" class="pngfix"></div>';
        $('body').prepend(shadow);
        $(".mm-ow-slot").hide();
        $("#shadow").click(function(){
          $('.lightSwitcher').click();
        });
      }
      
      $(turnOffLights).click(function(){
         $("#shadow").css("height", $(document).height()).toggle();
         if ($("#shadow").is(":hidden"))
             $(this).html("Zhasnout světlo").removeClass("turnedOff");
          else
             $(this).html("Rozsvítit světlo").addClass("turnedOff");
         return false;
       //}).prependTo($div.parent()).css({'margin' : '10px 0 -20px 25px', 'color' : '#007CA5'});
       }).insertBefore('.animation', $div).css({'margin' : '-15px 0 13px', 'color' : '#007CA5', 'position' : 'relative'});
     }


    if (params.multimediaUrl) 
    {
      $('#head').addClass('photohead');
      $('.heading').hide();
			discussionLink = params.articleLink + '#diskuze';
			discussionCount = params.discussionCount;
      $('.content .article-date', $div).html(params.articleDate);
    } else
    {
			//discussionLink = params.articleLink + '#diskuze';
      discussionLink = $('#comm-url').attr('href');
			discussionCount = params.discussionCount;
      $('.content .article-date', $div).html(params.articleDate);
    }

    if (params.respekt)
    {
      var frameUrl = params.respekt? 'http://respekt.ihned.cz/?p=RM0000_big' : 'http://multimedia.ihned.cz/?m=big'; 
      frameUrl += '&rn=' + Math.random(); 
      $('#gallery-iframe', $div).attr('src', frameUrl).show();
    }

    if (params.discussionLink)
      discussionLink = params.discussionLink; 

    $('.content A.h1', $div).attr('href', params.articleLink);
    if (discussionLink && discussionCount != '' && (params.multimediaUrl || $('A#comm-url').css('display')=='block')) /* $('A#comm-url:visible').length != 0 */
    {
      $('.content A.discussion', $div).attr('href', discussionLink)
                                      .html($('.content A.discussion', $div).html().replace('?', discussionCount))
                                      .before('&nbsp;<span class="date-disc-deli" style="color: #96C2E4">|</span>&nbsp;&nbsp;');
    }
    else
    {
      $('.content A.discussion', $div).css('display', 'none');
    }
    $('.content ul li:gt(1)', $div).css('display', 'none');

    // pozdeji:
		var urls = $.parseJSON($.ajax({url: params.video_urls, async: false}).responseText);
		//var urls = $.parseJSON($.ajax({url: 'js/j.json', async: false}).responseText);
		(new Image()).src = params.preview_image.url;
		opts = {
			ads : params.ads_enabled,
			divId : 'vg' + params.galleryId,
			flashvars : {
				streamHigh1: urls['1280']['0'],
				altstreamHigh1: urls['alt1280']['0'],
				streamMedium1: urls['608']['0'],
				altstreamMedium1: urls['alt608']['0'],
				streamLow1: urls['320']['0'],
				altstreamLow1: urls['alt320']['0'],
				imagefile1: params.preview_image.url
			},
			autoplay : params.autoplay
		};
		multimediaObjects.installVideo(opts);
	},

	installSinglePhotogallery : function(params)
	{
  		//var html = '<div class="fla"><a description="$fDescription$" normalHeight="$fNormalHeight$" normalWidth="$fNormalWidth$" href="$fBig$" rel="!lytebox[gf$galleryId$]" title="$fTitle$" author="$fAuthor$"><span></span><img style="$fStyle$" alt="$fAlt$" rel="$fNormal$" src="$fPreview$" width="$fWidth$" height="$fHeight$"></a></div>';
  		
      var rel = params.respekt ? '!lyteshow[gf$galleryId$]' : '!lytebox[gf$galleryId$-$index$]'; 
      var relMain0 = params.respekt ? 'lyteshow[gf$galleryId$]' : 'lytebox[gf$galleryId$-0]'; 
      var relMain1 = params.respekt ? 'lyteshow[gf$galleryId$]' : 'lytebox[gf$galleryId$-1]'; 

      if (params.bigGallery)
      {
        var rel = ''; 
        var relMain0 = ''; 
        var relMain1 = '';
        var href = ''; 
        var bigGallery = '<div class="galleryName">$galleryName$</div><div class="galleryDescription">$galleryDescription$</div>';
      } else
      {
        var bigGallery = '';
        var href = '$fBig$';
      }

      var html = '<div class="fla"><a description="$fDescription$" largeHeight="$fLargeHeight$" largeWidth="$fLargeWidth$" normalHeight="$fNormalHeight$" normalWidth="$fNormalWidth$" href="' + href + '" big="$fBig$" rel="' + rel + '" title="$fTitle$" author="$fAuthor$"><span></span><img style="$fStyle$" alt="$fAlt$" rel="$fNormal$" src="$fPreview$" width="$fWidth$" height="$fHeight$"></a></div>';
    	params.itemsHtml = '';
      $.each(params.items, function(key, val){
          var ihtml = html; 

	        if (val.normal_image.width == val.large_image.width &&
					    val.normal_image.height == val.large_image.height)
					{
						ihtml = ihtml.replace(new RegExp('\\$fBig\\$', 'g'), val.normal_image.url);
					} else
					{
						ihtml = ihtml.replace(new RegExp('\\$fBig\\$', 'g'), val.large_image.url);
					}
          ihtml = ihtml.replace(new RegExp('\\$galleryId\\$', 'g'), params.galleryId);
          ihtml = ihtml.replace(new RegExp('\\$fAlt\\$', 'g'), val.image_alt);
          ihtml = ihtml.replace(new RegExp('\\$fTitle\\$', 'g'), (val.name == null ? '' : val.name.replace(/"/ig, '&quot;').replace(/</ig, '&lt;').replace(/>/ig, '&gt;')));
          ihtml = ihtml.replace(new RegExp('\\$fDescription\\$', 'g'), (val.description == null ? '' : val.description.replace(/"/ig, '&quot;').replace(/</ig, '&lt;').replace(/>/ig, '&gt;')));
          ihtml = ihtml.replace(new RegExp('\\$fPreview\\$', 'g'), val.preview_image.url);
          
          if (params.bigGallery)
          {
            ihtml = ihtml.replace(new RegExp('\\$fNormal\\$', 'g'), val.large_image.url);
            ihtml = ihtml.replace(new RegExp('\\$fNormalHeight\\$', 'g'), val.large_image.height);
            ihtml = ihtml.replace(new RegExp('\\$fNormalWidth\\$', 'g'), val.large_image.width);
          } else
          {
            ihtml = ihtml.replace(new RegExp('\\$fNormal\\$', 'g'), val.normal_image.url);
            ihtml = ihtml.replace(new RegExp('\\$fNormalHeight\\$', 'g'), val.normal_image.height);
            ihtml = ihtml.replace(new RegExp('\\$fNormalWidth\\$', 'g'), val.normal_image.width);
          }

          ihtml = ihtml.replace(new RegExp('\\$fLargeHeight\\$', 'g'), val.large_image.height);
          ihtml = ihtml.replace(new RegExp('\\$fLargeWidth\\$', 'g'), val.large_image.width);
          ihtml = ihtml.replace(new RegExp('\\$fAuthor\\$', 'g'), (val.author == null ? '' : val.author.replace(/"/ig, '&quot;').replace(/</ig, '&lt;').replace('>', '&gt;')));
          ihtml = ihtml.replace(new RegExp('\\$index\\$', 'g'), key + 1);
          
          /*
            110 x 72 = 1,52
            83 x 56 = 1,48
          */
          if (val.preview_image.width > val.preview_image.height)
          {
            if (val.preview_image.width / val.preview_image.height <= 1.9)
            {
              var width = '100%'; // 110
              var height = '100%'; // 72 
              var style = '';
            } else
            {
              var width = '100%'; // 10
              var height = 'auto';
              var style = 'height: auto;';
            }
          } else
          {
            var style = 'width: auto;';
            var width = 'auto';
            var height = '100%'; // 72 
          }

          ihtml = ihtml.replace(new RegExp('\\$fWidth\\$', 'g'), width);
          ihtml = ihtml.replace(new RegExp('\\$fHeight\\$', 'g'), height);
          ihtml = ihtml.replace(new RegExp('\\$fStyle\\$', 'g'), style);

          params.itemsHtml += ihtml; 
      });

      var turnOffLights = '';
      var slideshowLink = '';

      if (params.respekt)
      {
        slideshowLink = '<a class="slideshow pngfix" href="#"></a>';
      }
  		if (($(params.parentDivId).html() != ''))
  		{
				className =  'second';
				banner = '';	
        iframe = '';			
			} else
			{
				className =  '';
				banner = '';				
        if (params.respekt)
        {
          iframe = '<iframe style="sdisplay: none" src="" id="gallery-iframe" width="300" height="300" frameborder="0" scrolling="no"></iframe>';
          turnOffLights = '<a class="lightSwitcher pngfix" href="#">Zhasnout světlo</a>';
        }
        else
        {
          iframe = '<iframe style="sdisplay: none" src="" id="gallery-iframe" width="300" height="300" frameborder="0" scrolling="no"></iframe>';
        }
				//banner = '<div id="r-big"><span id="r-big-ozn">reklama</span>' + $('<div>').append($('#col3-article #r-big object').clone()).remove().html() + '</div>';
			}

			var socUrl = window.location.href.replace(window.location.hash, '') + '#' + (params.multimediaUrl ? '' : 'fotogalerie-') + 'gf$galleryId$';
			var soc = 
			
			'<div class="addthis_toolbox addthis_default_style" addthis:title="$galleryName$" addthis:description="$galleryDescription$" addthis:url="' + socUrl + '">' +
      '<a class="addthis_button_google_plusone" g:plusone:size="medium"></a>' +
			'<a class="addthis_button_facebook_like" fb:like:layout="button_count" fb:like:width=\"auto\" ></a>' +
			'<a class="addthis_button_tweet"></a>' +
			'<a class="addthis_counter addthis_pill_style"></a>' +
			'</div>' +
			'\<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4db1357d709d5410"\>\</script\>'; 
			//'\<script src="http://platform.twitter.com/widgets.js" type="text/javascript"\>\</script\>';

      if (params.bigGallery)
      {
        soc = '';
        bigSoc = '<div class="one-plus-top">' +
					       '<g:plusone size="small" count="false"></g:plusone>' +
				         '</div>' +		
				'<div class="addthis_toolbox addthis_default_style addtop">' +
					'<a class="addthis_button_facebook" title="Sdílet na Facebooku"></a>' +
					'<a class="addthis_button_twitter" title="Sdílet na Twitteru"></a>' +
					'<a class="addthis_button_email" title="Poslat e-mailem"></a>' +
					'<a class="addthis_button_print" title="Tisknout"></a>' +
					'<a class="addthis_button_compact"></a><a class="addthis_counter addthis_bubble_style"></a>' +
				'</div>' + 
  			'\<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4db1357d709d5410"\>\</script\>' + 
        '\<script type="text/javascript" src="https://apis.google.com/js/plusone.js"\>\</script\>';
        thumbAutor = '<div class="thumb-author">autor: '+ (params.author == null ? '' : params.author) +'</div>' + 
                     '<div class="thumb-title-and-desc"><div class="thumb-title">'+ params.items[0].image_alt +'</div><div class="photoDescription"></div></div>';
      } else
      {
        bigSoc = '';
        thumbAutor = '<div class="thumb-title-and-desc"><div class="thumb-title">'+ params.items[0].image_alt +'</div><div class="photoDescription"></div></div>' +
                     '<div class="thumb-author">autor: '+ (params.author == null ? '' : params.author) +'</div>';
      }

      //var related = '<ul><li><a href="http://zpravy.ihned.cz/c1-52054920-vlada-se-stavkou-nenecha-vydirat-vzkazuje-odborarum-necas">Vláda se stávkou nenechá vydírat, vzkazuje odborářům Nečas</a></li><li><a href="http://zpravy.ihned.cz/c1-52054920-vlada-se-stavkou-nenecha-vydirat-vzkazuje-odborarum-necas">Vláda se stávkou nenechá vydírat, vzkazuje odborářům Nečas</a></li></ul>';
      var related = params.relevantLinks ? params.relevantLinks : '';

      var secondLink = (params.step_by_2_pics ? '<a href="' + params.items[1].large_image.url + '" rel="' + relMain1 + '" class="mainlink lt-ignore ml-right" ><div class="dragspan pngfix"></div><span></span><img alt="" src="' + params.items[1].normal_image.url + '" /></a>' : '');

      var html = '<div class="pngfix otv photootv ' + className + '" id="gf$galleryId$">' +
  		'<div class="l pngfix">' +
    		'<div class="animation">' +
        
        bigGallery +
        
        '<div class="top">' +
          '<a href="" class="prev pngfix"></a>' +
          '<div class="count">1 / 10</div>' +
    		  '<a href="" class="next pngfix"></a>' +
      		bigSoc +
          slideshowLink + 
    		'</div>' +

         //'<div><a href="' + params.items[0].large_image.url + '" rel="lytebox[gf$galleryId$]" class="mainlink lt-ignore" ><span></span><img alt="" src="' + params.items[0].normal_image.url + '" /></a></div>' +

        '<div class="fg-pict"><div id="f-hlp" style="">Odkryjte obrázek tažením vybrané šipky</div><a href="' + params.items[0].large_image.url + '" rel="' + relMain0 + '" class="mainlink lt-ignore ml-left" ><div class="dragspan pngfix"></div><span></span><img alt="" src="' + params.items[0].normal_image.url + '" /></a>' + secondLink + '</div>' +

      		'<div class="info">' +
        		'<div class="l">' +
              /*'<div class="thumb-title">'+ params.items[0].image_alt +'</div>' +*/
              thumbAutor +
        		'</div>' +
      		'</div>' +
    		'</div>' +
  
    		'<div class="thumbs">' +
      		'<div class="content">' +
      		  '$itemsHtml$' +
      		'</div>' +
    		'</div>' +
    		soc +
  		'</div>' +
  		'<div class="r">' +
        '<div class="content">' +
          '<a class="h1" href="#">$galleryName$</a>' +
	        '<span class="article-date" href="#"></span>' +
	        '<a class="discussion" href="#">Diskuze (?)</a>' +
          '<h2>$galleryDescription$</h2>' +

          related +
          iframe + 

        '</div>' +
        banner +
  		'</div>' +
  	'</div>';

		$.each(params, function(key, val){
        html = html.replace(new RegExp('\\$' + key + '\\$', 'g'), val == null ? '' : val);
    });

    var $div = $(html).appendTo(params.parentDivId);

    if (turnOffLights)
    {
      if ($("#shadow").length == 0)
      {
        var shadow = '<div id="shadow" class="pngfix"></div>';
        $('body').prepend(shadow);
        $(".mm-ow-slot").hide();
        $("#shadow").click(function(){
          $('.lightSwitcher').click();
        });
      }
      
      $(turnOffLights).click(function(){
         $("#shadow").css("height", $(document).height()).toggle();
         if ($("#shadow").is(":hidden"))
         {
           $(".count").css({color: 'black'});
           $(".info").css({color: 'black'});
           $(".mm-ow-slot").css({color: 'black'});
           $("A.mainlink").css({background: '#E0E0E2'});
					 $(".jspTrack").removeClass('trackBlack');
           $(this).html("Zhasnout světlo").removeClass("turnedOff");
         }
          else
         {
           $(".info").css({color: 'white'});
           $(".count").css({color: 'white'});
           $(".mm-ow-slot").css({color: '#9D9D9F'});
           $("A.mainlink").css({background: 'black'});
           $(".jspTrack").addClass('trackBlack');
           $(this).html("Rozsvítit světlo").addClass("turnedOff");
         }
         return false;
       }).prependTo($('.animation', $div));
     }

    if (params.multimediaUrl) 
    {
      $('#head').addClass('photohead');
			discussionLink = params.articleLink + '#diskuze';
			discussionCount = params.discussionCount;
      $('.content .article-date', $div).html(params.articleDate);
    } else
    {
			discussionLink = params.articleLink + '#diskuze';
      discussionLink = $('#comm-url').attr('href');
			discussionCount = params.discussionCount;
      $('.content .article-date', $div).html(params.articleDate);

      /*
      discussionLink = $('#comm-url').attr('href');
			discussionCount = $('#comm-url').html().split('(')[1].replace(')', '');
			*/
    }

    if (params.discussionLink)
      discussionLink = params.discussionLink; 

    if ($.browser.msie == true && $.browser.version <= 7)
    {
      addthis.addEventListener('addthis.ready', function(e){
        $(".addthis_button_tweet iframe").attr("src", function(i, val){
          return val.replace('?', '#'); 
        });
      });
    }

    var viewingMethod = firstClick = hashCanBeChangedOnLoad = true;
    var firstPhotoIndex = 0;
    
    //hashCanBeChangedOnLoad = (!window.location.hash/* || (!params.multimediaUrl && window.location.hash.split('-').length < 3)*/);
    hashCanBeChangedOnLoad = !firstClick;
    var hashes = window.location.hash.substring(1).split('-');
    if (params.multimediaUrl) 
    {
      if (hashes.length >= 3 && hashes[0] == 'gf' + params.galleryId)
      {
        firstPhotoIndex = parseInt(hashes[1])-1;
  			$(document).scrollTop($('#' + hashes[0]).offset().top);
      }
    } else
    {
      if (hashes.length >= 4 && hashes[1] == 'gf' + params.galleryId)
      {
        firstPhotoIndex = parseInt(hashes[2])-1; 
      }
    }

    firstPhotoIndexLink =  $('.thumbs .content a', $div).get(firstPhotoIndex);

    if (params.allowReloading)
    {
      var domainInfos = {
	'zpravy.ihned.cz':	['http://zpravy.ihned.cz/?m=big',	'ofHgIj7HG0oirpAccCckO2YmzeB15ydwq3wYQx3eUtf.l7'],
	'byznys.ihned.cz':	['http://byznys.ihned.cz/?m=big',	'AfhK5i7sBxryo6dJGKuZL5R8LSqiMubAJjFo1y76WqP.N7'],
	'life.ihned.cz'	:	['http://life.ihned.cz/?m=big',		'AfhKhi7sB5uSFqcXsIQR4ZR8j1iiMg8I8O405DPY5vf.17'],
	'art.ihned.cz'	:	['http://art.ihned.cz/?m=big',		'nd1L_vrePEGOq_Fa0MrVqaei3_jgqi_qC_mUujucC4j.c7'],
	'tech.ihned.cz'	:	['http://tech.ihned.cz/?m=big',		'ofHqxj7H9_KIAS2s_Z2su2aG7zd1p898C6tkrmZ3Lzf.N7'],
	'sport.ihned.cz':	['http://sport.ihned.cz/?m=big',	'.F5AgnfkK4HNK9AUnEJsHoZRzXZF0yeUq98YwWZuUi3.W7'],
	'dialog.ihned.cz':	['http://dialog.ihned.cz/?m=big',	'.F3qxnfk9_HHDgdjM0PBzoZRLSpF0_bAS3vCUu65wuT.l7']
      }
      
      viewingMethod = function(link, linkIndex)
      {
        if (params.respekt)
        {
          var frameUrl = 'http://respekt.ihned.cz/?p=RM0000_big'; 
          var gemiusId = '1vCb6_Lh7NaTrzIxshmqe5YUzdtF0ycyS1N1fj6OVlr.b7';
        } else
        {
          var frameUrl = 'http://multimedia.ihned.cz/?m=big'; 
          var gemiusId = '1vCb6_Lh7NaTrzIxshmqe5YUzdtF0ycyS1N1fj6OVlr.b7';
          if (domainInfos[location.host])
          {
            var frameUrl = domainInfos[location.host][0]; 
            var gemiusId = domainInfos[location.host][1];
          }
        }
        
        //var frameUrl = params.respekt? 'http://respekt.ihned.cz/?p=RM0000_big' : 'http://multimedia.ihned.cz/?m=big'; 

        var temp = link.attr('rel').split('[')[1].replace(']', '').split('-')[0] + '-' + (linkIndex + 1);
        var hash = temp + '-' + params.id;
        frameUrl += '&rn=' + Math.random() + '#' + hash; 

        if (params.multimediaUrl) 
        {
    			$('.col3 #r-big').hide();
          if (!firstClick || hashCanBeChangedOnLoad)
            window.location.hash = hash;        
        } else
        {
    			//$('#heading .r #r-big').hide();
          if (!firstClick || hashCanBeChangedOnLoad)
            window.location.hash = 'fotogalerie-' + hash;        
        }
        
        $('#gallery-iframe', $div).attr('src', frameUrl).show();
        if (!firstClick)
        {
        if (typeof pp_gemius_hit == 'function')
          pp_gemius_hit(gemiusId);
        }
        firstClick = false;
      }
    }

    //$('.thumbs .content a', $div).gallery({'viewer' : '.animation a img', 'viewingMethod' : viewingMethod, 'firstPhotoIndex' : firstPhotoIndex});
    //$('.thumbs .content a', $div).gallery({'viewer' : '.animation a img', 'viewingMethod' : viewingMethod, 'firstPhotoIndex' : firstPhotoIndex, 'rootEl' : $div, 'installDragger' : params.step_by_2_pics});
    
    $('.content A.h1', $div).attr('href', params.articleLink);

    if (discussionLink && discussionCount != '' && (params.multimediaUrl || $('A#comm-url').css('display')=='block')) /*$('A#comm-url:visible').length != 0*/
    {
      $('.content A.discussion', $div).attr('href', discussionLink)
                                      .html($('.content A.discussion', $div).html().replace('?', discussionCount))
                                      .before('&nbsp;<span class="date-disc-deli" style="color: #96C2E4">|</span>&nbsp;&nbsp;');
    }
    else
    {
      $('.content A.discussion', $div).css('display', 'none');
    }
    $('.content ul li:gt(1)', $div).css('display', 'none');
    
    $mainLink = $('.mainlink', $div);

    if (params.step_by_2_pics)
    {
      $mainLink.parent().css({float: 'left', display: 'block', width: 600, 'border' : '1px solid #9D9D9F'});
      $mainLink.data({width: '600px', height: '341px'});

   		$('.ml-right', $div).css({'width': '300', 'float' : 'left'});
  		$('.ml-right SPAN', $div).hide();
  		$('.ml-right IMG', $div).css({ position: 'absolute', right: '0'});

  		$('.ml-left', $div).css({'width': '299', 'float' : 'left'});
  		$('.ml-left IMG', $div).css({float: 'left'});
  		$('.ml-left SPAN', $div).hide();

      $('.dragspan', $div).show();

      $('.thumbs .fla', $div).filter(':odd').hide();
    } else
    {
  		//$('.ml-left', $div).css({'float' : 'left'});
      if (params.bigGallery)
      {
        $mainLink.data({width: '900px', height: '600px'}).css({width: '100%', height: '600px'});
        $mainLink.parent().css({float: 'left', tableLayout : 'fixed', width: '100%'});
      } else
      {
        $mainLink.data({width: '600px', height: '341px'});
        $mainLink.parent().css({float: 'left', tableLayout : 'fixed', width: 600, border : '1px solid #CFCFCF'});
      }
      try{$mainLink.parent().css({display: 'table'});} catch(e){}
    }

    $('.thumbs .content a', $div).gallery({'viewer' : '.animation a img', 'viewingMethod' : viewingMethod, 'firstPhotoIndex' : firstPhotoIndex, 'rootEl' : $div, 'installDragger' : params.step_by_2_pics, 'installSlideshow' : params.respekt, 'bigGallery' : params.bigGallery});

    $('.thumbs', $div).bind('jsp-initialised', function(event, isScrollable, jsp){
      //if (jsp) jsp.scrollToElement(firstPhotoIndexLink, false, false);
      var flaOWidth = $('.thumbs .content .fla', $div).actual('outerWidth');
      var flaMarginL = parseInt($('.thumbs .content .fla', $div).css('marginLeft'));
      var flaMarginR = parseInt($('.thumbs .content .fla', $div).css('marginRight'));
      flaOWidth += flaMarginL + flaMarginR;  

      var flaWidth = $('.thumbs .content .fla', $div).actual('width'); 
      if (jsp) jsp.scrollToX((firstPhotoIndex * flaOWidth) + flaWidth -600 /*+4*/);
    }); 


    // Scrollbar
    if (params.bigGallery)
    {
      var thumbsWidth = $('.thumbs', $div).actual('width'); // 637
      var thumbsHeight = 105;
      //var size = ((101 + 20) * (params.step_by_2_pics ? params.items.length / 2 : params.items.length)) - (10 * 2); size = isNaN(size) ? 0 : size + 5; $('.thumbs .content', $div).width(size); 
      var size = ((99 + 20) * (params.step_by_2_pics ? params.items.length / 2 : params.items.length)) - (10 * 2); size = isNaN(size) ? 0 : size + 20; $('.thumbs .content', $div).width(size); 
      $mainLink.click(function(){
        return false;
      });
      $div[0].oncontextmenu = function() { return false; };
    } else
    {
      var thumbsWidth = $('.thumbs', $div).actual('width'); // 637
      var thumbsHeight = 105;
      var size = ((112 + 8) * (params.step_by_2_pics ? params.items.length / 2 : params.items.length)) - (4 * 2); size = isNaN(size) ? 0 : size; $('.thumbs .content', $div).width(size); 
      $('.thumbs .content', $div).children().first().css('marginLeft', '0px');
    }
    if (thumbsWidth > size) $('.thumbs', $div).height('auto'); else $('.thumbs', $div).jScrollPane({contentWidth: $('.thumbs .content', $div).actual('width'), animateScroll : true, enableKeyboardNavigation : false});

    //if ($('.thumbs', $div).data('jsp')) $('.thumbs', $div).data('jsp').scrollToElement(firstPhotoIndexLink, false, false); 

    if (params.step_by_2_pics)
    {
      $('.thumbs .content', $div).children().filter(':even').last().css('marginRight', '0px');
    } else
    {
      $('.thumbs .content', $div).children().last().css('marginRight', '0px');
    }

    initLytebox();

	},

	installPhotogallery : function(params)
	{
  		var html = '<div class="fla"><a description="$fDescription$" largeHeight="$fLargeHeight$" largeWidth="$fLargeWidth$" normalHeight="$fNormalHeight$" normalWidth="$fNormalWidth$" href="$fBig$" rel="!lytebox[gf$galleryId$-$index$]" title="$fTitle$" author="$fAuthor$"><span></span><img style="$fStyle$" alt="$fAlt$" rel="$fNormal$" src="$fPreview$" width="$fWidth$" height="$fHeight$"></a></div>';
    	params.itemsHtml = '';
      $.each(params.items, function(key, val){
          var ihtml = html; 

	        if (val.normal_image.width == val.large_image.width &&
					    val.normal_image.height == val.large_image.height)
					{
						ihtml = ihtml.replace(new RegExp('\\$fBig\\$', 'g'), val.normal_image.url);
					} else
					{
						ihtml = ihtml.replace(new RegExp('\\$fBig\\$', 'g'), val.large_image.url);
					}
          ihtml = ihtml.replace(new RegExp('\\$galleryId\\$', 'g'), params.galleryId);
          ihtml = ihtml.replace(new RegExp('\\$fAlt\\$', 'g'), val.image_alt);
          ihtml = ihtml.replace(new RegExp('\\$fTitle\\$', 'g'), (val.name == null ? '' : val.name.replace(/"/ig, '&quot;').replace(/</ig, '&lt;').replace(/>/ig, '&gt;')));
          ihtml = ihtml.replace(new RegExp('\\$fDescription\\$', 'g'), (val.description == null ? '' : val.description.replace(/"/ig, '&quot;').replace(/</ig, '&lt;').replace(/>/ig, '&gt;')));
          ihtml = ihtml.replace(new RegExp('\\$fPreview\\$', 'g'), val.preview_image.url);
          ihtml = ihtml.replace(new RegExp('\\$fNormal\\$', 'g'), val.normal_image.url);
          ihtml = ihtml.replace(new RegExp('\\$fNormalHeight\\$', 'g'), val.normal_image.height);
          ihtml = ihtml.replace(new RegExp('\\$fNormalWidth\\$', 'g'), val.normal_image.width);
          ihtml = ihtml.replace(new RegExp('\\$fLargeHeight\\$', 'g'), val.large_image.height);
          ihtml = ihtml.replace(new RegExp('\\$fLargeWidth\\$', 'g'), val.large_image.width);
          ihtml = ihtml.replace(new RegExp('\\$fAuthor\\$', 'g'), (val.author == null ? '' : val.author.replace(/"/ig, '&quot;').replace(/</ig, '&lt;').replace(/>/ig, '&gt;')));
          ihtml = ihtml.replace(new RegExp('\\$index\\$', 'g'), key + 1);
          
          /*
            110 x 72 = 1,52
            83 x 56 = 1,48
          */
          if (val.preview_image.width > val.preview_image.height)
          {
            if (val.preview_image.width / val.preview_image.height <= 1.9)
            {
              var width = '100%'; // 110
              var height = '100%'; // 72 
              var style = '';
            } else
            {
              var width = '100%'; // 10
              var height = 'auto';
              var style = 'height: auto;';
            }
          } else
          {
            var style = 'width: auto;';
            var width = 'auto';
            var height = '100%'; // 72 
          }

          ihtml = ihtml.replace(new RegExp('\\$fWidth\\$', 'g'), width);
          ihtml = ihtml.replace(new RegExp('\\$fHeight\\$', 'g'), height);
          ihtml = ihtml.replace(new RegExp('\\$fStyle\\$', 'g'), style);

          params.itemsHtml += ihtml; 
      });

			className =  '';
			banner = '';				

      var html = 
    		'<div class="embed-gallery">' +
         '<div><a href="' + params.items[0].large_image.url + '" rel="lytebox[gf$galleryId$]" class="mainlink lt-ignore" ><span></span><img alt="" src="' + params.items[0].normal_image.url + '" /></a></div>' +
          '<a href="" class="prev pngfix"></a>' +
    		  '<a href="" class="next pngfix"></a>' +
      		'<div class="info pngfix">' +
        		'<div class="l">' +
              '<div class="thumb-title">'+ params.items[0].image_alt +'</div>' +
              '<div class="thumb-author" style="display: none">autor: '+ (params.author == null ? '' : params.author) +'</div>' +
              '<div class="count">1 / 10</div>' +
        		'</div>' +
      		'</div>' +
    		'</div>' +
    		'<div class="thumbs" style="display: none">' +
      		'<div class="content">' +
      		  '$itemsHtml$' +
      		'</div>' +
    		'</div>';

		$.each(params, function(key, val){
        html = html.replace(new RegExp('\\$' + key + '\\$', 'g'), val == null ? '' : val);
    });

//    width = $(params.parentDivId).width();
//    height = $(params.parentDivId).height();
    var width = params.width;
    var height = params.height;
    $(params.parentDivId).html('');

    $div = $(html).appendTo(params.parentDivId).width(width).height(height).css({position: 'relative', overflow: 'hidden'});

    //$mainLink = $('.mainlink', $div).width(width).height(height - 50 + 7).data({width: width, height: height - 50 + 7}); toto bylo zakomentovane
    $mainLink = $('.mainlink', $div).width(width).height(height).data({width: width, height: height});

    $mainLink.parent().css({display: 'table', tableLayout : 'fixed', width: width});
    //$prevLink = $('.prev', $div).css({top: ((height - 50 + 7) / 2) - (25) + 'px'});
    //$nextLink = $('.next', $div).css({top: ((height - 50 + 7) / 2) - (25) + 'px', left : (width - 64) + 'px'});
    $prevLink = $('.prev', $div).css({top: ((height) / 2) - (25) + 'px'});
    $nextLink = $('.next', $div).css({top: ((height) / 2) - (25) + 'px', left : (width - 64) + 'px'});

    $div.click(function(){
			var transparentTitle = $(params.parentDivId).parent('A').siblings('.title.pngfix').hide();
			var transparentTitle = $(params.parentDivId).siblings('.title.pngfix').hide();
		});

    $nextLink.click(function(){
			var transparentTitle = $(params.parentDivId).parent('A').siblings('.title.pngfix').hide();
			var transparentTitle = $(params.parentDivId).siblings('.title.pngfix').hide();
		});

    if (1 || $.browser.mozilla)
    {
			$div.parent().css('overflow', 'hidden').css('position', 'relative');
		}

    $('.thumbs .content a', $div.parent()).gallery({'viewer' : '.embed-gallery a img', 'rootEl' : $div.parent(), 'hidableInfo' : true});

    //initLytebox();

	},

	installPhotogalleryAttention : function(params)
	{
  	var links = '';

    $.each(params.items, function(key, val){
      if (key > 2) return false;
      var style = key > 2 ? 'style="display: none"' : '';
      links += '<a onclick="activatePhotoTabByHash(\'#fotogalerie-gf$galleryId$-' + (key + 1) + '\'); return false;"' + style + ' author="' + val.Author + '"  description="' + val.Description + '" title="' + val.Title + '" href="' + val.Big + '" rel="lytenobox[ga$galleryId$-' + key + ']"><img alt="' + val.Alt + '" src="' + val.Small + '" style="' + val.Wide + '" border="0" /></a>'; 
    });

    var html = '<div class="photogallery-atention">' +
			'<a href="#" class="heading" onclick="activatePhotoTabByHash(\'#fotogalerie-gf$galleryId$-1\'); return false;">Fotogalerie</a>' +
			'<div class="photos">' +
			   links +
			'</div>' +
			'<a href="#" class="sub-heading" onclick="activatePhotoTabByHash(\'#fotogalerie-gf$galleryId$-1\'); return false;">$galleryName$</a>' +
      '<div class="clean"></div>' +
			'<a href="#" onclick="activatePhotoTabByHash(\'#fotogalerie-gf$galleryId$-1\'); return false;" class="go-to">přejít do fotogalerie</a>' +
		'</div>';
		$.each(params, function(key, val){
        html = html.replace(new RegExp('\\$' + key + '\\$', 'g'), val == null ? '' : val);
    });
    $('#' + params.divId).html(html);
    initLytebox();
	},


	// pokud je hodnota v elementId parametru, tak jde o instalaci na vypis
	// pokud ne, tak na detail
	installSingleObject : function(params, elementId, width, height, enabledObjects)
	{

		if (elementId && enabledObjects)
		{
			enabledObjects = enabledObjects.split(',');
			//if (params.type == 'gallery' || $.inArray(params.type, enabledObjects) == -1) return;
			if ($.inArray(params.type, enabledObjects) == -1) return;
		}
		
    switch (params.type)
		{
			case 'video':
				if (elementId || params.element_id)
  			{
          // pozdeji:
					var urls = $.parseJSON($.ajax({url: params.video_urls, async: false}).responseText);
					//var urls = $.parseJSON($.ajax({url: 'js/j.json', async: false}).responseText);
					(new Image()).src = params.preview_image.url;
					opts = {
						ads : params.ads_enabled,
						divId : elementId || params.element_id,
						flashvars : {
							streamHigh1: urls['1280']['0'],
							altstreamHigh1: urls['alt1280']['0'],
							streamMedium1: urls['608']['0'],
							altstreamMedium1: urls['alt608']['0'],
							streamLow1: urls['320']['0'],
							altstreamLow1: urls['alt320']['0'],
							imagefile1: params.preview_image.url
						},
						width: width,
						height: height,
						disableParentClick : typeof elementId != 'undefined'
					};
					multimediaObjects.installVideo(opts, typeof elementId != 'undefined');
				}
				if (!elementId)
				{
					opts = {
							parentDivId : params.parentSelector || '#col123d-video',
							galleryName : params.name,
							galleryDescription : params.description,
							galleryId : params.iobject_id
					}
	    		var opts = $.extend(true, params, opts);
					multimediaObjects.installSingleVideo(opts);
				}
			break;

			case 'info_graphic':
				if (elementId || params.element_id)
  			{
					opts = {
							divId : elementId || params.element_id,
							width: width,
							height: height,
							disableParentClick : typeof elementId != 'undefined' 
					}
	    		var opts = $.extend(true, params, opts);
					multimediaObjects.installInfographic(opts, typeof elementId != 'undefined');
  			}
				if (!elementId)
				{
					opts = {
							parentDivId : params.parentSelector || '#col123d-infographic',
							galleryName : params.name,
							galleryDescription : params.description,
							galleryId : params.iobject_id
					}
	    		var opts = $.extend(true, params, opts);
					multimediaObjects.installSingleInfographic(opts);
				}
			break;

			case 'embedded_video':
				if (elementId || params.element_id)
  			{
					(new Image()).src = params.preview_image.url;
					opts = {
						ads : params.ads_enabled,
						divId : elementId || params.element_id,
						width: width,
						height: height,
						disableParentClick : typeof elementId != 'undefined' 
					};
	    		var opts = $.extend(true, params, opts);
					multimediaObjects.installExternalVideo(opts, typeof elementId != 'undefined');
				}
				if (!elementId)
				{
					opts = {
							parentDivId : params.parentSelector || '#col123d-video',
							galleryName : params.name,
							galleryDescription : params.description,
							galleryId : params.iobject_id
					}
	    		var opts = $.extend(true, params, opts);
					multimediaObjects.installSingleExternalVideo(opts);
				}
			break;

			case 'gallery':
  			if (elementId || params.element_id)
  			{
					if (elementId)
					{
  					opts = {
 							galleryId : params.iobject_id,
  						parentDivId : '#' + elementId,
  						width: width,
  						height: height,
  						disableParentClick : typeof elementId != 'undefined' 
  					};
  	    		var opts = $.extend(true, params, opts);
  					multimediaObjects.installPhotogallery(opts);
          } else
          {
            
            var displayWide = function(width, height) {
              if (height >= width) 
              {
                return true;
              } else
              {
                var viewerLinkWidth = 186;
                var viewerLinkHeight = 122;
                var resizedHeight = viewerLinkWidth / (width / height);
                return resizedHeight >= viewerLinkHeight; 
              }  
            }

          	var items = [];
            $.each(params.items, function(k, val){
            	var o = {};
  						o['Alt'] = params.items[k].image_alt; 
  						o['Title'] = (params.items[k].name == null ? '' : params.items[k].name.replace(/"/ig, '&quot;').replace(/</ig, '&lt;').replace(/>/ig, '&gt;')); 
  						o['Description'] = (params.items[k].description == null ? '' : params.items[k].description.replace(/"/ig, '&quot;').replace(/</ig, '&lt;').replace(/>/ig, '&gt;')); 
  						o['Author'] = (params.items[k].author == null ? '' : params.items[k].author.replace(/"/ig, '&quot;').replace(/</ig, '&lt;').replace(/>/ig, '&gt;')); 
  						o['Big'] = params.items[k].large_image.url;
  						o['Small'] = params.items[k].normal_image.url;
              o['Wide'] = displayWide(params.items[k].normal_image.width, params.items[k].normal_image.height) ? 'width: 186px; height: auto;' : 'width: auto; height: 122px;';
  						o['Diff'] = Math.abs((186 / 122)  - params.items[k].normal_image.width / params.items[k].normal_image.height);
              items.push(o);
            });

            //items.sort(function(a,b){ return a['Diff']-b['Diff']; });
            
            opts = {
  						galleryId : params.iobject_id,
  						divId : params.element_id,
  						galleryName : params.name,
  						items : items
  					}

  					multimediaObjects.installPhotogalleryAttention(opts);
					}
			 }
 			 if (!elementId)
			 {
  				opts = {
  						parentDivId : params.parentSelector || '#col123d-gallery',
  						galleryName : params.name,
  						galleryDescription : params.description,
  						galleryId : params.iobject_id
  				}
      		var opts = $.extend(true, params, opts);
  				multimediaObjects.installSinglePhotogallery(opts);
			}
			break;
		}


	},

	// returns the array of presented multimedia objects
  install : function(params, enabledObjects, extendedParams, useAutoplay)
	{
		if (enabledObjects)
		{
			enabledObjects = enabledObjects.split(',');
		}
		if (useAutoplay)
		{
	    var c = 0;
			$.each(params, function(key, val){
					if (enabledObjects && $.inArray(val.type, enabledObjects) != -1) c++;
			});
			if (c == 1)
			{
				extendedParams.autoplay = true;
			}
		}
		var presented = {};
    $.each(params, function(key, val){
				if (extendedParams != null) var val = $.extend(val, extendedParams);
				if (enabledObjects && $.inArray(val.type, enabledObjects) == -1) return true;

				presented[val.type] = true;
				multimediaObjects.installSingleObject(val);
		});
	
		return presented;
	}

}

function getAdServerParams() { 
	return {
		preRollURL: "http://go.cz.bbelements.com/please/showit/2059/25/1/7/?typkodu=js&_xml=1"+bbh+"&alttext=0&border=0",
		midRollURL: "http://go.cz.bbelements.com/please/showit/2059/25/2/7/?typkodu=js&_xml=1"+bbh+"&alttext=0&border=0",
		postRollURL: "http://go.cz.bbelements.com/please/showit/2059/25/3/7/?typkodu=js&_xml=1"+bbh+"&alttext=0&border=0",
		midRollRequestInterval: 90
	}
}

function noAdServerParams() {
	return {}
}

var bbs=screen,bbn=navigator,bbh;bbh='&ubl='+bbn.browserLanguage+'&ucc='+bbn.cpuClass+'&ucd='+bbs.colorDepth+'&uce='+bbn.cookieEnabled+'&udx='+bbs.deviceXDPI+'&udy='+bbs.deviceYDPI+'&usl='+bbn.systemLanguage+'&uje='+bbn.javaEnabled()+'&uah='+bbs.availHeight+'&uaw='+bbs.availWidth+'&ubd='+bbs.bufferDepth+'&uhe='+bbs.height+'&ulx='+bbs.logicalXDPI+'&uly='+bbs.logicalYDPI+'&use='+bbs.fontSmoothingEnabled+'&uto='+(new Date()).getTimezoneOffset()+'&uti='+(new Date()).getTime()+'&uui='+bbs.updateInterval+'&uul='+bbn.userLanguage+'&uwi='+bbs.width;
if(typeof(bburlparam)=='string') { bbh+='&'+bburlparam; }
if(typeof(bbkeywords)=='string') { bbh+='&keywords='+escape(bbkeywords); }
var bbIframeUrls={};
var bbw=window,bbiw=0,bbih=0;
if(document.body) if(bbw.innerWidth){bbiw=bbw.innerWidth;bbih=bbw.innerHeight;}else{bbiw=document.body.clientWidth;bbih=document.body.clientHeight;}
bbh+='&__INWIDTH='+bbiw+'&__INHEIGHT='+bbih;
var bbcb=(document.bgColor)?document.bgColor.substr(1):'FFFFFF',bbct=(document.fgColor)?document.fgColor.substr(1):'000000',bbcl=(document.linkColor)?document.linkColor.substr(1):'0000FF';

