/*
 * Function generating random content in Webshop box
 */
$.fn.webshop = function (options) {
    if ($(this).find('ul li').length) {
        var webshop = $(this);
        // check options
        var opts = jQuery.extend({
                    count: 3
                }, options || {});
        // declare variables
        var webshopElementCount = webshop.find('ul li').length;
        var webshopElementRandArr = [];
        var num;
        var webshopElementHtml = '';
        // generate random numbers, store elements html
        for (i=0; i<opts.count; i++) {
            num = Math.floor(webshopElementCount * Math.random());
            while (in_array(num, webshopElementRandArr)) {
                num = Math.floor(webshopElementCount * Math.random());
            }
            webshopElementRandArr.push(num);
            webshopElementHtml += '<li>' + webshop.find('ul li:eq('+num+')').html() + '</li>';
        }
        // replace old <ul> with a new one and show it
        webshop.find('ul:first').replaceWith('<ul>' + webshopElementHtml + '</ul>');
        $('#' + webshop.attr('id') + 'Preloader').remove();
        webshop.find('ul:first').css('display','block');
    }
};

/*
 * Additional function for searching through array
 */
function in_array(what, where) {
    var found = false;
    for(var i=0; i<where.length; i++){
      if(what == where[i]) {
        found = true;
        break;
      }
    }
    return found;
};

$.fn.webshopPreloader = function (options) {
    var webshop = $(this);
    // append preloader
    webshop.append("<img src=\"/images/preloader.gif\" width=\"32\" height=\"32\" alt=\"loading\" id=\"" + webshop.attr('id') + "Preloader\" />");
};