$(document).ready(function(){
    // This initialises the demo scollpanes on the page.
    $('#pane1').jScrollPane();
    $('#pane2').jScrollPane({showArrows:true, scrollbarWidth:14, scrollbarMargin:10});
    $('#pane3').jScrollPane({showArrows:true, scrollbarWidth:14, scrollbarMargin:10});
});

function addthisReady() {
    // Register the preparePrint event
    $('.addthis_button_print span').click(preparePrint);
}

function clearText(field){
    if (field.defaultValue == field.value) 
        field.value = '';
    else if (field.value == '') 
        field.value = field.defaultValue;
}

function preparePrint() {
    // Get the active slider id
    var sliderWrapperId = $('.coin-slider.visible').attr('id');
    
    // Manipulate the id to find the active image's container
    var imageId = sliderWrapperId + '11';
    imageId = imageId.replace('coin-slider', 'cs');
    
    // Manipulate the id to find the active desc's container
    var descId = sliderWrapperId.replace('coin-slider', 'cs-title');
    
    // Get the desc of the active image (only if there is one)
    var desc = '';
    if ($('#' + descId).css('opacity') > 0)
        desc = $('#' + descId + ' font').html();
    
    // Get the image src of the active image
    var imgSrc = $('#' + imageId).css('background-image');
    imgSrc = imgSrc.replace('url(','').replace(')','');
    imgSrc = imgSrc.replace('\"', '');
    imgSrc = imgSrc.replace('\"', '');
    
    // Set the image and desc to print 
    // (for a full page layout)
    $('#print-image').attr('src', imgSrc);
    $('#print-desc').html(desc);
    
    // (for the printImage.php form)
    $('#imgSrc-input').attr('value', imgSrc);
    $('#desc-input').attr('value', desc);
}
