﻿$(document).ready(function () {
    set();
});

function set() {
    setCufon();
    setHeadMenu();
    setBanners();
    setFontSizer();
    setNews();
    setTooltip();
    setSearch();
    setSubHome();
    setValidate();
}

function setValidate() {
    $.validator.addMethod(
        "regex",
        function (value, element, regexp) {
            var check = false;
            var re = new RegExp(regexp);
            return this.optional(element) || re.test(value);
        },
        "En az bir büyük harf bir küçük harf ve rakamdan oluşmalıdır"
    );

    $("form").validate({
        rules:
                {
                    UserName: { required: true },
                    Password: { required: true },
                    EMail: { required: true, email: true },
                    AgencyName: { required: true },
                    ExpertName: { required: true },
                    CustomerName: { required: true },
                    PolicyNo: { required: true },
                    OldPassword: { required: true },
                    NewPassword: { required: true, minlength: 8, maxlength: 10, regex: /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).*$/ },
                    NewPasswordRepeat: { required: true, minlength: 8, maxlength: 10, equalTo: "#NewPassword" },
                    Captcha: { required: true },

                    //goruş ve önerileriniz sayfasının
                    cAdSoyad: { required: true },
                    cTelefon: { required: true, number: true, maxlength: 15 },
                    cEPosta: { required: true, email: true },
                    cIl: { required: true },
                    cIlce: { required: true },
                    cBrans: { required: true },
                    cKonu: { required: true },
                    cEnUygunZaman: { required: true },

                    //ürünler>sağlık>kurumsal
                    kSirketAdi: { required: true, accept: "[a-zA-Z]+" },
                    kAdSoyad: { required: true, accept: "[a-zA-Z]+" },
                    kTelefon: { required: true, number: true, maxlength: 15 },
                    kEPosta: { required: true, email: true },
                    kIl: { required: true, accept: "[a-zA-Z]+" },
                    kIlce: { required: true, accept: "[a-zA-Z]+" },
                    kAdres: { required: true },
                    kCalisanSayi: { required: true }
                },
        errorLabelContainer: $("form div.error")
    });
}

function nextbanner() {
    if ($('.head .numbers a:first').attr('rel') == '1') {
        $('.head .numbers a:last').mouseover();
    }
    else
        $('.head .numbers a[rel=1]').prev().mouseover();
}

function setBanners() {
    var iVal = 5000;
    var iId = setInterval("nextbanner()", iVal);

    $('.head .numbers').empty();
    var count = $('.bannerContainer .banners').children().length;

    $('.bannerContainer .banners').width(973 * (count));


    $('.head .numbers a').attr('rel', '0');
    for (k = 0; k < count; k++) {
        $('<a>')
            .mouseover(function () {
                var i = ($('.head .numbers a').length - $(this).index()) - 1;
                banner = $('.bannerContainer .banners .banner:nth-child(' + (i + 1) + ')');

                $('.head .numbers a').attr('rel', '0');
                $(this).attr('rel', '1');

                rel = banner.attr('rel');
                $('.head .bannerText').hide();
                $('.head .bannerText.' + rel).show();
                $('.bannerContainer .banners').stop().animate({ marginLeft: 0 - (i * 973) })
                
                clearInterval(iId);
                iId = setInterval("nextbanner()", iVal);

            })
            .attr({ href: 'javascript:' })
            .css('background-position-x', 0 - (k * 19)).text(k + 1)
            .prependTo('.head .numbers');
    }
    $('.head .numbers a:last').mouseover().attr('rel', '1');
}

function setFontSizer() {
    var defsize = 12;
    function SetDescHeight() {
        // Kıl IE
        $('.middle .content.sub .description').css('height', $('.middle .content.sub .description .text').height() + 100);
    }

    $('#font-b').click(function () {
        $('.content.sub .description .text *').css({
            fontSize: function () { return parseInt($(this).css('font-size')) + 1; },
            lineHeight: '3ex'
        });
        SetDescHeight();
    });

    $('#font-s').click(function () {
        $('.content.sub .description .text *').css({
            fontSize: function () { return parseInt($(this).css('font-size')) - 1; },
            lineHeight: '3ex'
        });
        SetDescHeight();
    });

    $('#font-reset').click(function () {
        $('.content.sub .description .text *').css({
            fontSize: '',
            lineHeight: '3ex'
        });
        SetDescHeight();
    });

    //ekmek kırıntısındaki son oku gizler
    $('.middle .content.sub .description .navigation img').filter(':last').hide();
}


var activeNew = 0;
function nextNews(direction, newCount, w) {

    activeNew += direction;
    if (activeNew > 0) activeNew = 0;
    if (activeNew < 0 - (newCount - 2)) activeNew = 0 - (newCount - 2);
    $('.head .headbox.news .container .scrollPanel').stop().animate({ marginLeft: activeNew * w });

    if (activeNew == -(newCount - 2)) {
        activeNew = 1;
    }
}


function setNews() {
    var newCount = $('.head .headbox.news .container p').length + 1;
    var w = $('.head .headbox.news .container p').width();

    setInterval('nextNews(-1,' + newCount + ',' + w + ');', 4000);

    function setNew(direction) {
        activeNew += direction;
        if (activeNew > 0) activeNew = 0;
        if (activeNew < 0 - (newCount - 2)) activeNew = 0 - (newCount - 2);
        $('.head .headbox.news .container .scrollPanel').stop().animate({ marginLeft: activeNew * w });
    }


    $('.head .headbox.news .container .scrollPanel').width(newCount * w);

    $('.head .headbox.news .scroll.left').unbind('click').click(function () { setNew(1); });
    $('.head .headbox.news .scroll.right').unbind('click').click(function () { setNew(-1); });
}

function setTooltip() {
    $('.tooltip').mouseover(function () {
        $('.tooltipBox .text span').html($(this).attr('tooltip'));

        $('.tooltipBox')
        .css({ left: $(this).offset().left, top: $(this).offset().top - $('.tooltipBox').height() })
        .show()
        .find('.text span');
    }).mouseout(function () {
        $('.tooltipBox').hide();
    }).attr({
        'tooltip': function () { var tt = $(this).attr('title'); $(this).attr({ title: '', alt: '' }); return tt; }
    });
}

function setHeadMenu() {
    var active = $('.head .headmenu .menu a').mouseover(function () {
        $('.head .headmenu .menu .bg').stop().animate({
            marginLeft: $(this).offset().left - $('.head .headmenu .menu').offset().left,
            width: $(this).width()
        });
    }).filter('.active');

    if (active.length == 0) active = $('.head .headmenu .menu a:first');
    active.mouseover();

    $('.head .headmenu .menu').mouseout(function () {
        $('.head .headmenu .menu a.active').mouseover();
    });
}

function setCufon() {
    $('.cufon_sil').each(function () {
        var family = $(this).css('font-family');
        var size = $(this).css('font-size');
        var trimsize = size.substring(size.lenght - 2, 2);
        if (family == "Conduit") {
            var value = Math.floor(trimsize / 3);
            trimsize = parseFloat(trimsize) + parseFloat(value);
        }

        params = { fontFamily: $(this).css('font-family'), fontWeight: $(this).css('font-weight'), fontSize: trimsize + 'px' };
        Cufon.replace(this, params);
    });
    setTimeout("setHeadMenu()", 200);
}

function setMenu(ust, orta, alt) {
    var defContentHeight = $('.content.sub').height();
    //İlk kırılım
    $('.middle .content.sub .menu > ul > li > a').click(function () {
        //$('.middle .content.sub .menu ul ul').hide();
        if ($(this).next().children().size() > 0)
            $(this).next().toggle('fast', function () {
                if ($.browser.msie && $('.content.sub .menu').height() > defContentHeight) {
                    $('.content.sub').css('height', $('.content.sub .menu').height());
                } else if ($.browser.msie) { $('.content.sub').css('height', defContentHeight); }
            });
    });

    //ikinci kırılım
    $('.middle .content.sub .menu > ul > li > ul > li > a').click(function () {
        // $('.middle .content.sub .menu ul ul ul').hide();
        if ($(this).next().children().size() > 0)
            $(this).next().toggle('fast', function () {
                if ($.browser.msie && $('.content.sub .menu').height() > defContentHeight) {
                    $('.content.sub').css('height', $('.content.sub .menu').height());
                } else if ($.browser.msie) { $('.content.sub').css('height', defContentHeight); }
            });
    });

    //son kırılımların alt çizgilerini gizle
    $('.middle .content.sub .menu ul').children().filter("li:last-child").css("border-bottom-width", "0px");
    $('.middle .content.sub .menu ul ul').children().filter("li:last-child").css("border-bottom-width", "0px");

    //bulunduğu sayfanın menüsünü açık getir.
    $('ul[rel="' + ust + '"]').show();
    $('ul[rel="' + orta + '"]').show();
    $('ul[rel="' + alt + '"]').show();

    $('.middle .content.sub .menu ul li').each(function () {
        if ($('ul li', this).length == 0)
            $('ul', this).hide();
    });

    $('.middle .content.sub .menu ul li ul li').each(function () {
        if ($('ul li ul li', this).length == 0)
            $('ul li ul', this).hide();
    });
}

function setSearch() {
    if (getUrlVars()["q"] != undefined)
        $('.searchtext').val(decodeURIComponent(getUrlVars()["q"]));

    $('.searchtext').keyup(function (e) {
        if (e.keyCode == 13) {
            search();
        }
    });
}

function getHomePageBannerSWF(swFile) {
    var str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width=953 height=403 VIEWASTEXT>';
    str += '<param name="movie" value="' + swFile + '" />';
    str += '<param name="quality" value="high" />';
    // wmode = window, transparent, opaque
    str += '<param name="wmode" value="transparent" />';
    str += '<param name="menu" value="false" />';
    str += '<embed src="' + swFile + '" width=953 height=403 menu="false" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed></object>';
    document.write(str);
}

//querystring pars
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function setSubHome() {
    $(".aabox").filter(":last").css("margin-right", "0px");
    $(".aabox a").hide();


    $(".aabox").hover(function () {
        $(this).children().filter(".ayrinti").show();
    }, function () { $(this).children().filter(".ayrinti").hide(); });


    $(".sliderleft").click(function () {
        if ($(this).data("click") != 1) {
            $(this).data("click", 1);
            $(".Container").animate({ scrollLeft: $(".Container").scrollLeft() - 219 }, "slow", function () {
                $(".sliderleft").data("click", 0);
            });
        }
    });
    $(".sliderright").click(function () {
        if ($(this).data("click") != 1) {
            $(this).data("click", 1);
            $(".Container").animate({ scrollLeft: $(".Container").scrollLeft() + 219 }, "slow", function () {
                $(".sliderright").data("click", 0);
            });
        }
    });


}

function ShowMessage(msg) {
    $("#alert").append("<div class='alertbox'><div class='msg'>" + msg + "</div><div class='close'><a href=# onclick='CloseBox();'><img src='/ui/img/Alert/btn-close.jpg' alt='#' /></a></div><div class='tamam'><a href=# onclick='CloseBox();'><img src='/ui/img/Alert/btn-tamam.jpg' alt='#' /></a></div></div>");
    $("#alert").show();
}

function CloseBox() {
    $("#alert").hide();
}
