$(document).ready(function(){
	// hovers
	$(".galleria img, .galleria_scroll img, .scroll_nappi").hover(
		function(){
			$(this).animate({
				opacity: 1.0
			}, "normal");
		},
		function(){
			$(this).animate({
				opacity: 0.7
			}, "normal");
		}
		);

	$("#slider").cycle({
		fx:		'scrollHorz',
		timeout: 0,
		cleartype: true,
		cleartypeNoBg: true,
		prev:	'#nappi_left',
		next:	'#nappi_right'
	});

	$("#dialog").dialog({
			height: 550,
			width: 340,
//			modal: true,
			resizable: false,
			draggable: false,
			title: 'Tuotteen tiedot',
			closeText: 'Sulje',
			closeOnEscape: true,
			autoOpen: false
		});

	$('.open_product').click(function(event){
		event.preventDefault();
		$('#dialog').empty();
		$('#dialog').load('/product_popup.php?pdid=' + $(this).attr('rel'), function(){
			if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
				jQuery(function($) {
					$("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) {
						return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
					});
				});
			}
		});
		$('#dialog').dialog('open');
		return false;
	});

});

function addCart(id, elem)
{
	$.post("/addcart.php", {
		prod_id: id,
		type: 'add'
	}, function(data){
		$(elem).text("Lisätty");
		$(elem).attr("onclick", "return false;");
		$("#tuotelkm").text(data.lkm);
		$("#ideakori").css("display", "block");
	}, "json");

}

function removeCart(id, elem)
{
	$.post("/addcart.php", {
		prod_id: id,
		type: 'remove'
	}, function(data){
		$(elem).parent().parent().fadeOut('fast', function(){
			$(this).remove()
		});
		$("#tuotelkm").text(data.lkm);
	}, "json");

	return false;
}
