function setupLabel1() {
    if (jQuery('.label_radio input').length) {
        jQuery('.label_radio').each(function(){
            jQuery(this).removeClass('r_on');
        });
 
        jQuery('.label_radio input:checked').each(function(){          
            jQuery(this).parent('label').addClass('r_on');            
        });        
    }
}

jQuery(document).ready(function(){
    
    jQuery('marquee').marquee('marquee').mouseover(function () {
        $(this).trigger('stop');
    }).mouseout(function () {
        $(this).trigger('start');
    }).mousemove(function (event) {
        if ($(this).data('drag') == true) {
            this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
        }
    }).mousedown(function (event) {
        $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
    }).mouseup(function () {
        $(this).data('drag', false);
    });

    jQuery('.scroll-pane').jScrollPane({
        showArrows:true
    });
    jQuery('.scroll-pane-large').jScrollPane({
        showArrows:true
    });
    
    jQuery('.label_radio').click(function(){
        setupLabel1();
        document.cookie = "map_id=" + jQuery('.label_radio input:checked').attr("id");
        var src = APPPATH_URI + "themes/default/img/data/" + jQuery(this).attr("rel");
        jQuery("#bg-image").attr("src", src);
        document.cookie = "map_img=" + src;
    });

    var re_map =new RegExp("map_img"+"=[^;]+", "i") //construct RE to search for target name/value pair
    if (document.cookie.match(re_map)) { //if cookie found
        cookie_img = document.cookie.match(re_map)[0].split("=")[1];
        jQuery("#bg-image").attr("src", cookie_img);
    }

    var re_map_id=new RegExp("map_id"+"=[^;]+", "i") //construct RE to search for target name/value pair
    if (document.cookie.match(re_map_id)) { //if cookie found
        cookie_img_id = document.cookie.match(re_map_id)[0].split("=")[1];
        jQuery("#" + cookie_img_id).attr('checked', "checked");        
    }

    setupLabel1();

    // GALLERY

    jQuery("#zoom01").gzoom({
        sW: 470,
        sH: 250,
        lW: 3000,
        lH: 2500,
        lighbox : false
    });

    jQuery(".thumbnail", this).click(function() {
        src = jQuery(this).attr("rel");

        jQuery("#large-image").fadeOut(400, function(){
            $("#large-image").attr('src',src).bind('readystatechange load', function(){
                //if (this.complete)
                jQuery(this).fadeIn(400);
            });
        });
    })
    
});

