// site specific javascript stuff

//console.log("running");

$(document).ready( function(){
    $('div.node.rug').each( popup_init );
});

function popup_init(){
    //console.log('popup_init()');
    
    // bind our function to the links
    $('div.rug a.rug_image_link').click( show_popup );

    // hide popup and bind our click handler for the popup
    $('#rug_detail_popup').removeClass('closed');
    $('#rug_detail_popup').hide();
    $('#rug_detail_popup').click( hide_popup );
    
    //console.log('popup_init() done');
}

// load the popup with the image clicked and then show it
function show_popup(){
    //console.log('show_popup(), this:', this );
    $('#rug_detail_popup img').attr('src', '');
    
    // get the image source from the anchors href, and load as img src 
    var img_src = $(this).attr('href');
    $('#rug_detail_popup img').attr('src', img_src);
    
    $('#rug_detail_popup').show();
    
    return false;
}

function hide_popup(){
    //$(this).addClass('closed');
    $(this).hide();
    // revert src to none
    $('#rug_detail_popup img').attr('src', '');
}
