function displayMenuItem(nid) {
	$('#menu-item-'+nid).parents('li').add('#menu-item-'+nid)
		.addClass('a-selected');
	$('#menu-item-'+nid).parents('ul').add('#menu-item-'+nid).show();
}

function addSpaces(str) {
    var amount = new String(str);
    amount = amount.split("").reverse();

    var output = "";
    for ( var i = 0; i <= amount.length-1; i++ ){
        output = amount[i] + output;
        if ((i+1) % 3 == 0 && (amount.length-1) !== i)output = ' ' + output;
    }
    
    return output.replace(' .', ',');
}

/**
  * document.onload()
  * 
  */
$(function() {

//		$('.buy').button();
//		$('#productTabs').tabs();
//		alert('ahoj');

	if (location.hash != '' && location.hash.substring(1, 6) == '!http') {
		//redirect
		location.href = location.hash.substring(2) ;
	}

	/**
	  * menu onclick event binding
	  */
	$('#left ul a').click(function() {
		$(this).siblings().toggle(300);
		if ($(this).parent().has('ul').length > 0) {
			return false;
		} else {
			return true;
		}
	});
	
	var current_content = $('#content').html();
	$('#menu li').hover(function(event) {
		event.preventDefault();
		
		$('#menu li').removeClass('a-hover');
		

		$(this).addClass('a-hover');
		$(this).parents('li').addClass('a-hover');

//		location.hash = '!'+$(this).children('a').attr('href');
		
//		$.get($(this).children('a').attr('href')+".ajax", function(data) {
//			$('#content').replaceWith(data)();
//		});
		
	});
	
	$('#menu').mouseout(function() {
//		$('#content').html(current_content);
//		location.hash = '';
	});
	
	$('.buy').button();
	$('input:submit').button();
	$('button').button();
	$('#productTabs').tabs();
	$('#homeTabs').tabs();

	$("*[rel^='prettyPhoto']").prettyPhoto({social_tools: ''});
	
	$('.input-q').click(function() {
		if ($(this).val() == 'hledat v e-shopu') {
			$(this).val('');
		}
	}).keypress(function() {
		$('#searchForm').submit();
	});
		
	$('#searchForm').submit(function() {
		if ($('#searchForm .input-q').val().length > 0) {
			$('#content')
				.load('/product/search/'+encodeURI($('#searchForm .input-q').val()));
			if ($('#searchForm .input-q').val().length < 10) {
				$('#searchForm input:submit')
					.val('hledám '+$('#searchForm .input-q').val());
			} else {
				$('#searchForm input:submit')
					.val('hledám ...');			
			}
		}
		return false;
	});
	
});

