﻿// Funkce spouštěné při načítání stránky


	// Fce pro vytvoreni bezpecneho odkazu
	inCMS.initLinks = function() {
		var mailList = $('span.link');
		mailList.each(function(){
			var mail = $(this).html().replace('(zavinac)','@');
			mail = mail.replace(/\(tecka\)/g,'.');
			$(this).html('<a href="mailto:'+mail+'" title="'+mail+'">' + mail +'</a>');
		});
	}
	inCMS.initLinks();


	// Inicializace pozadi stranky
	$('body').css({
		/*height: $(document).height(),*/
		backgroundPosition: 'center bottom'
	});

	var corners = '<span class="corner cornerTL" /><span class="corner cornerTR" /><span class="corner cornerBL" /><span class="corner cornerBR" />';

	// Fce pro pridani kulatych rohu k obrazkum
	inCMS.initImageCorners = function() {
		$('img.bordered').each(function() {
			var imgContainer = $('<span class="imgContainer"></span>');
			$(this).before(imgContainer);
			$(imgContainer).append($(this)).append(corners).css({
				'float': $(this).css('float'), 'width': $(this).width() + 'px',
				'margin': $(this).css('margin-top') + ' ' + $(this).css('margin-right') +
			' ' + $(this).css('margin-bottom') + ' ' + $(this).css('margin-left')
			});
			$(this).css({ 'float': 'none', 'margin': '0px' });
		});
	}
	// Fce pro pridani kulatych rohu k tabulkam
	inCMS.initTableCorners = function() {
		$('table.styled').each(function() {
			var tableContainer = $('<span class="tableContainer"></span>');
			$(this).before(tableContainer);
			$(tableContainer).append($(this)).append(corners).css({
				'float': $(this).css('float'), 'width': $(this).width() + 'px',
				'margin': $(this).css('margin-top') + ' ' + $(this).css('margin-right') +
			' ' + $(this).css('margin-bottom') + ' ' + $(this).css('margin-left')
			});
			$(this).css({ 'float': 'none', 'margin': '0px' });
			var caption = $(this).find('caption');
			if ($(caption).length > 0) {
				$('span.cornerTL, span.cornerTR', tableContainer).css('top', $(caption).outerHeight(true) + 'px');
			}
		});
	}
	$(document).ready(function() {
		inCMS.initImageCorners(); inCMS.initTableCorners();
		// oznaci tridou prvni prvek
		$('#menuList-h1 li').eq(0).addClass('firstItem');
		// pripoji prazdnou polozku do druhe urovne (spodni okraj)
		$('#menuList-h1 ul').append('<li class="borderBottom"><span class="corner cornerTL"></span><span class="corner cornerTR"></span><span class="corner cornerBL"></span><span class="corner cornerBR"></span></li>');
		// Nastylovani selectu
		$('.itemsSort').sSelect();
		$('.itemsCount').sSelect();
		// Zalamovani 7me polozky v prislusenstvi
		$('.relatedItems .itemBox:nth-child(7n)').css("clear", "both");
	});

	// IE6 PNG fix
	if ($.browser.msie && $.browser.version < 7) {
		DD_belatedPNG.fix('#logo, .itemBox .goToDetailLink, .itemBox .action span, span.corner, .detail .titles span, .detail #moreInfo #panelHeaders,.detail #moreInfo #panelHeaders li a:hover span, .detail #moreInfo #panelHeaders li.panelActive a span, ul#menuList-h1 ul li.borderBottom');
		$('.items-list > .itemBox:nth-child(4n)').css("clear", "both");
		$('#tems-catalog > .itemBox:nth-child(4n)').css("clear", "both");

		$('#menuList-h1 *').hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});
	}

	$(document).ready(function () {

	    $('#items-catalog .itemBox:nth-child(3n+1)').css({ clear: 'both' });	    

	});

	$(window).load(
    function () {

      // Centrovani obrazku v katalogu
      $('.itemBox').each(function () {
        itemImageBoxHeight = $(this).children('.itemImage').innerHeight();
        if (itemImageBoxHeight < 1) {
          itemImageBoxHeight = parseInt($(this).children('.itemImage').css('height'));
        }

        itemImageBoxWidth = $(this).children('.itemImage').innerWidth();
        if (itemImageBoxWidth < 1) {
          itemImageBoxWidth = parseInt($(this).children('.itemImage').css('width'));
        }

        itemImage = $(this).find('img');

        itemImateHeight = $(itemImage).height();
        if (itemImateHeight < 1) {
          itemImateHeight = parseInt($(itemImage).attr('height'));
        }

        itemImageWidth = $(itemImage).width();
        if (itemImageWidth < 1) {
          itemImageWidth = parseInt($(itemImage).attr('width'));
        }

        $(itemImage).css({
          top: itemImageBoxHeight / 2 - itemImateHeight / 2,
          left: itemImageBoxWidth / 2 - itemImageWidth / 2
        });

        $(this).find('.action > span').each(function () {
          var spanText = $(this).text();
          spanText = spanText.replace('<--1-->', '');
          $(this).text(spanText);
        });
      });

      $('.detailImage').each(function () {
        itemImageBoxHeight = $(this).innerHeight();
        itemImageBoxWidth = $(this).innerWidth();
        itemImage = $(this).find('img');
        itemImateHeight = $(itemImage).height();
        itemImageWidth = $(itemImage).width();
        $(itemImage).css({
          top: itemImageBoxHeight / 2 - itemImateHeight / 2,
          left: itemImageBoxWidth / 2 - itemImageWidth / 2,
          right: 'auto',
          position: 'relative'
        });
      });

      // Zuzeni oblych rohu v galerii

      $('.gallery .item').each(function () {
        var image = $(this).find('img');
        var imageWidth = $(image).width();
        var boxWidth = $(this).width();
        if (imageWidth < boxWidth) {
          $(this).find('.wrapper').width(imageWidth).css("left", boxWidth / 2 - imageWidth / 2 + "px");
        }

      });

    }
);




	
	
