
$(function () {

    $(".scrollable").scrollable({ circular: true }).autoscroll({ autoplay: true });

});

// $(function () {
    // if ($('#newsslider').length > 0) {
        // $('#newsslider').bxSlider({
            // mode: 'vertical',
            // auto: true,
            // autoHover: true,
            // speed: 1250,
            // pause: 0
        // });
    // }
// });

$(document).ready(function () {

    $('.map li:last a').css("color", "#26aad3");

    function megaHoverOver() {
        $(this).find(".sub").stop().fadeTo('fast', 1).show();
        (function ($) {

            jQuery.fn.calcSubWidth = function () {
                rowWidth = 0;

                $(this).find("ul").each(function () {
                    rowWidth += $(this).width();
                });
            };
        })(jQuery);

        if ($(this).find(".row").length > 0) {

            var biggestRow = 0;

            $(this).find(".row").each(function () {
                $(this).calcSubWidth();

                if (rowWidth > biggestRow) {
                    biggestRow = rowWidth;
                }
            });

            $(this).find(".sub").css({ 'width': biggestRow });
            $(this).find(".row:last").css({ 'margin': '0' });

        } else {

            $(this).calcSubWidth();
            //  $(this).find(".sub").css({ 'width': rowWidth });

        }
    }

    function megaHoverOut() {
        $(this).find(".sub").stop().fadeTo('fast', 0, function () {
            $(this).hide();
        });
    }

    var config = {
        sensitivity: 2,
        interval: 100,
        over: megaHoverOver,
        timeout: 500,
        out: megaHoverOut
    };

    $(".topmenu li .sub").css({ 'opacity': '0' });
    $(".topmenu li").hoverIntent(config);

    Cufon.replace('.topmenu > li > a', { fontFamily: 'fontbold', hover: true, textShadow: '#0c5469 1px 1px 1px' });
    Cufon.replace('.boxitem span, .bigboxitem span, .bigboxitemnews span', { fontFamily: 'fontnormal', hover: true, textShadow: '#fff 1px 1px 1px' });
    


    $("#scroller").scrollable({ circular: true }).autoscroll({ autoplay: false });

    $('.boxitem:last').css("background", "none");

    $('.boxitem').hover(function () {
        $('img', this).animate({ height: '85px' }, 70);
    },
	function () {
	    $('img', this).animate({ height: '77px' }, 70);
	});

    $('.i1').hover(function () {
        $('img', this).animate({ height: '108px' }, 70);
    },
	function () {
	    $('img', this).animate({ height: '103px' }, 70);
	});

    $('.i2').hover(function () {
        $('img', this).animate({ height: '130px' }, 70);
    },
	function () {
	    $('img', this).animate({ height: '126px' }, 70);
	});
	
	var tnon = $('.newsdiv ul li').length;
	var ttnon = tnon * 20;
	var ctop = 0;
	var vtop = 0;
	var xtop = 0;

	$('.down').click(function () {
	    if ($('.newsdiv ul li').length > 2) {
	        ctop = ctop - 60;
	        $('.newsdiv ul').animate({ top: "" + ctop + "px" }, 250);
	        if (ctop <= ((ttnon * -1) + 160)) { xtop = (ttnon * -1) + 160; ctop = ctop + 60; $('.newsdiv ul').animate({ top: "" + xtop + "px" }, 100); }
	    }
	});

	$('.up').click(function () {
	    if ($('.newsdiv ul li').length > 2) {
	        ctop = ctop + 60;
	        $('.newsdiv ul').animate({ top: "" + ctop + "px" }, 250);
	        if (ctop >= 0) { ctop = 0; $('.newsdiv ul').animate({ top: "" + 0 + "px" }, 100); }
	    }

	});

    if ($('.anasayfa').length > 0) {
        $('.bottom').css({ 'padding-top': '45px' });
    }


    if ($('.tabnav1').length > 0) {
        $('.tabnav1').click(function () {
            $('.tabdiv1').slideToggle(400);
            $('.tabdiv2').slideUp(400);
        });
    }

    if ($('.tabnav2').length > 0) {
        $('.tabnav2').click(function () {
            $('.tabdiv2').slideToggle(400);
            $('.tabdiv1').slideUp(400);
        });
    }

});

$(window).load(function () {

    if ($('#slider').length > 0) {
        $('#slider').nivoSlider({ effect: 'fade', animSpeed: 1 });
        for (i = 0; i < $('#slider > a').length; i++) {
            var slink = $("#slider > a:eq(" + i + ")").attr("href");
            $(".nivo-controlNav > a:eq(" + i + ")").attr({ href: "" + slink + "" });
        }
        $('.nivo-control[rel="1"]').css("background-image", "url(/App_Templates/Theme1/Images/control-vrf.png)");
        $('.nivo-control[rel="2"]').css("background-image", "url(/App_Templates/Theme1/Images/control-yeni.png)");
        $('.nivo-control[rel="3"]').css("background-image", "url(/App_Templates/Theme1/Images/control-imalat.png)");
        $('.nivo-control[rel="4"]').css("background-image", "url(/App_Templates/Theme1/Images/control-munters.png)");
        $('.nivo-control[rel="5"]').css("background-image", "url(/App_Templates/Theme1/Images/control-bakim.png)");
    }

    $('.topmenu > li:eq(2) > .sub').css("width", "650px");
    $('.topmenu > li:eq(2) > .sub > ul:eq(2)').css({ 'margin-top': '70px', 'margin-left': '-130px' });
    $(".topmenu > li:eq(2) > .sub > ul:eq(3) > li:eq(1) > a").attr({ href: "http://www.munters.com.tr/tr/tr/UrunlerHizmetler/Hava-artlandrma-Bolumu-/", target: "_blank" });
    $(".topmenu > li:eq(2) > .sub > ul:eq(3) > li:eq(2) > a").attr({ href: "http://www.munters.com.tr/tr/tr/UrunlerHizmetler/AGHORT-Agriculture-Horticulture-TR/", target: "_blank" });
    $(".topmenu > li:eq(2) > .sub > ul:eq(3) > li:eq(3) > a").attr({ href: "http://www.munters.com/tr/Global/Products--Services/Spot-Climate-Control/", target: "_blank" });
    $(".topmenu > li:eq(2) > .sub > ul:eq(3) > li:eq(4) > a").attr({ href: "http://www.munters.com/tr/Global/Products--Services/Mist-Elimination/", target: "_blank" });



    for (i = 0; i < $('.topmenu > li').length; i++) {
        if ($('.topmenu > li:eq(' + i + ') .sub ul').length < 2) {
            var newlink = $(".topmenu > li:eq(" + i + ") > .sub > ul > li  a").attr("href");
            //alert(newlink);
        //    $(".topmenu > li:eq(" + i + ") > a").attr({ href: "" + newlink + "" });
            if ($(".topmenu > li:eq(" + i + ") > .sub > ul").length < 2) { $(".topmenu > li:eq(" + i + ") > .sub > ul > li:first").remove(); }
        }
    }

    $('.topmenu > li:first > a').attr({ href: "/Default.aspx" });

});
