var lastPixAlert = 0;

function validateSearch(form) {

    if (form.q.value == null || form.q.value == "") {
        alert("Ange sökord");
        return false;
    }

    return true;
}

function pixAlert(message) {
	jQuery("#popup-message li").removeClass("last");
	jQuery("#popup-message ul").append("<li class='last'>" + message + "</li>");
	jQuery("#popup-message").show("fast");
	setTimeout('hidePixAlert(' + (lastPixAlert++) + ')', 5000);

	// show max 5 messages
	if(jQuery("#popup-message li").size() > 5) {
		jQuery("#popup-message li:first").remove();
	}
}

function hidePixAlert(messageId) {
	if(lastPixAlert == messageId + 1) {
		jQuery("#popup-message").hide("slow");
	}
}

function addToCart(imageId) {
    jQuery.post("/ajax/cart/addImage", { imageId: imageId }, function(response) {
            jQuery("#itemCount").html(response);
            pixAlert("Image added to cart.");
        }
    );
}

function addToCartWithPriceAndUsage(imageId, price, usage) {
    jQuery.post("/ajax/cart/addImage", { imageId: imageId, price: price, usage: usage }, function(response) {
            jQuery("#itemCount").html(response);
            pixAlert("Image added to cart.");
        }
    );
}

function addToCartWithSize(imageId, size) {
    jQuery.post("/ajax/cart/addImage", { imageId: imageId, size: size }, function(response) {
            jQuery("#itemCount").html(response);
            pixAlert("Image added to cart.");
        }
    );
}

function addToLightBox(imageId) {
    jQuery.getJSON("/ajax/lightbox/addImage", { imageId: imageId}, function(json) {
            jQuery("#imageCount_" + json['id']).html(json['name'] + "(" + json['imageCount'] + ")");
            pixAlert("Image " + json.publicId + " added to lightbox.");
        }
    );
}

function addToLightBox(imageId) {
    jQuery.getJSON("/ajax/lightbox/addImage", { imageId: imageId}, function(json) {
            jQuery("#imageCount_" + json['id']).html(json['name'] + "(" + json['imageCount'] + ")");
            pixAlert("Image " + json.publicId + " added to lightbox.");
        }
    );
}

function setActiveLightBox(lightBoxId) {
    jQuery.post("/ajax/lightbox/activate", { id: lightBoxId }, function(response) {
            pixAlert("Lightbox " + response + " now active.");
        }
    );
}


jQuery(document).ready(function() {

/*
	jQuery(".pix-button")
	.hover(
		function(){
			jQuery(this).addClass("ui-state-hover");
		},
		function(){
			jQuery(this).removeClass("ui-state-hover");
		}
	)
	.mousedown(function(){
			jQuery(this).parents('.pix-buttonset-single:first').find(".pix-button.ui-state-active").removeClass("ui-state-active");
			if( jQuery(this).is('.ui-state-active.pix-button-toggleable, .pix-buttonset-multi .ui-state-active') ){ $(this).removeClass("ui-state-active"); }
			else { jQuery(this).addClass("ui-state-active"); }
	})
	.mouseup(function(){
		if(! jQuery(this).is('.pix-button-toggleable, .pix-buttonset-single .pix-button,  .pix-buttonset-multi .pix-button') ){
			jQuery(this).removeClass("ui-state-active");
		}
	});
*/
	jQuery("img.tooltip").tooltip({ showURL: false, extraClass: 'tooltip-content' });


	jQuery('input.tooltip').tooltip({ showURL: false, extraClass: 'tooltip-content' });

});


jQuery.ui.dialog.defaults.bgiframe = true;

jQuery(function() {
	jQuery("#dialog").dialog(
		{
			autoOpen: false,
			modal: true,
			height: 200,
			width: 400
		}
	);
});

function loginDialog() {
	jQuery('#dialog').dialog('open');
}

