var flag_discussion = false;
		
(function($){
	$(function(){
		var presented = multimediaObjects.install(iobjects, 'video,info_graphic,embedded_video,gallery', extendData);
		presented['discussion'] = presented['article'] = true;
		
		$("#heading .tabs-d LI").each(function(){
			var search = {
				'Článek' : 'article',
				'Video' : 'video',
				'Infografika' : 'info_graphic',
				'Fotogalerie' : 'gallery',
				'Diskuse' : 'discussion'
			};
			var search2 = {
				'Video' : 'embedded_video'
			};
			if (presented[search[$('A', this).html().split(' ')[0]]] || presented[search2[$('A', this).html().split(' ')[0]]])
			{
				$(this).show();
			}	
		});
		$("#heading .tabs-d").show();
		
		// Font Scaling
		var selector = '#text'; // #text p
		$(".ico-zoom-plus").fontscale(selector,"up",{unit:"px",increment:1.0});
		$(".ico-zoom-minus").fontscale(selector,"down",{unit:"px",increment:1.0});
		$(".ico-zoom").fontscale(selector,"reset");
		
		activatePhotoTabByHash = function(hasho){

		  activateTabByHash(hasho);

			hash = hasho.substring(1).split('-');
		  if ($('#' + hash[1]).data('gallery'))
		  {
        $('#' + hash[1]).data('gallery').setPhoto(parseInt(hash[2])-1);
      }

		}

		activateTabByHash = function(hash, step, search){
			var search = search || {
				'clanek' : 'Článek',
				'video' : 'Video',
				'infografika' : 'Infografika',
				'fotogalerie' : 'Fotogalerie',
				'diskuze' : 'Diskuse'
			};
			if (hash)
			{
				var step = step || 1;
				hash = hash.substring(1).split('-');
				if (step == 1)
				{
					if (search[hash[0]])
					{
						$(".tabbing").hide();
						$("#heading .tabs-d LI").each(function(){
							if ($('A', this).html().indexOf(search[hash[0]]) != -1)
							{
								$("#heading .tabs-d LI").removeClass('active');
								$(this).addClass('active');
								$(this).click();
								$(document).scrollTop($('#' + hash[1]).offset().top);
							}
						});
					}
				}
				
				
				if (hash[0]=="comm") {
					flag_discussion = true;
					$("#heading .tabs-d LI").removeClass("active");
					$("#comm-url").parent().addClass("active");
					$("#text, .relevants, #sklikReklama_8801,.social-bottom-detail").css("display","none");
				}
				
			}
		}

		onChangeTab = function(obj){
			$('.tabbing').hide();
			obj.parent().removeClass('black-tabs');
			switch ($('A', obj).html())
			{
				case 'Článek':
					if (flag_discussion) {
						var aid = $('H1 A').attr('href');
						var p1 = aid.indexOf("/c1-");
						var p2 = aid.indexOf("-",p1+4);
						aid = aid.substring(p1+4,p2);
						var re1=/^[0-9]{8}$/;
						
						var apage = window.location.href;
						p1 = apage.indexOf("p=");
						p2 = apage.indexOf("&",p1+2);
						apage = apage.substring(p1+2,p2);
						var re2=/^[a-zA-Z0-9]{6}_d$/;
						
						if (re1.test(aid) && re2.test(apage)) { location.href='/?p='+apage+'&article[id]='+aid; } else { location.href=$('H1 A').attr('href'); }
					}
					$('#col12d-article').show();
					$('#col3-article').show();
				break;
				case 'Video':
					$('#col123d-video').show();
				break;
				case 'Infografika':
					$('#col123d-infographic').show();
				break;
				case 'Fotogalerie':
					$('#col123d-gallery').show();
				break;
			}
			if ($('A', obj).html().indexOf('Diskuse') != -1)
			{
				if (!flag_discussion) {
					if ($('#comm-url').attr('href')!="#") location.href=$('#comm-url').attr('href');
				} else {
					$('#col12d-article').show();
					//$('#col12d-discussion').show();
					$('#col3-article').show();
				}
				
			}
		};
		
		// Tabs
		var opts = { onClick: onChangeTab };
		$("#heading .tabs-d").tabs(opts);
		activateTabByHash(window.location.hash);

	});
		
	$(window).load(function(){
		// Zoomer
		var maxWidth = 615;	// 602
		var opts = {
			maxAllowedWidth: maxWidth,
			maxWidth: null,
			onBeforeMaximized: function() { $(this).css({marginLeft: '39px'}); },
			onAfterMaximized: function() { $('.zoom', this).addClass('minizoom'); },
			onAfterMinimized: function() { $('.zoom', this).removeClass('minizoom'); $(this).css({marginLeft: '15px'}); },
			supressMarginBeforeMaximize : {Left : true, Right : false}
		};
		$('div.picture, .d-elm.zoomable').objectZoomer(opts);
	});
	
})(jQuery);
