$(document).ready(function()
{
	$("#searchField").focus(function(){
		if ($(this).val() == shHint)
			$(this).val('');
	});

	$("#searchField").blur(function(){
		if ($(this).val() == '')
			$(this).val(shHint);
	});

	$("form#searchForm").submit(function(){
		var q = trimString($("#searchField").val());
		if ((q) && (q != '') && (q != shHint))
		{
			//q = escape(q);
			q = q.replace(/&/, '');
			q = q.replace(/=/, '');
			var baseUri = $("#searchForm").attr('action');
			if (!baseUri)
				baseUri = host+'lt';
			window.location = baseUri + '?sq=' + q;
		}

		return false;
	});

	$(".form_addToCart").submit(function(){
		var url = $(this).attr('action');
		var name = $(this).attr('name');
		name = name.replace(/cartForm_/, '');
		var cartItemName = "cartItem["+name+"]";
		var cartItemQty = parseInt($("#cartItem_"+name).val());

		if (cartItemQty >= 0)
		{
			$.ajax({
				type: "POST",
				url: url+'?ajax=1', 
				data: [{ name: cartItemName, value: cartItemQty }],
				cache: false,
				success: function(html) {
					if (html)
					{
						$('#cartBlock').show();
						$('#cartInfo').html(html);
					} else {
						$('#cartBlock').hide();
					}
					//$('#cartItem_'+name).val('');
					$('#emptyCartBlock').hide();
					$('#btn_cartItem_'+name).blur();
					$('#cartItem_'+name).addClass('add_success');
				}
			});
		}

		return false;
	});
	
	/*
	$('a.products_read_more').click(function(){
		var href = $(this).attr('href');
		if (href) {
			getInfoContent(href);
		}
		return false;
	});
	*/
	
	getInfoContent = function(url)
	{
		var yy = document.all? truebody().scrollTop : pageYOffset;
		
		setOverlay();
		
		if (yy >= 0)
			$('#popup_box').css({	top: 100+yy+'px' });
		$('#popup_box').show();
		
		var n = 0;
		$("#popup_box_content").ajaxStart(function() {
			if (n++ > 0) return;
			$("#popup_box_content").html('<img src="'+host+'public/images/loading_small.gif" alt="Kraunasi..." />');
		});
		
		$.ajax({
			url: url+'?ajax=1', 
			cache: false,
			success: function(html) {
				if (html) {
					$("#popup_box_content").html(html);
				}
			}
		});
		
		
		return false;
	}
	
	$('#overlay').click(function() {
		closeDescription();
	});
	
});

setOverlay = function() {
	var obj = document.getElementById('top');
	var w = $('body').width();
	var h = obj.scrollHeight;
	
	$('#overlay').css({	width: w });
	$('#overlay').css({	height: h });
	$('#overlay').show();
}

closeDescription = function() {
	$('#overlay').hide();
	$('#popup_box').hide();
	$('#popup_box_content').html('');
}
//---------------------------------------------------------------
