function dfFancyboxTitleFormat(title, currentArray, currentIndex, currentOpts)
{
    var resultTitle = "<strong>" + title + "</strong>";

    if ($('#lightbox-caption' + currentArray[currentIndex].id.substr(8)).length)
    {
        resultTitle += "<br \/>" + $('#lightbox-caption' + currentArray[currentIndex].id.substr(8)).html();
    }
    
    return resultTitle;
}

$(function() {
    //ezImage - Lightbox
    $("a[rel^='lightbox']").fancybox({
        'autoScale'     : true,
        'titlePosition' : 'inside',
        'titleFormat'   : dfFancyboxTitleFormat,
        'transitionIn'  : 'elastic',
        'transitionOut' : 'elastic',
        'easingIn'      : 'easeOutBack',
        'easingOut'     : 'easeInBack',
        'scrolling'     : 'yes'
    });
    $("a.iframe").fancybox({
        'frameWidth'    : 560,
        'frameHeight'   : 320
    });
    $('a.ajax').attr('href', function() {
        var uri = $(this).attr('href').substr(1).split("/");
        var prefix = '/';
        var siteaccessTest = /[a-z][a-z][a-z]_[a-z][a-z]/g;

        if (siteaccessTest.test(uri[0]))
            prefix = '/' + uri.shift() + '/';
        return prefix + 'ezjscore/run/' + uri.join('/');
    });
    $("a.ajax").fancybox();
    //Navigator - GoToPage Textfield
    function gotopage(event) {
        if (event.keyCode == 13) {
            var item_limit = $('#gotopage_item_limit').html();
            var location_href = $('#gotopage_location_href').html();
            var location_new = location_href.substr(0, location_href.search('%%%')) + ($(this).attr('value') * item_limit - item_limit) + location_href.substr(location_href.search('%%%') + 3);
            document.location.href = location_new;
        }
    }
    $('.gotopage').focus(function() {
        if ('...' == $(this).attr('value'))
            $(this).attr('value', '');
        $(this).keyup(gotopage);
    });
    $('.gotopage').blur(function() {
        if ('' == $(this).attr('value'))
            $(this).attr('value', '...');
        $(this).unbind('keyup', gotopage);
    });
});
