﻿$(document).ready(function () {

    try {

        $('#productTeaser').jCarouselLite({
            btnNext: '#productTeaserRight',
            btnPrev: '#productTeaserLeft',
            auto: 3000,
            speed: 1500,
            visible: 1

        });

    }
    catch (err)
    { }


    try {
        $('#macaroniSlider').jCarouselLite({
            btnNext: '#macaroniRigth',
            btnPrev: '#macaroniLeft',
            visible: 5,
            start: 0,
            speed: 500
        });
    }
    catch (err)
    { }






    $("ul.topNav li.sub1").hover(function () { //When trigger is clicked...
        //Following events are applied to the subnav itself (moving subnav up and down)
        $(this).find("ul.subnav").stop(true, true).slideDown('fast').show(); //Drop down the subnav on click

        $(this).hover(function () {
        }, function () {
            $(this).find("ul.subnav").stop(true, true).slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
        });

        //Following events are applied to the trigger (Hover events for the trigger)
    }).hover(function () {
        $(this).addClass("subhover"); //On hover over, add class "subhover"
    }, function () {	//On Hover Out
        $(this).removeClass("subhover"); //On hover out, remove class "subhover"
    });



    $("ul.topNav li.sub2").hover(function () { //When trigger is clicked...
        //Following events are applied to the subnav itself (moving subnav up and down)
        $(this).find("ul.subnav2").stop(true, true).slideDown('fast').show(); //Drop down the subnav on click

        $(this).hover(function () {
        }, function () {
            $(this).find("ul.subnav2").stop(true, true).slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
        });

        //Following events are applied to the trigger (Hover events for the trigger)
    }).hover(function () {
        $(this).addClass("subhover2"); //On hover over, add class "subhover"
    }, function () {	//On Hover Out
        $(this).removeClass("subhover2"); //On hover out, remove class "subhover"
    });

    $("ul.topNav li.sub3").hover(function () { //When trigger is clicked...
        //Following events are applied to the subnav itself (moving subnav up and down)
        $(this).find("ul.subnav3").stop(true, true).slideDown('fast').show(); //Drop down the subnav on click

        $(this).hover(function () {
        }, function () {
            $(this).find("ul.subnav3").stop(true, true).slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
        });

        //Following events are applied to the trigger (Hover events for the trigger)
    }).hover(function () {
        $(this).addClass("subhover3"); //On hover over, add class "subhover"
    }, function () {	//On Hover Out
        $(this).removeClass("subhover3"); //On hover out, remove class "subhover"
    });


    $('.searchtext').focus(function () {
        if ($(this).val() == $(this).attr('title')) {
            $(this).val('');
        }
    });
    $('.searchtext').blur(function () {
        if ($(this).val() == '') {
            $(this).val($(this).attr('title'));
        }
    });

    $('#txtNewsletter').focus(function () {
        if ($(this).val() == $(this).attr('title')) {
            $(this).val('');
        }
    });
    $('#txtNewsletter').blur(function () {
        if ($(this).val() == '') {
            $(this).val($(this).attr('title'));
        }
    });

    $('#btnNewsletter').click(function () {

        if ($('#txtNewsletter').val() != $('#txtNewsletter').attr('title')) {
            var emailStr = $('#txtNewsletter').val();

            $('#txtNewsletter').val('Ekleniyor...');

            var rege = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            if (rege.test(emailStr)) {
                //do something 

                $.ajax({
                    url: '/ebulten',
                    cache: false,
                    type: 'post',
                    data: {
                        email: emailStr
                    },
                    success: function (data) {
                        if (data == 'true') {
                            $('#txtNewsletter').val('Eklendi.');
                        }
                        else if (data == "exist") {
                            $('#txtNewsletter').val('Daha önceden eklemişsiniz.');
                        }
                        else {
                            $('#txtNewsletter').val('Eklenemedi.');
                        }
                    },
                    error: function (e) {
                        alert(e.responseText);
                        //document.write(e.responseText);
                    }
                });


            }
            else {
                $('#txtNewsletter').val('Geçerli e-posta girmelisiniz...');
                return;
            }


        }


    });


    $('.lunchDetay .imgContainer').css('height', '215px');

    $('.lunchDetay .imgContainer img').mouseover(function () {
        $(this).animate({ height: '247px',left: '-13px' }, 'fast');
    });

    $('.lunchDetay .imgContainer img').mouseout(function () {
        $(this).animate({ height: '215px', left: '0' }, 'fast');
    });


    $('.kartalDetay .imgContainer').css('height', '239px').css;

    $('.kartalDetay .imgContainer img').mouseover(function () {
        $(this).animate({ height: '275px', left: '-7px' }, 'fast');
    });

    $('.kartalDetay .imgContainer img').mouseout(function () {
        $(this).animate({ height: '239px', left: '0' }, 'fast');
    });


});

function toggleNewsDetail(sender,target) {

    $('.newsDetail').slideUp();
    $('.newsButton').attr('src', '/ui/images/arrowDown.png');

    if ($(target).is(':visible') == true) {
        $(target).slideUp();

        $(sender).attr('src', '/ui/images/arrowDown.png');

        
    }
    else {
        $(target).slideDown();
        $(sender).attr('src', '/ui/images/arrowUp.png');
    }
}


function search(lang) {
    var text = $('.searchtext').val();
    if (text.length > 2 && text != "")
        window.location = '/' + lang + '/s?q=' + text;
    else if (text.length < 3 || text == "")
        alert(alertText.replace("&#231;", "ç"));
}
