var google_map;

$(document).bind('google_maps_loaded', function() {

    google_map = new GoogleMaps('map', gmap_data);

    google_map.drawMap();

    if ((typeof(pc_location) !== 'undefined') && (typeof(pc_hint) !== 'undefined')) {

        google_map.addPoint(pc_location.lat, pc_location.lon, pc_hint, '/images_site/google_marker_red.png');
        google_map.setCenter(pc_location.lat, pc_location.lon);
        google_map.setZoom(9);

    } else {

        if ((typeof(gmap_center) !== 'undefined')) {

            google_map.setCenter(gmap_center.lat, gmap_center.lon);
            google_map.setZoom(gmap_center.zoom);
        }
    }
});

$(document).ready(function() {

    var gallery_image_count = $('.breeds_gallery_image');

    var gallery_width = gallery_image_count.length * 205 || 0;

    $('input[type=radio].star').rating();

    $('a[rel=lightbox]').lightBox({
        imageLoading : '/images_site/lightbox-ico-loading.gif',
        imageBtnClose : '/images_site/lightbox-btn-close.gif',
        imageBtnPrev : '/images_site/lightbox-btn-prev.gif',
        imageBtnNext : '/images_site/lightbox-btn-next.gif',
        imageBlank : '/images_site/lightbox-blank.gif',
        txtImage : trn.image_text,
        txtOf : trn.image_of_text
    });

    $('a[rel=items_lightbox]').each(function() {
        $(this).lightBox({
            imageLoading : '/images_site/lightbox-ico-loading.gif',
            imageBtnClose : '/images_site/lightbox-btn-close.gif',
            imageBtnPrev : '/images_site/lightbox-btn-prev.gif',
            imageBtnNext : '/images_site/lightbox-btn-next.gif',
            imageBlank : '/images_site/lightbox-blank.gif',
            txtImage : trn.image_text,
            txtOf : trn.image_of_text
        });
    })

    $('.breeds_gallery_nav_link').attr('href', 'javascript:void(0)');

    $('.breeds_gallery_slider').css('margin-left', '0px');

    if (gallery_width > 615) {

        $('.breeds_gallery_nav_prev').hide();

        $('.breeds_gallery_nav_hidden').removeClass('breeds_gallery_nav_hidden');

        $('.breeds_gallery_nav_link_next').click(function() {

            var animated = $('.breeds_gallery_slider:animated');

            if (animated.length > 0) return;

            var gallery_offset = parseInt($('.breeds_gallery_slider').css('margin-left'));

            if ((gallery_offset > ((gallery_width - 615) * -1))) {

                $('.breeds_gallery_slider').animate({ marginLeft: '-=205px' }, 1000);
                $('.breeds_gallery_slider').css('width', gallery_width);
            }

            if ((gallery_offset - 205) < 0) {
                $('.breeds_gallery_nav_prev').show();
            }

            if ((gallery_offset - 205) <= ((gallery_width - 615) * -1)) {
                $('.breeds_gallery_nav_next').hide();
            }
        });

        $('.breeds_gallery_nav_link_prev').click(function() {

            var animated = $('.breeds_gallery_slider:animated');

            if (animated.length > 0) return;

            var gallery_offset = parseInt($('.breeds_gallery_slider').css('margin-left'));

            if (gallery_offset < 0) {

                $('.breeds_gallery_slider').animate({ marginLeft: '+=205px' }, 1000);
                $('.breeds_gallery_slider').css('width', gallery_width);
            }

            if ((gallery_offset - 205) < ((gallery_width - 615) * -1)) {
                $('.breeds_gallery_nav_next').show();
            }

            if ((gallery_offset + 205) == 0) {
               $('.breeds_gallery_nav_prev').hide();
            }
        });
    }

    /* Shop display limit select box */

    $('.shop_display_limit_dropdown').change(function() {
        $('.shop_sort_form').submit();
    });

    /* Shop display sort select box */

    $('.shop_sort_dropdown').change(function() {
        $('.shop_sort_form').submit();
    });
});