$(document).ready(function() {
	$("a.external").attr("target","_blank");
    Shadowbox.init({
            loadingImage: '/images/misc/loading_sb.gif',
            keysClose: ['s', 27],
            keysPrev: ['z', 37],
            keysNext: ['v', 39],
            initialHeight: 50,
            initialWidth: 500,
            fadeDuration: 0.15,
            resizeDuration: 0.15,
            text:{
                of:         "von",
                cancel:     "Abbrechen",
                loading:    "loading",
                close:      '<span class="shortcut">S</span>chließen',
                next:       '<span class="shortcut">V</span>or',
                prev:       '<span class="shortcut">Z</span>urück'
            }
    });
    sbLinks = $("a[@rel^='shadowbox']");
    if (0 < sbLinks.length) {
        Shadowbox.setup(sbLinks);
    }
});

function feedback(caption,width,height,div) {
	Shadowbox.open({
        title:      caption,
        type:       'html',
        content:    '<h1 class="feedback">' + $("#" + div).html() + '</h1>',
        height:     height,
        width:      width
    });
}

function sbInit(lang,prodId) {
	$("#searchbox").empty().append('<img src="/images/misc/loading.gif" />').load("/ajax/mirrormounts/searchbox/lang/" + lang + "/product_id/" + prodId);
}

function sbUpdate(lang) {
	var product_id = $("#box1 option:selected").val();
	var base_id = $("#box2 option:selected").val();
	var screws = $("#box3 option:selected").val();
	var front_id = $("#box4 option:selected").val();
	params = "product_id/" + product_id + "/base_id/" + base_id + "/screws/" + screws + "/front_id/" + front_id;
	$("#searchbox").empty().append('<img src="/images/misc/loading.gif" />').load("/ajax/mirrormounts/searchbox/lang/" + lang + "/" + params);
    $("#list").empty().append('<img src="/images/misc/loading.gif" />');
    $.get("/ajax/mirrormounts/search/lang/" + lang + "/" + params, function(data) {
        $("#list").empty().append(data);
        Shadowbox.clearCache();
        sbLinks = $("a[@rel^='shadowbox']");
	    if (0 < sbLinks.length) {
	        Shadowbox.setup(sbLinks);
	    }
    });
	return false;
}

function addToList(prodId,confId) {
    $.getJSON("/ajax/prodlist/add/prodid/" + prodId + "/confid/" + confId,
        function(items) {
        	feedback('', 500, 50, 'feedback');
        	updateList();
        }
    );
}

function removeFromList(idx) {
    $.getJSON("/ajax/prodlist/remove/idx/" + idx);
    updateList();
}

function updateList() {
    $("#sidebar").empty().append('<img src="/images/misc/loading.gif" />').load("/ajax/prodlist/get");
}