$(document).ready(function(){
	
	$('#cat > li.active ul').show();
	
	$('#cat > li > a').live("click", function(e) {
		
		var ul = $(this).parent().find('ul');
		
		if($(ul).is(':hidden')) {
			$("#cat > li.active ul").slideUp('slow').parent('li').removeClass('active');
			$(this).parent('li').toggleClass('active');
			$(ul).slideDown('slow', function(){
				$("#cat > li.active ul").parent('li').removeClass('active');	// small
				$(this).parent('li').toggleClass('active');						// fix
			});
		} else {
			$(ul).slideUp('slow', function(){
				$(this).parent('li').toggleClass('active');
			});
		}
		
		return false;
	});
	
	
	var inputs = '#top input[type="text"], #top input[type="password"], #buy input[type="text"]';
	
	$(inputs).focus(function() {
		if(this.value == this.defaultValue)
			this.value = '';
			
		if(this.value != this.defaultValue )
			this.select();
	});
	$(inputs).blur(function(){
		if(this.value == '')
			this.value = (this.defaultValue ? this.defaultValue : '');
	});

	
	
	
	/*
	$('.paleta').click(function () { 
		$('#paleta').slideToggle('slow'); 
	});
	*/
	
	$('#paleta span').click(function () { 
		$('#paleta span').removeClass('active');
		$(this).addClass('active');
		var title = $(this).attr("title");
		$('#tarcza').css('background', title);
	});


	$(".wersja input").change(function () {
		var vval = $(this).attr('class');
		if(vval == 'show_color') {
			$('.kolor').fadeIn();
		} else {
			$('.kolor').fadeOut();
		}
	  });

	$("input[name=kolor]").change(function () {
		var vval = $(this).attr('title');
		if(vval) {
			$('#tarcza').css('background', vval);
		}
	  });
	
	$(".kolor input").change(function () {
		var vval = $(this).attr('rel');
		if(vval == 'niestandardowy') {
			$('#paleta').slideDown();
		} else {
			$('#paleta').slideUp();
		}
	  });
	
	$("table.items tr td").click(function(){
		location.href = $(this).parent('tr').find('a').attr('href');
	});
	
	
	
});