$(document).ready(function() {
	/* seznam produktu */
	if ($(".produkty-list-item").size() % 2) {
		$(".produkty-list-item").last().addClass("lastrow");
	}
	else {
		$(".produkty-list-item").last().prev(".produkty-list-item").andSelf().addClass("lastrow");
	}

	
	/* filterSv */
	$("#pdpSelectSv").bind("change", function() {
		$(this).closest("form").submit();
	});

	$(".pFilterSelect").bind("change", function() {
		if ($(this).hasClass('top')) {
			$(".pFilterSelect.sub").val('');
		}
		$(this).closest("form").submit();
	});

	if ($(".produkty-filter select").size() > 1) {
		$(".produkty-filter select").first().after(' &nbsp;<img src="'+HTTP_PATH+'custom/img/filter-sipka.gif" alt="" style="vertical-align: bottom;" />&nbsp; ');
	}

	/* tabulka polozek */
	$(".seznam-polozek-v-radcich TR").find("TD").last().addClass("nowrap");

	/* print */	
	$("#produkty, #kariera").find("#dataListButton").after(' &nbsp;<input type="submit" class="button" name="do[post]" id="dataPrintButton" value="'+MM_Print+'" onclick="window.print(); return false;" />');

	/* player */
	$('a[href$=".flv"]').each(function(index, element) {
		var blockid = ("autovideo"+index);
		var playerid = ('autovideoplayer'+index);
		$(this).attr("id", blockid);
		/*jwplayer(("autovideo"+index)).setup({
			flashplayer: HTTP_PATH+"custom/resources/player.swf",
			file: $(this).attr("href")			
		});*/		
		var flashvars = { file:$(this).attr("href"), autostart:'false' };
		var params = { allowfullscreen:'true', allowscriptaccess:'always' };
		var attributes = { id:playerid, name:playerid };

		swfobject.embedSWF((HTTP_PATH+"custom/resources/player.swf"), blockid,'400','300','9.0.115','false', flashvars, params, attributes);
	});

	/* autoheight */
	autoHeightBlocks(".autoheight", 0);
});

$(window).load(function() {
	autoHeightBlocks(".autoheight-w", 0);
	autoHeightBlocks(".home-bottom-box-content", 28);
	autoHeightBlocks(".produkty-list-item", 0);
	autoHeightBlocks(".mrizka-item", 0);
	
	/* stin */
	var isn = new IsNavigator();
	if (isn.webkit == true) {
		$(".shadow").dropShadow({'left': 2, 'top': 4, 'blur': 2, 'opacity': 0.3});
	}
	else {
		$(".shadow").dropShadow({'left': 2, 'top': 2, 'blur': 2, 'opacity': 0.3});
	}
});

function autoHeightBlocks(selector, add) {
	var maxHeight = 0;
	$(selector).each(function() {
		tmpHeight = $(this).height();		
		if (tmpHeight > maxHeight) {
			maxHeight = tmpHeight;
		}
	});
	if (add > 0) {
		maxHeight += add;
	}
	$(selector).height(maxHeight);
}
