$(function() {

    $(document).pngFix();

    initCommentForm();

    $("a.qtip").qtip({
        style: {name: 'dark',tip: true,border: {width: 7,radius: 7,color: '#000000'},padding: 10,width:300},
        position: {corner: {target: 'bottomMiddle', tooltip: 'topMiddle'}},
        show:{delay: 0}
    });

	$('.photobox .img').innerfade({
		speed: 'slow',
		timeout: 7000,
		type: 'sequence',
		containerheight: '314px'
	});

	$('.order_button a').click(function(e) {
	    $('.header .shopping_cart').css('display', 'block');
        alert("A terméket elhelyeztük a kosaradban. A rendelés véglegesítéséhez kattints a jobb felső sarokban megjelent kosárra.");
        return true;
    });


    $(".imgshow ul li a").click(function(e) {
        var p = $(this).parents("li");
        var index = $(".imgshow ul li").index(p);
        var tmp = $(this).attr("title");
        tmp2 = tmp.split(" | ");
        var titl = tmp2[0];
        var comm = tmp2[1];

        var kep = $(".imgshow img:eq("+index+")").parents("a");

        $(".imgshow ul li").removeClass("active");
        $(this).parents("li").addClass("active");
        $(".imgshow img").parents("a").css("display", "none");
        kep.css("display", "block");
        $(".imgshow_text .right").html(titl);
        $(".imgshow_text .comments a").html(comm + ' hozzászólás');
        $(".imgshow_text .comments a").attr('href', kep.attr('href')+'#comments');

        return false;
    });

});



var needToCheckErrors = true;

function errorcheck(){
    var t = $("#comment_text").val();
    if(t == ''){
        alert("Írd be a hozzászólásod!");
        return false;
    } else {
        $("form.commentform").trigger("submit");
        return true;
    }
    return false;
}

function initCommentForm(){
    $("form.commentform").submit(function(){
        var t = $("#comment_text").val();

        if(needToCheckErrors == true){
            if(t == ''){
                alert("Írd be a hozzászólásod!");
                return false;
            } else {
                needToCheckErrors = false;
                $("form.commentform").trigger("submit");
                return true;
            }
            return false;
        } else {
            return true;
        }
    });

}
