$(document).ready(function() {
    blankTarget();

    $("a.fancybox").fancybox({
        'zoomSpeedIn': 300,
        'zoomSpeedOut': 300,
        'overlayShow': true,
        'hideOnContentClick': false,
        'titlePosition'	: 'over',
        'autoDimensions' : true,
		'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
    });

    $("a.iframe").fancybox({
        'zoomSpeedIn': 300,
        'zoomSpeedOut': 300,
        'overlayShow': true,
        'overlayOpacity': 0.7,
        'overlayColor': '#a4a4a4',
        'hideOnContentClick': false,
        'width': 720,
        'height': 405+19
    });

});

function blankTarget()
{
    if(!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for(var i=0; i<anchors.length; i++)
    {
        var anchor = anchors[i];
        anchor.tabindex = i;
        if(anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
        {
            anchor.target = "_blank";
        }
    }
}

function ajax(url, data, async, type, target, readyfunction)
{
    if(typeof async == 'undefined')
    {
        async = true;
    }

    if(typeof type == 'undefined')
    {
        type = 'html';
    }

    $.ajax({
		type: "POST",
		url: url,
		data: data,
        dataType: type,
        async: async,
		complete: function(xhr) {
		    if(typeof target == 'undefined' && xhr.responseText != '')
            {
                //alert(xhr.responseText);
            }
            else if(typeof target != 'undefined')
            {
                $( target ).html( xhr.responseText );
                if(typeof readyfunction != 'undefined')
                {
                    eval(readyfunction);
                }
            }
		}
	});
}

function reloadhajo(val, target_id, def)
{
    var selected = $(val).val();

    var d = '';
    d += '&selected=' + selected;
    d += '&def=' + def;

    ajax('_reloadhajo.php', d, true, 'html', target_id, "$( target ).val("+ def +")");
}
