function addToCart(event, id){
	$('#_product_add_id').val(id);
	$(event).parents('div:first').effect("transfer", { to: ".box-cart" }, 700, function(){
		$('#_product_add').submit();
	});
	return false;
}

function intinc(id){
	var val = parseInt($("#"+id).val());
	if (isNaN(val)){
		val = 1;
	} else {
		val+=1;
		$(".cart-update").css('visibility', 'visible');
	}
	$("#"+id).val(val);
	cartupdate();
	return false;
}

function intdec(id){
	var val = parseInt($("#"+id).val());
	if (isNaN(val)){
		val = 1;
	} else {
		val-=1;
		$(".cart-update").css('visibility', 'visible');
	}
	if (val < 1){
		val = 1;
	}
	$("#"+id).val(val);
	cartupdate();
	return false;
}

function cartupdate(){
	var total = 0;

	$('.cartInput').each(function(){
		var id = $(this).attr('id');
		var count = $(this).val();
		var price = $("#"+id+"_price").val();

		var p_total = price * count;
		total += p_total;
		$("#"+id+"_total").html(p_total.toFixed(2) + " €");
	});

	$("#checkout-total").html(total.toFixed(2) + " €");
}

function checkInput(event,type,id){

	var value = $("#"+id).val();
	$(event).attr('disabled', 'disabled');
	$.post(window.location.href, {_ac:type,_value:value}, function(data){
		if (data == ''){
			$("#"+id).parents('p:first').removeClass('error');
			$("#"+id).parents('p:first').addClass('success');
			$('#'+id+'_emsg').html('');
			if (type == 'captcha'){
				$("#"+id).attr('readonly', 'readonly');
				$(event).remove();
			}
		} else {
			if (type == 'captcha'){

				var newImg = $('#captcha_img').clone();
				newImg.attr('src', _captcha+'?sid='+new Date().getTime());
				$('#captcha_img').replaceWith(newImg);
			}
			$("#"+id).parents('p:first').removeClass('success');
			$("#"+id).parents('p:first').addClass('error');
			if ($('#'+id+'_emsg').length == 0){
				$(event).after('<br/><small id="'+id+'_emsg"></small>');
			}
			$('#'+id+'_emsg').html(data);
		}
		$(event).removeAttr('disabled');
		return false;
	});
	return false;
}

function removeFromCart(event, id){
	$("#"+id).val(0);
	$(event).parents('form').submit();
}

var searchText = "";
$(document).ready(function(){

	$('.searchInput').css('color', '#aaa');
	$('.searchInput').next().attr('disabled', 'disabled');
	
	searchText = $('.searchInput').val();
	$('.searchInput').focus(function(){
		if ($(this).val() == searchText){
			$(this).val("");
			$('.searchInput').css('color', '#000');
			$(this).next().removeAttr('disabled');
		}
	});
	$('.searchInput').blur(function(){
		if ($(this).val() == ""){
			$(this).css('color', '#aaa');
			$(this).val(searchText);
			$(this).next().attr('disabled', 'disabled');
		}
	});


	$('.cartInput').keyup(cartupdate);


	$(".box-hideable .col-box-content").hide();

	$('.box-hideable .col-box-content2 input[type="submit"]').click(function(){


		var content = $(this).parents('.box-hideable:first').find('.col-box-content:hidden');
		if (content.length > 0){
			content.slideDown(150);
			content.find('input[type="text"]:first').focus();
			return false;
		}
		return true;
	});

	$(".box-hideable .col-box-title").click(function(){
	 if ($(this).parent('.box-hideable').find('.col-box-content').is(":hidden")){
      $(this).parent('.box-hideable').find('.col-box-content').slideDown(150);
    } else {
      $(this).parent('.box-hideable').find('.col-box-content').slideUp(150);
    }
  });
   
    
  $('.gallery a').lightBox();

	$('.slide-1').cycle({
   fx:     'fade',
	  speed:   3000,
		delay:  12000,
    timeout:  12000,
		pause:  1,
		fastOnEvent: true,
		pager:  '.slide-1-nav',
		pagerAnchorBuilder: function(idx, slide) {  
        return '.slide-1-nav span:eq(' + idx + ')'; 
    },
		before: function(){
			//$('.slide-1-content').hide();
			$('.slide-1-content').html('<h3>'+this.title+'</h3><p>'+this.alt+'</p>');
		},
		after:   function(){
			
			//$('.slide-1-content').fadeIn(600);
		}
	});

});


function changeImage(img){
  $('.slide-1-nav #n'+img).triggerHandler('click');
}


