var jersey_image_front = '';
var jersey_image_back = '';
var jersey_image_back_big = '';
var jersey_art_no = '';
/**
 * Flock-Vorschau laden
 *
 * @param int art_no Artikelnummer
 * @param object config Konfigurationsoptionen (Details siehe Standard-Werte)
 */
function jersey_load_preview(art_no, config) {
    //Konfiguration mit Standard-Werten mergen
    config = jQuery.extend({
        jersey_image_id : '#myjersey_preview',
        jersey_logosmall_id : '.mod_myjersey_dfllogoline img',
        jersey_logobig_id : '#myjersey_dfllogoimage img',
        jersey_label_id : '#myjersey_preview .label',
        use_big_preview : false,
        img_mode : false
    }, config);
    //Artikelnummer merken
    jersey_art_no = art_no;
    //Flock-Konfiguration laden
    jQuery.getJSON('/pages/flocks/'+art_no+'.json',
        function(data){
            //Bilder in globalen Variablen merken (fuer Aktualisierung der Vorschau)
            jersey_image_front = data.image_front;
            jersey_image_back = data.image_back;
            jersey_image_back_big = data.image_back_big;
            //Logo-Bilder setzen
            $(config.jersey_logosmall_id).attr('src', data.logo_small);
            $(config.jersey_logobig_id).attr('src', data.logo_big);
            if (typeof(language) != 'undefined' && language == 'en') {
                var html = $(config.jersey_logosmall_id).parent().html();
                html = html.replace(/Meister /, " ");
                $(config.jersey_logosmall_id).parent().html(html);
            }
            //Shirt-Bilder setzen
            if ($(config.jersey_label_id).html() || config.use_big_preview) {
                if (config.use_big_preview)
                    jersey_change_image(config.jersey_image_id, jersey_image_back_big, config);
                else
                    jersey_change_image(config.jersey_image_id, jersey_image_back, config);
            } else {
                jersey_change_image(config.jersey_image_id, jersey_image_front, config);
            }
            //Flock-Position berechnen
            if (config.use_big_preview) {
                data.flock_x *= 2.4;
                data.flock_y *= 3.1;
                data.flock_x -= 150;
            } else
                data.flock_x -= 100;
            $(config.jersey_label_id).css('left', data.flock_x + 'px');
            $(config.jersey_label_id).css('top', data.flock_y + 'px');
            $(config.jersey_label_id).css('color', data.flock_color);
            //Flock-Schrift setzen
            switch (data.flock_font) {
                case 'serif':
                    $(config.jersey_label_id).css('font-family', 'Calibri, Cambria, Times');
                    if (config.use_big_preview)
                        $(config.jersey_label_id).css('font-size', '32px');
                    else
                        $(config.jersey_label_id).css('font-size', '14px');
                    $(config.jersey_label_id).css('font-weight', 'bold');
                    $(config.jersey_label_id).css('text-transform', 'uppercase');
                    break;
                case 'nonserif':
                default:
                    $(config.jersey_label_id).css('font-family', 'Arial');
                    if (config.use_big_preview)
                        $(config.jersey_label_id).css('font-size', '32px');
                    else
                        $(config.jersey_label_id).css('font-size', '12px');
                    $(config.jersey_label_id).css('font-weight', 'bold');
                    $(config.jersey_label_id).css('text-transform', 'uppercase');
            }
        }
    );
}
/**
 * Flock-Vorschau aktualisieren
 *
 * @param bool flock Hintergrund mit Flock anzeigen
 * @param string text Flock-Text
 * @param object config Konfigurationsoptionen (Details siehe Standard-Werte)
 * @param string player Wert der Spielerauswahl: hier wird die Nummer extrahiert
 */
function jersey_update_preview(flock, text, config, player) {
    config = jQuery.extend({
        jersey_image_id : '#myjersey_preview',
        jersey_logosmall_id : '.mod_myjersey_dfllogoline img',
        jersey_logobig_id : '#myjersey_dfllogoimage img',
        jersey_label_id : '#myjersey_preview .label',
        use_big_preview : false,
        img_mode : false
    }, config);
    var image_front = jersey_image_front;
    var image_back_big = jersey_image_back_big;
    if (typeof(player) != 'undefined') {
        var number = player.substr(4, 2);
        if (player.match(/[0-9][0-9]/)) {
            image_front = '/cat_images/flock/flock_' + jersey_art_no + '_' + number + '.png';
            image_back_big = '/cat_images/big_flock/big_flock_' + jersey_art_no + '_' + number + '.jpg';
        }
    }
    if (flock || config.use_big_preview) {
        $(config.jersey_label_id).html(text);
        if (config.use_big_preview)
            jersey_change_image(config.jersey_image_id, image_back_big, config);
        else
            jersey_change_image(config.jersey_image_id, jersey_image_back, config);
    } else {
        $(config.jersey_label_id).html('');
        jersey_change_image(config.jersey_image_id, image_front, config);
    }
}
/**
 * Bild austauschen
 *
 * @param string id jQuery-Identifier
 * @param string src Pfad zum neuen Bild
 * @param object config Konfigurationsoptionen
 */
function jersey_change_image(id, src, config) {
    if (config.img_mode) {
        $(id).attr('src', src);
    } else {
        $(id).css('background-image', 'url('+src+')');
    }
}

