/**
*	Some js
*/




$(document).ready(function(){
	
	if ( jQuery.browser.msie )
		$("div#bg").css("height", $(document).height());
	
	$(window).bind("resize", function(){
		if ( jQuery.browser.msie ) {
			//window.location.reload();
		}
	});
	
	
	// bind toggle for cat button images

	$("div#topButtons img").hover(
		function(){
			if($(this).attr("src").indexOf("0") != -1) {
					var newSrc = $(this).attr("src").replace("0","1");
					$(this).attr("src" ,newSrc);
			}
		},
		function(){
			if($(this).attr("src").indexOf("1") != -1 && this.className != "active") {
				var newSrc = $(this).attr("src").replace("1","0");
				$(this).attr("src",newSrc);
			}
		}
	);

	
	
	// galery 
	
	$("a#thumb1 img").hover(
			function(){
				if($(this).attr("src").indexOf("0") != -1) {
						var newSrc = $(this).attr("src").replace("0","1");
						$(this).attr("src" ,newSrc);
				}
			},
			function(){
				if($(this).attr("src").indexOf("1") != -1 && this.className != "active") {
					var newSrc = $(this).attr("src").replace("1","0");
					$(this).attr("src",newSrc);
				}
			}
		);	
	
	
	
	$("ul.leftMenu.level0 > li").hover(function() {
				
				if(!$(this).hasClass("active")) {
					$(this).addClass("roll");
					$("a", this).addClass("roll");
				}
			}, 
			function (){
				if(!$(this).hasClass("active")) {
					$(this).removeClass("roll");
					$("a", this).removeClass("roll");
				}
			}
		);
	
	
	
	
	$("input.pers").bind("click", function() {
		
		var val = $(this).val();
		
		$("table.pers").hide();
		$("table.pers#pers-" + val).show();
		
	})
	
	
	// voting protection
	

	$("input.cr").each(function(i, el){
		$(this).val(hex_md5($(this).val()));
	})
	
});










function addToBasket(item)
{
	basket("change", item, 1);
}



function changeBasket(item, inp)
{
	basket("change",item, inp.value);
}


function removeFromBasket(item)
{
	basket("remove",item);
}



function basket(cmd, item, qtn)
{
	
	//$("#basket").fadeTo(1, 0.33);
	
	$.ajax({
		type: "POST",
		url: "feed.php",
		data: "cmd=" + cmd + "&item=" + item + "&skaits=" + qtn,
		dataType: "json",
		success: function(json){
						
			if(json != null) {

				//showBasket(true);
				//$("#basket").fadeTo("fast", 1);
				
				$.each(json, function(name, value) {
					
					if ($(name).length > 0) {
						$(name).html(value);
					}
					
				});
				
				
				location.href = "?basket";
			}

			
		},
		error: function (msg) {
			alert(msg.responseText);
		}
	});	
	
	
}




