$(document).ready(function(){	
	bind_hover ();
	bind_search ();
	bind_effects ();
	bind_tabs ();
	bind_params ();
});

/**
 * hover efekt na menu
 **/
function bind_hover ()
{
	$(".menu li, .path li, .brands-menu li").hover(
		function() {
			$(this).addClass("sfhover");
		},
		function() {
			$(this).removeClass("sfhover");
		}
	);
}

/**
 * smazani textu v search input
 **/
function bind_search ()
{
	// vynulovani pole pri focusu
	$(".search-input").focus(function() {
		$(this).val('');
	});
}

/*
 * animovani panelu
 **/
function bind_effects ()
{
	
	$('#products li a').hoverIntent(
		function(){
			$('#products li a').removeClass('sfhover');
			$(this).addClass('sfhover');
			$('#products li a').each(function(){
				if (!$(this).hasClass('sfhover')) {
					$(this).animate({opacity:0.5},400);
				}
			});
		},function(){
			$('#products li a').removeClass('sfhover').animate({opacity:1},100);
		}
	);
}

/*
 flash player
 http://snipplr.com/view/288/flash-video-player-html-code/
 */

 /**
 * zalozky
 **/
function bind_tabs ()
{
	 $('#tab-container').tabs();
}
 
 /**
 * tabulka s parametry ve dvou sloupcich
 * vstupem je tabulka s daty #product-param-1,
 * jejiz data se rozdeli do dvou tabulek
 * #product-param-1 a #product-param-2
 **/
function bind_params ()
{
	var keys = new Array();
	var values = new Array();
	var treshold;
	
	if ($('#product-param-1 tr').length > 0)
	{
		// pole s klici
		$("#product-param-1 tr th").each(
			function()
			{
				var str = $(this).text();
				if(str != "")
					keys.push(str);
			}
		);
		
		// pole s hodnotami
		$("#product-param-1 tr td").each(
			function()
			{
				var str = $(this).text();
				if(str != "")
					values.push(str);
			}
		);

		// novy layout
		if(keys.length == values.length)
		{
			// smazani dat v tabulce
			$("#product-param-1 tr").remove();
			$("#product-param-2 tr").remove();
			treshold = Math.ceil(values.length/2);

			// naplneni dat do dvou tabulek
			for (var i = 0; i < keys.length; i++) 
			{
				if(i<treshold) $("#product-param-1").append("<tr><th>" + keys[i] + "</th><td>" + values[i] + "</td></tr>");
				else $("#product-param-2").append("<tr><th>" + keys[i] + "</th><td>" + values[i] + "</td></tr>");
			}	
		}
	}
}

