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'], a[rel='lightbox-gallery']").fancybox({
        'autoScale'     : true,
        'titlePosition' : 'inside',
        'titleFormat'   : dfFancyboxTitleFormat,
        'transitionIn'  : 'elastic',
        'transitionOut' : 'elastic',
        'easingIn'      : 'easeOutBack',
        'easingOut'     : 'easeInBack',
        'scrolling'     : 'yes'
    });
    $("a[rel='lightbox-gmap']").fancybox({
        'autoScale'     : true,
        'titlePosition' : 'inside',
        'titleFormat'   : dfFancyboxTitleFormat,
        'transitionIn'  : 'fade',
        'transitionOut' : 'fade',
        'scrolling'     : 'yes',
        'showNavArrows' : false
    });
    $("a[rel='lightbox-gmap-path']").fancybox({
        'autoScale'     : true,
        'titlePosition' : 'inside',
        'titleFormat'   : dfFancyboxTitleFormat,
        'transitionIn'  : 'fade',
        'transitionOut' : 'fade',
        'scrolling'     : 'yes'
    });
    $("a[rel='lightbox-anker']").click(function() {
        $.fancybox( $( $( this ).attr( 'href' ) ).html() );
    });
    $("a.iframe").fancybox({
		'type'			: 'iframe',
        'titlePosition' : 'inside',
        'titleFormat'   : dfFancyboxTitleFormat
    });
    $("a.iframe800").fancybox({
        'width'  	    : 800,
        'height'	    : 600,
		'type'			: 'iframe',
        'titlePosition' : 'inside',
        'titleFormat'   : dfFancyboxTitleFormat
    });
    $("a.iframe1000").fancybox({
        'width'  	    : 1000,
        'height'	    : 750,
		'type'			: 'iframe',
        'titlePosition' : 'inside',
        'titleFormat'   : dfFancyboxTitleFormat
    });
    $('a.ajax, a.ajax800, a.ajax1000').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({
		'type'           : 'ajax',
        'titlePosition'  : 'inside',
        'titleFormat'    : dfFancyboxTitleFormat
    });
    $("a.ajax800").fancybox({
        'autoDimensions' : false,
        'width'  	     : 800,
        'height'         : 'auto',
		'type'			 : 'ajax',
        'titlePosition'  : 'inside',
        'titleFormat'    : dfFancyboxTitleFormat
    });
    $("a.ajax1000").fancybox({
        'autoDimensions' : false,
        'width'          : 1000,
        'height'         : 'auto',
		'type'           : 'ajax',
        'titlePosition'  : 'inside',
        'titleFormat'    : dfFancyboxTitleFormat
    });
    $("a.tooltip").cluetip({ showTitle: false });
    //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);
    });
});
