﻿function splanding_setupseed(theCategoryId)
{
    $('.categoryMod').each(function() {
        var categoryHref = $(this).find('h2>a').attr('href');
        var categoryId = categoryHref.substr(categoryHref.lastIndexOf('-') + 1);
        if (categoryId == theCategoryId) {
            if ($.cookie(categoryId + 'seed') == null) {
                $.cookie(categoryId + 'seed', Math.round(Math.random() * 100000), { expires: 1 });
            }
            $(this).find('.modGrid img').each(function(index) {
                if ($(this).data('realsrc') == null) {
                    var src = $(this).attr('src');
                    src = src.indexOf("&seed=") != -1 ? src.substring(0, src.indexOf("&seed=")) : src;
                    $(this).data('realsrc', src);
                }
                $(this).attr('src', $(this).data('realsrc') + '&seed=' + parseInt($.cookie(categoryId + 'seed') * index + index).toString());
            });
        }
    });
}


$(document).ready(function() {
    $('.categoryMod > .browseBar a').click(function() {
        var categoryDiv = $(this).parents('.categoryMod').get(0);

        if (!$(categoryDiv).find('.modGrid > a').get(0))
            return; // when no_products.png is shown

        var categoryHref = $(categoryDiv).find('h2>a').attr('href');
        var categoryId = categoryHref.substr(categoryHref.lastIndexOf('-') + 1);
        $.cookie(categoryId + 'seed', null);
        splanding_setupseed(categoryId);
        return false;
    });

    var decodedURI = unescape(document.location.href);
    if (decodedURI.indexOf('ar=1') != -1) {
        createNewRoom();
    }
    $('#ShowCreateProductSet').click(function() {
        productset_showCreationPopup('#dialogueBox');
    });
})    