/* =============================================================================
BASE JS FILE
--------------------------------------------------------------------------------
Project: Narex templates
Author: Filip Novak - mame.napilno.cz
E-mail: filip.f.novak@gmail.com

Project notice:

--------------------------------------------------------------------------------
============================================================================= */





/* =============================================================================
Startup - BEGIN
- for register all startup actions
----------------------------------------------------------------------------- */
if (typeof jQuery != 'undefined') { 
    jQuery(document).ready(function () {
        
        init();
        langSelector();
        defaultSearchText();
        leftNavigationHeightAutoSizerInit();
        productsSubnavigation();
        productPhotogallery();
        lightboxInit();
        tabsInit();
        titleSlideshowInit();
        titleFlashBanersInit();
        tableEvenOdd();
        newsDateSelector();
        salesAndServiceMaps();
        stickerReplacer();
        createEmailLink();
         
    }); 
}
/* -----------------------------------------------------------------------------
Startup - END
============================================================================= */





/* =============================================================================
init - BEGIN
- nastavuje promene prostredi
----------------------------------------------------------------------------- */
function init () {
    
    NAREX = Object;
    NAREX.products_images_hires_path = '500x500'; // relativni cesta k nejvetsim obrazkum
    
    NAREX.default_map_center_lat = 49.740568; // cihost = geograficky stred Ceske republiky
    NAREX.default_map_center_lng = 15.335877; // cihost = geograficky stred Ceske republiky
    NAREX.default_map_zoom = 7; // pri sirce 646px zobrazi celou CR
    
    if (typeof default_map_adress_field_text != 'undefined') {
        NAREX.default_map_adress_field_text = default_map_adress_field_text;
    }
    
    if (typeof geocoder_return_empty_result != 'undefined') {
        NAREX.geocoder_return_empty_result = geocoder_return_empty_result;
    }
    
    if (typeof geocoder_return_many_result != 'undefined') {
        NAREX.geocoder_return_many_result = geocoder_return_many_result;
    }
    
    // ziskani jazyka stranek - pozdeji mozno napr. vycucnout z URL
    if (typeof narex_page_language != 'undefined') {
        NAREX.language = narex_page_language;
    }
    
    
}
/* -----------------------------------------------------------------------------
init - END
============================================================================= */





/* =============================================================================
lang selector - BEGIN
- skryje odesilaci tlacitko
----------------------------------------------------------------------------- */
function langSelector () {
    
    jQuery('#language_selector #select_language').css('display', 'none');
    
}
/* -----------------------------------------------------------------------------
lang selector - END
============================================================================= */





/* =============================================================================
default search text - BEGIN
- po nakliknuti do vyhledavaciho pole smaze defaultni hodnotu
  vyhledavaciho pole
----------------------------------------------------------------------------- */
function defaultSearchText () {
    
    if (typeof narex_search_empty_value == 'undefined') {
        NAREX.search_empty_value = '';
    } else NAREX.search_empty_value = narex_search_empty_value;
    
    // pocatecni nastaveni empty value
    jQuery(':text', '#search').attr('value', NAREX.search_empty_value);
    
    // udalosti na textovem poli - BEGIN
    jQuery(':text', '#search').focusin(function () {
        if (jQuery(this).attr('value') == NAREX.search_empty_value) {
            jQuery(this).attr('value', '');
        }
    });
    jQuery(':text', '#search').focusout(function () {
        if (jQuery.trim(jQuery(this).attr('value')) == '') {
            jQuery(this).attr('value', NAREX.search_empty_value);
        }
    });
    // udalosti na textovem poli - END
    
    // zakaz stisknuti tlacitka - BEGIN
    jQuery('.button', '#search').click(function (e) {
        var search_phrase = jQuery.trim(jQuery(':text', '#search').attr('value'));
        if (search_phrase == '' || search_phrase == NAREX.search_empty_value) {
            e.preventDefault();
        }
    });
    // zakaz stisknuti tlacitka - END
    
}
/* -----------------------------------------------------------------------------
default search text - END
============================================================================= */





/* =============================================================================
left Navigation Height Auto Sizer - BEGIN
- automaticky nastavuje vysku divu sub_navigation_panel
  podle vysky stranky
----------------------------------------------------------------------------- */
function leftNavigationHeightAutoSizerInit () {
    
    // zaveseni udalosti resize na #content
    jQuery('#content_wrapper').bind('resize', function (e) {
        leftNavigationHeightAutoSizer();
    });
    
    leftNavigationHeightAutoSizer();
    
}

function leftNavigationHeightAutoSizer () {
    
    jQuery('#sub_navigation_panel').css('height', 'auto');
    var wrapper_height = jQuery('#content_box_in_2_wrapper').height();
    var subnavigation_top_margin = parseInt(jQuery('#sub_navigation_panel').css('margin-top'));
    var subnavigation_top_padding = parseInt(jQuery('#sub_navigation_panel').css('padding-top'));
    
    jQuery('#sub_navigation_panel').height(wrapper_height - (subnavigation_top_margin + subnavigation_top_padding));
    
}
/* -----------------------------------------------------------------------------
left Navigation Height Auto Sizer - END
============================================================================= */





/* =============================================================================
products subnavigation - BEGIN
- zobrazuje/skryva submenu produktu
----------------------------------------------------------------------------- */
function productsSubnavigation () {
    
    jQuery('#products_submenu_thumbnails_selector')
        .wrap('<div id="products_popup" />');
    jQuery('#page_wrapper').append(jQuery('#products_popup'));
    jQuery('#products_submenu_thumbnails_selector').css('display', 'block');
    jQuery('#products_popup').toggle();
    
    jQuery('#products_menu a').click(function (e) {
        e.preventDefault();
        jQuery('#products_popup').slideToggle();
    });
    
}
/* -----------------------------------------------------------------------------
products subnavigation - END
============================================================================= */





/* =============================================================================
product photogallery - BEGIN
- na karte produktu prepina hlavni obrazek
----------------------------------------------------------------------------- */
function productPhotogallery () {
    
    // zaveseni eventu - BEGIN
    jQuery.each(jQuery('.tpl_product-card #gallery_wrapper #thumbnails_gallery li a img'), function (i, elm) {
        jQuery(elm).click(function (e) {
            e.preventDefault();
            
            /* parametry obrazku - BEGIN */
            var image_url = jQuery(this).parent().attr('href');
            var image_alt = jQuery(this).attr('alt');
            var image_title = jQuery(this).attr('title');
            /* parametry obrazku - END */
            
            /* prenastaveni obrazku - BEGIN */
            jQuery('.tpl_product-card #gallery_wrapper #product_image img').attr({
                'src' : image_url,
                'alt' : image_alt,
                'title' : image_title
                });
            /* prenastaveni obrazku - END */
           
            /* link na hires - BEGIN */
            
            var split_url = image_url.split('/');
            var hires_src = '';
            
            for (x = 0; x < split_url.length; x++) {
                
                // nastaveni HIRES slozky - BEGIN
                if (x == split_url.length - 2) {
                    hires_src += NAREX.products_images_hires_path + '/';
                }
                // nastaveni HIRES slozky - BEGIN
                
                // standardni sestaveni cesty - BEGIN
                else {
                    hires_src += split_url[x] + '/';
                }
                // standardni sestaveni cesty - END
                
                // odstraneni polsedniho lomitka - BEGIN
                if (x == split_url.length - 1) {
                    hires_src = hires_src.slice(0, -1);
                }
                // odstraneni polsedniho lomitka - END
                
            }
            
            jQuery('.tpl_product-card #gallery_wrapper #product_image a').attr('href', hires_src);
            /* link na hires - END */
            
        });
    });
    // zaveseni eventu - END
    
}
/* -----------------------------------------------------------------------------
product photogallery
============================================================================= */





/* =============================================================================
lightbox Init - BEGIN
- inicializuje lightbox - pro vsechny a s tridou .lightbox
----------------------------------------------------------------------------- */
function lightboxInit () {
    
    jQuery('a.lightbox').lightBox({
            fixedNavigation:true,
            imageLoading: 'css/img/jquery-lightbox/lightbox-ico-loading.gif',
            imageBtnClose: 'css/img/jquery-lightbox/lightbox-btn-close.gif',
            imageBtnPrev: 'css/img/jquery-lightbox/lightbox-btn-prev.gif',
            imageBtnNext: 'css/img/jquery-lightbox/lightbox-btn-next.gif',
            imageBlank: 'css/img/jquery-lightbox/lightbox-blank.gif'
        });
    
}
/* -----------------------------------------------------------------------------
lightbox Init - END
============================================================================= */





/* =============================================================================
tabs Init - BEGIN
- inicializuje taby resene pomoci jQuery UI custom 
  pro vsechny div s tridou .tabs
----------------------------------------------------------------------------- */
function tabsInit () {
    jQuery("#tabs").tabs();
}
/* -----------------------------------------------------------------------------
tabs Init - END
============================================================================= */





/* =============================================================================
title Slideshow Init - BEGIN
- inicializuje titulni horni slideshow
----------------------------------------------------------------------------- */
function titleSlideshowInit () {
    
    if (jQuery('.tpl_title  #top_baners p').length == 0) {
        return;
    }
    
    jQuery('.tpl_title  #top_baners p').cycle({
        fx : 'fade',
        speed : 500, 
        timeout : 4000 
    });
}
/* -----------------------------------------------------------------------------
title Slideshow Init - END
============================================================================= */





/* =============================================================================
title Flash Baners Init - BEGIN
- pokud je v tele stranky neprazdna promena narex_title_bottom_baners
  inicializuje flashe pres SWFObject
----------------------------------------------------------------------------- */
function titleFlashBanersInit () {
    
    if (typeof narex_title_bottom_baners == 'undefined'
        || jQuery.isArray(narex_title_bottom_baners) == false
        || narex_title_bottom_baners.length != 4) {
        return;
    }
    
    NAREX.title_bottom_baners = narex_title_bottom_baners;
    
    for (x = 0; x <= (NAREX.title_bottom_baners.length - 1); x++) {
        var params = {'wmode': 'transparent'};
        var url = jQuery('#bottom_baner_' + (x+1) + ' h2 a').attr('href');
        var flashvars = {'url': url};
        swfobject.embedSWF(NAREX.title_bottom_baners[x], 'bottom_baner_' + (x+1), "190", "260", "9.0.0", "expressInstall.swf", flashvars, params, {});
    } 
    
}
/* -----------------------------------------------------------------------------
titleFlashBanersInit - END
============================================================================= */


/* =============================================================================
table Even Odd - BEGIN
- oznackuje vsechny radky tabulek tridou .even a .odd,
  protoze IE8- to neumi pres CSS selektor 
----------------------------------------------------------------------------- */
function tableEvenOdd () {
    jQuery('tr:odd').addClass('odd');
    jQuery('tr:even').addClass('even');
}
/* -----------------------------------------------------------------------------
table Even Odd - END
============================================================================= */


/* =============================================================================
news Date Selector - BEGIN
- z formulare newsDateSelector vytvari minikalendar a mapu 
  pro zobrazeni novinek
----------------------------------------------------------------------------- */

function newsDateSelector () {
    
    // existuje prostor pro umisteni kalendare?
    if (jQuery('#news_date_selector').length != 1) return;
    
    // ziskani a kontrola dat pro minikalendar z JS generovaneho do stranky - BEGIN
    if (typeof narex_newscalendar_display_month == 'undefined') return; // musi existovat
    if (typeof narex_newscalendar_display_year == 'undefined') return; // musi existovat
    if (typeof narex_newscalendar_days_with_news == 'undefined') return; // musi existovat
    if (jQuery.isArray(narex_newscalendar_days_with_news) == false) return; // musi byt pole
    // ziskani a kontrola dat pro minikalendar z JS generovaneho do stranky - END
    
    // pradne hodnoty - BEGIN
    if (jQuery.trim(narex_newscalendar_display_month) == '' 
    || jQuery.trim(narex_newscalendar_display_year) == '') {
        return;
    }
    // pradne hodnoty - END
    
    // vlozeni do globalniho objektu - BEGIN
    NAREX.newscalendar_display_month = parseInt(narex_newscalendar_display_month);
    NAREX.newscalendar_display_year = parseInt(narex_newscalendar_display_year);
    NAREX.newscalendar_days_with_news = narex_newscalendar_days_with_news;
    // vlozeni do globalniho objektu - BEGIN
    
    
    
    newsDateSelector.createMinicalendar();
    
}

    // vytvari kalendar na zaklade zvoleneho mesice - BEGIN
    newsDateSelector.createMinicalendar = function () {
        
        // pocet dnu aktualniho mesice
        var days_in_actual_month = 32 - new Date(NAREX.newscalendar_display_year, (NAREX.newscalendar_display_month - 1), 32).getDate();
        
        // prvni den v tydnu aktualniho mesice
        var first_day_in_actual_month = new Date(NAREX.newscalendar_display_year, (NAREX.newscalendar_display_month - 1)).getDay();
        
        // prevod javascriptovych dnu v tydnu na "normalni"
        // index je cesky, hodnota je JS
        var week_days = new Array(1, 2, 3, 4, 5, 6, 0);
        
        // vytvoreni kalendare - BEGIN
        
            // zacatek tabulky
            var html = '<table id="minicalendar">';
            html += '<thead><tr><th>Po</th><th>Út</th><th>St</th><th>Čt</th><th>Pá</th><th>So</th><th>Ne</th></tr></thead>';
            html += '<tbody>';
            
            // telo kalendare - BEGIN
            var day_counter = 1;
            var day_in_week = 1;
            
                
                // zacatek kalendare - BEGIN
                html += '<tr>';
                for (var x = 0; x < 7; x++) {
                    if (week_days[x] != first_day_in_actual_month) {
                        html += '<td>&nbsp;</td>';
                        day_in_week++;
                    }
                    
                    else {
                        break;
                    }
                }
                
                for (var x = day_in_week; x <= 7; x++) {
                    
                    if (jQuery.inArray(day_counter, NAREX.newscalendar_days_with_news) != -1) {
                        html += '<td class="has-news"><span>' + day_counter + '</span></td>';
                    }
                    else {
                        html += '<td><span>' + day_counter + '</span></td>';
                    }
                    
                    day_in_week++;
                    day_counter++;
                }
                
                html += '</tr>';
                day_in_week = 1;
                // zacatek kalendare - BEGIN
                
                
                // stred tabulky - BEGIN
                html += '<tr>';
                for (var x = day_counter; x <= days_in_actual_month; x++) {
                    
                    if (jQuery.inArray(day_counter, NAREX.newscalendar_days_with_news) != -1) {
                        html += '<td class="has-news"><span>' + day_counter + '</span></td>';
                    } 
                    else {
                        html += '<td><span>' + day_counter + '</span></td>';
                    }
                    
                    if (day_in_week == 7) {
                        html += '</tr><tr>';
                        day_in_week = 1;
                    }
                    
                    else {
                        day_in_week++;
                    }
                    
                    day_counter++;
                    
                }
                // stred tabulky - END
                
                // dokonceni tela - BEGIN
                if (day_in_week != 7) {
                    for (var x = day_in_week; x <= 7; x++) {
                        html += '<td>&nbsp;</td>';
                        if (x == 7) {
                            html += '</tr>';
                        }
                    }
                }
                // dokonceni tela - END
            
            // telo kalendare - END
            
            // konec tabulky
            html += '</tbody>';
            html += '</table>';
        
        // vytvoreni kalendare - END
        
        // vlozeni kalendare do stranky
        jQuery('#news_date_selector').append(html);
        
    }
    // vytvari kalendar na zaklade zvoleneho mesice - END

/* -----------------------------------------------------------------------------
news Date Selector - END
============================================================================= */





/* =============================================================================
salesAndServiceMaps - BEGIN
- zajistuje funkci zobrazovani servisnich a prodejnich mist pomoci Google Maps
----------------------------------------------------------------------------- */

// zakladni inicializace - BEGIN
function salesAndServiceMaps () {
    
    // neexistuje prostor pro mapu
    if (jQuery('#google_map_canvas').length == 0) return;
    
    
    // inicializace mapy
    gmap_initialize();
    
    
    // inicializace geocoderu
    NAREX.geocoder = new google.maps.Geocoder();
    
    // zaveseni udalosti na odeslani formulare
    findPlacesFormAction();
    
    // focus na pole adresy - BEGIN
    jQuery('#center_point_address').focusin(function () {
        if (jQuery(this).attr('value') == NAREX.default_map_adress_field_text) {
            jQuery(this).attr('value', '');
        }
    });
    jQuery('#center_point_address').focusout(function () {
        if (jQuery.trim(jQuery(this).attr('value')) == '') {
            jQuery(this).attr('value', NAREX.default_map_adress_field_text);
        }
    });
    // focus na pole adresy - END
    
    
    // nastaveni markeru pro stred hledani - BEGIN
    setCenterMarker();
    // nastaveni markeru pro stred hledani - END
    
    // nacteni markeru z vCards mikroformatu - BEGIN
    createMarkersFromVcards();
    // nacteni markeru z vCards mikroformatu - END
    
}
// zakladni inicializace - END


    // vytvoreni mapy, nastaveni stredua zoomu - BEGIN
    function gmap_initialize () {
        
        // neexistuje prostor pro mapu
        if (jQuery('#google_map_canvas').length == 0) return;
        
        // stred hledani - BEGIN
        
            // v hidden polozce je latlng stredu hledani - BEGIN
            if (jQuery('#map_center_lat').attr('value') != 'false' 
                && jQuery('#map_center_lng').attr('value') != 'false') {
                var center_point = new google.maps.LatLng(jQuery('#map_center_lat').attr('value'), jQuery('#map_center_lng').attr('value'));
            }
            // v hidden polozce je latlng stredu hledani - END
        
            // defaultni centrum hledani - BEGIN
            else {
                var center_point = new google.maps.LatLng(NAREX.default_map_center_lat, NAREX.default_map_center_lng);
                jQuery('#center_point_address').attr('value', NAREX.default_map_adress_field_text);
            }
            // defaultni centrum hledani - END
        
        // stred hledani - END
        
        // nastaveni zoomu - BEGIN
        var zoom = NAREX.default_map_zoom;
        // nastaveni zoomu - END
        
        // zobrazeni mapy - BEGIN
        NAREX.gmap = new google.maps.Map(document.getElementById("google_map_canvas"), 
            {
                zoom: zoom,
                center: center_point,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                scaleControl: true
            });
        // zobrazeni mapy - END
        
    }
    // vytvoreni mapy, nastaveni stredua zoomu - END
    
    
    // akce pro odeslani formulare hledani - BEGIN
    function findPlacesFormAction () {
        
        jQuery('#find_places').click(function (e) {
            
            e.preventDefault();
            var address = jQuery('#center_point_address').attr('value');
            
            // nebyla zadana adresa pro hledani 
            if (address == NAREX.default_map_adress_field_text) return;
            
            // ziskani latlng hledaneho mista z geocoderu - BEGIN
            NAREX.geocoder.geocode({'address': address}, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    
                    // filtrace stejnych vysledku - BEGIN
                    var filtered_results = new Array();
                    var indexes = new Array();
                    for (var x = 0; x < results.length; x++) {
                        if (jQuery.inArray(results[x].formatted_address, indexes)) {
                            indexes.push(results[x].formatted_address);
                            filtered_results.push(results[x]);
                        }
                    }
                    // filtrace stejnych vysledku - END
                    
                    // vice nez jeden vysledek - BEGIN
                    if (filtered_results.length > 1) {
                        findPlacesFormMessages('many-results', filtered_results);
                        return;
                    }
                    // vice nez jeden vysledek - END
                    
                    // odeslani formulare (adresa je jednoznacna) - BEGIN
                    else {
                        jQuery('#map_center_lat').attr('value', filtered_results[0].geometry.location.lat());
                        jQuery('#map_center_lng').attr('value', filtered_results[0].geometry.location.lng());
                        jQuery('#center_point_address').attr('value', filtered_results[0].formatted_address);
                        
                        // odeslani s testem na existenci hlavniho NET formulare - BEGIN
                        
                            // sestaveni GET stringu - BEGIN
                            var get_string = '?';
                            
                            // sekce - BEGIN
                            if (document.location.search.search('type=shops') != -1) {
                                get_string += 'type=shops&';
                            }
                            if (document.location.search.search('type=services') != -1) {
                                get_string += 'type=services&';
                            }
                            // sekce - END
                            
                            get_string += 'lat=' + jQuery('#map_center_lat').attr('value');
                            get_string +=  '&lng=' + jQuery('#map_center_lng').attr('value');
                            get_string +=  '&address=' + jQuery('#center_point_address').attr('value');
                            get_string +=  '&distanc=' + jQuery('#places_radius').attr('value');
                            // sestaveni GET stringu - BEGIN
                            
                            var action = 'Sales_and_services.aspx' + get_string;
                        
                            // nastaveni action a odeslani formulare - BEGIN
                            jQuery('#aspnetForm').attr('action', action);
                            jQuery('#aspnetForm').submit();
                            // nastaveni action a odeslani formulare - BEGIN
                            
                        // odeslani s testem na existenci hlavniho NET formulare - END
                        
                    }
                    // odeslani formulare - END
                    
                }
                else {
                    findPlacesFormMessages('address non-exists', false);
                }
            });
            // ziskani latlng hledaneho mista z geocoderu - END
            
        });
        
    }
    // akce pro odeslani formulare hledani - END
    
    
    // hlasky pro chyby ve vyhledavani adresy - BEGIN
    function findPlacesFormMessages(type, results) {
        
        // odstraneni puvodni message
        jQuery('#find_places_messages').remove();
        
        // adresa nebyla nalezena - BEGIN
        if (type == 'address-non-exists') {
            var html = '<p class="error" id="find_places_messages">';
            html += NAREX.geocoder_return_empty_result;
            html += '</p>';
            jQuery('#find_places_wrapper').prepend(html);
        }
        // adresa nebyla nalezena - END
        
        // nejednoznacna adresa (vice vysledku) - BEGIN
        if (type == 'many-results') {
            var html = '<div class="notice" id="find_places_messages">';
            html += '<p>' + NAREX.geocoder_return_many_result + '</p>';
            html += '<ul>';
            for (var x = 0; x < results.length; x++) {
                html += '<li>';
                html += '<a href="#' + results[x].formatted_address + '" id="many_results_' + x + '" class="many_results">';
                html += results[x].formatted_address;
                html += '</a>';
                html += '</li>';
            }
            html += '</ul>';
            html += '</div>';
            jQuery('#find_places_wrapper').prepend(html);
            
            // naveseni udalosti na linky - BEGIN
            jQuery.each(jQuery('.many_results'), function (x, elm) {
                jQuery(elm).click(function (e) {
                    e.preventDefault;
                    var address = jQuery(this).attr('href');
                    jQuery('#center_point_address').attr('value', address.substring(1));
                    jQuery('#find_places').click(); // vyvolani stisknuti tlacitka pro odeslani formulare
                });
            });
            // naveseni udalosti na linky - END
            
        }
        // nejednoznacna adresa (vice vysledku) - END
        
    }
    // hlasky pro chyby ve vyhledavani adresy - END
    
    
    // nastaveni markeru pro stred hledani - BEGIN
    function setCenterMarker() {
        
        if (jQuery('#map_center_lat').attr('value') != 'false' 
                && jQuery('#map_center_lng').attr('value') != 'false') {
            
            var latlng = new google.maps.LatLng(jQuery('#map_center_lat').attr('value'), jQuery('#map_center_lng').attr('value'));
            var image = './css/img/google-maps-markers-center-point.png';
            
            var center_marker = new google.maps.Marker({
                position: latlng, 
                map: NAREX.gmap, 
                title: jQuery('#center_point_address').attr('value'),
                icon: image
            });
                    
        }
        
        else {
            return;
        }
        
    }
    // nastaveni markeru pro stred hledani - END
    
    
    // nacteni markeru z vCards mikroformatu - BEGIN
    function createMarkersFromVcards () {
        
        // vcards
        var vcards = jQuery('.vcard', '#places_results_list');
        if (vcards.length == 0) return;
        
        NAREX.gmap_markers_bounds = new google.maps.LatLngBounds(); // pro automaticky zoom
        
        jQuery.each(vcards, function (i, elm) {
        
            // ikona
            var image = './css/img/google-maps-markers-place-point.png';
            
            // latlng
            var latlng = new google.maps.LatLng(jQuery('.latitude', jQuery(elm)).text(), jQuery('.longitude', jQuery(elm)).text());
            
            
            // title
            var title = jQuery('h2', jQuery(elm)).text();
            
            // vytvoreni markeru
            var marker = new google.maps.Marker({
                position: latlng, 
                map: NAREX.gmap, 
                title: title,
                icon: image
            });
            
            // vytvoreni infowindow - BEGIN
            var html = '<div class="infowindow"><p>';
            html += '<strong>' + title + '</strong><br />';
            html += jQuery('.street-address', jQuery(elm)).text() + '<br />';
            html += jQuery('.postal-code', jQuery(elm)).text() + ' ' + jQuery('.locality', jQuery(elm)).text() + '<br />';
            html += jQuery('.country-name', jQuery(elm)).text();
            html += '</p></div>';
            var infowindow = new google.maps.InfoWindow({
                content: html
            });
            // vytvoreni infowindow - END
            
            // pripojeni infowindow
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.open(NAREX.gmap,marker);
            });
            
            // pridani latlng markeru do storage (pro automaticky zooming)
            NAREX.gmap_markers_bounds.extend(latlng);
            
            
        });
        
        // automaticky zoom
        NAREX.gmap.fitBounds(NAREX.gmap_markers_bounds);
        
        
    } 
    // nacteni markeru z vCards mikroformatu - END

/* -----------------------------------------------------------------------------
salesAndServiceMaps - END
============================================================================= */





/* =============================================================================
Sticker replacer - BEGIN
- v seznamu produktu vklada nalepky "novinka"... 
----------------------------------------------------------------------------- */
function stickerReplacer () {
    
    // vsechny spany, ktere maji tridu zacinajici na "sticker_replacer_"
    var stickers = jQuery('span').filter('[className^="replaceable_sticker_"]');
    
    stickers.each( function () {
        
        // sestaveni URL k obrazku
        var url = 'script_inserted_images/product_stickers/' + jQuery(this).attr('class') + '_' + NAREX.language + '.gif';
        
        // objekt obrazku - BEGIN
        var img = jQuery('<img>');
        img.hide();
        
            // naveseni udalosti na load - BEGIN
            img.bind('load', function () {
                jQuery(this).show();
            });
            // naveseni udalosti na load - END
        
        img.attr('src', url);
        // objekt obrazku - BEGIN
        
        // nastaveni tridy pro sticker box 
        jQuery(this).addClass('sticker_replacer').text('').append(img);
        
    });
    
    /*
    // vytvoreni pole nalepek - BEGIN
    NAREX.stickers = {};
    NAREX.stickers.url = [];
    NAREX.stickers.obj = [];
    NAREX.stickers.img = [];
    // vytvoreni pole nalepek - END
    
    // naplneni pole nalepek - BEGIN
    stickers.each( function () {
        
        var background_image_url = 'css/img/' + jQuery(this).attr('class') + '_' + NAREX.language + '.gif';
        var sticker_obj = jQuery(this);
        var index = NAREX.stickers.obj.length;
        
        NAREX.stickers.url.push(background_image_url);
        NAREX.stickers.obj.push(sticker_obj);
        
        // vytvoreni objektu obrazku - BEGIN
        var img = new Image ();
        img.src = background_image_url;
        NAREX.stickers.img.push(img);
        // vytvoreni objektu obrazku - BEGIN
        
        // zaveseni load eventu - BEGIN
        jQuery(NAREX.stickers.img[NAREX.stickers.img.length - 1]).load( function () {
            
        });
        // zaveseni load eventu - END
        
    });
    // naplneni pole nalepek - END
    console.dir(NAREX);
    
    // vytvoreni pole nalepek - END
    
    // vlozeni tridy a nastaevni bacground-image - BEGIN
    /*
    stickers.each( function () {
        var background_image = jQuery(this).attr('class') + '_' + NAREX.language + '.gif';
        var x = new Image();
        x.src = 'css/img/new-product_sticker.gif';
        jQuery(x).load(function () {
            console.log(jQuery(this).attr('src'));
            
        });
        jQuery(this).addClass('sticker_replacer');
        
        
    });
    */
    // vlozeni tridy a nastaevni bacground-image - END
    
}
/* -----------------------------------------------------------------------------
Sticker replacer - END
============================================================================= */



/* =============================================================================
Create email link - BEGIN
- v elementech class="email" nahradi vytvori link "mailto"
----------------------------------------------------------------------------- */
function createEmailLink () {
    
    jQuery.each(jQuery('.email'), function () {
        var email = jQuery(this).text();
        jQuery(this).html('<a href="mailto:' + email + '"' + '>' + email + '</a>');
    });
    
}
/* -----------------------------------------------------------------------------
Create email link - END
============================================================================= */
