$(document).ready(function() {
    blankTarget();

    $('.slideshow').each(function(index) {
        $(this).cycle({
			fx:     'fade',
			timeout: 10000,
			speed:   600,
			sync:    false,
			prev:    '#prev',
			next:    '#next',
			pager:   '#nav',
			pagerAnchorBuilder: function(i) {
				if (index == 0) {
                    return '<a href="#">'+(i+1)+'</a>';
				}
                else {
                    return '#nav a:eq('+i+')';
                }
        	}
		});
    });

    $('.utolsokepek').each(function(index) {
        $(this).cycle({
			fx:     'fade',
			timeout: 6000,
			speed:   600,
			sync:    false
		});
    });

    $('.right_termek').each(function(index) {
        $(this).cycle({
			fx:     'fade',
			timeout: 6000,
			speed:   600,
			sync:    false
		});
    });
	

    $("a.fancybox").fancybox({
        'zoomSpeedIn': 300,
        'zoomSpeedOut': 300,
        'overlayShow': true,
        'hideOnContentClick': false,
        'titlePosition'	: 'over',
        'autoDimensions' : true
    });
	

    $("a.iframe").fancybox({
        'zoomSpeedIn': 300,
        'zoomSpeedOut': 300,
        'overlayShow': true,
        'overlayOpacity': 0.7,
        'overlayColor': '#a4a4a4',
        'hideOnContentClick': false,
        'titleShow': false,
        'width': 480,
        'height': 350
    });
	
    $("a.iframe_box").fancybox({
        'hideOnContentClick': false,
        'titleShow': false,
        'width': 350,
        'height': 145,
        'type': 'iframe'
    });

    $("a.iframe_mail").fancybox({
        'hideOnContentClick': false,
        'titleShow': false,
        'width': 460,
        'height': 400,
        'type': 'iframe'
    });

    $("a.popup_fancybox").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
        'titleShow'         : false,
        'autoDimensions'    : true,
        'onComplete'        : function() {
            $.fancybox.resize();
        },
        'scrolling'         : 'no'
    });

	$(".scroll").click(function(event){
		event.preventDefault();
    	var full_url = this.href;
		var parts = full_url.split("#");
		var trgt = parts[1];
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;
		$('html, body').animate({scrollTop:target_top}, 500);
	});

    $(".cart").fancybox({
        'autoScale' : true,
        'type' : 'ajax',
        'titleShow' : false,
        'href' : '_kosar.php',
        'overlayOpacity' : 0.4,
        'overlayColor' : '#000'
    });
	
    $('a.cluetip').cluetip({
        delayedClose: 1500,
        sticky: false,
        dropShadow: false,
        showTitle: false,
        mouseOutClose: true,
        closePosition: 'title',
        closeText: '<img src="img/cross.png" alt="close" />',
        fx: {open: 'fadeIn', openSpeed: 750}
    });
});

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 setFontSize(size, item) {
    $('.font_size1').removeClass('actual');
    $('.font_size2').removeClass('actual');
    $('.font_size3').removeClass('actual');

    $(item).addClass('actual');

    $('p.lead').css('font-size', size+'px');
    $('div.ck_editor').css('font-size', size+'px');
}

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 reload(file, val, target_id, def, func)
{
    var fk = $(val).attr('id');
    var selected = $(val).val();

    var d = '';
    d += '&selected=' + selected;
    d += '&def=' + def;

    if(typeof func == 'uncefined') {
        func = '';
    }

    ajax(file, d, true, 'html', target_id, "$( target ).val("+ def +");" + func);
}

function reloadCaptcha(id)
{
	document.getElementById('captcha_'+id).src = 'include/kcaptcha/?'+Math.random();
}

function reloadKoromszalon(elite, varos_id, target_id)
{
    var d = '';
    d += '&varos_id=' + varos_id;
    d += '&elite=' + elite;

    ajax('_reload_koromszalonok.php', d, true, 'html', target_id);
}

function reloadSzakuzlet(varos_id, target_id)
{
    var d = '';
    d += 'varos_id=' + varos_id;

    ajax('_reload_szakuzletek.php', d, true, 'html', target_id);
}

function reloadSzakuzlet_subpage(varos_id, target_id)
{
    var d = '';
    d += 'varos_id=' + varos_id;

    ajax('_reload_szakuzletek_subpage.php', d, true, 'html', target_id);
}

function reloadFelhasznalo(galeria_id, varos_id, def)
{
    var d = '';
	if(typeof galeria_id != 'undefined' && galeria_id != 0){
    	d += '&galeria_id=' + $(galeria_id).val();
	}
    d += '&varos_id=' + $(varos_id).val();

    ajax('_reload_felhasznalo.php', d, true, 'html', '#felhasznalo_id', "$('#felhasznalo_id').val("+ def +")");
}

function ertekel(ertek, msg)
{
    var d = '';
    d += 'id=' + current;
    d += '&ertek=' + ertek;

    ajax('_ertekel.php', d, false, 'script');

    if(typeof nemszavazhat != 'undefined' && nemszavazhat == 1)
    {
        alert(msg);
    }
    else
    {
        $('#rating').width(w+'px');
        $('#atlag').html('(' + atlag + ')');
        $('#ertekeles').html(ertekeles);
    }
}

function idojaras(regio)
{
    var d = 'regio=' + regio;

    $('#idojaras').load('_idojaras.php', d);
}

function kosarba(id)
{
    var data = 'id=' + id + '&db=' + $("#darabszam_" + id).val();

    $.ajax({
        url: "_kosarba.php",
        type: "POST",
        data: data,
        cache: false,
        async: false,
        success: function (response) {
            if(response != '') {
                $('#error').html(response);
            }
            else {
                //$('#error').html('');
                $("#cart").click();
                //$("#kosarinfo").load("_kosar_tartalom.php");
            }
        }
    });
}

function fb(data)
{
    $.ajax({
        url: '_fb.php',
        type: "POST",
        data: data,
        cache: false,
        async: false,
        success: function (response) {
            if(response != '') {
                alert(response);
            }
            else {
                alert('ok');
            }
        }
    });
}

function changeAll(form, input)
{
    var chkBox = null;

    for (i=0; i < document.getElementById(form).elements.length; i++)
    {
        if (document.getElementById(form).elements[i].name.search(input) != -1)
        {
            var id = "checkall_" + form + "_" + input;
            document.getElementById(form).elements[i].checked = document.getElementById(id).checked;
        }
    }
}
