$(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">' + title + '</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 ertekel(id, e_id, ertek)
{
    var d = '';
    d += 'id=' + id;
    d += '&e_id=' + e_id;
    d += '&ertek=' + ertek;

    ajax('_ertekeles.php', d, false, 'script');

    if(typeof nincsbelepve != 'undefined' && nincsbelepve == 1)
    {
        alert('Csak bejelentkezett felhasználók értékelhetnek.');
    }
    else if(typeof nemszavazhat != 'undefined' && nemszavazhat == 1)
    {
        alert('Ezt a szempontot már értékelte.');
    }
    else
    {
        $('#rating_' + e_id).width(w);
        $('#perc_' + e_id).html(szazalek+'%');
        $('#valasz_' + e_id).html(valasz);
    }
}

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);
                }
            }
		}
	});
}