﻿$(document).ready(function () {
    $("#slider div").addClass("element");
    $("#slider div").addClass("deactive");
    $("#slider div:first").removeClass("deactive");
    $("#slider div:first").addClass("active");

    $("#slidePager a:first").addClass("activeDot");
    $("#slidePager img:first").attr("src", "/images/slideActive.png");

    var currentPosition = 0;
    var slideWidth = 940;
    var slides = $("#slider div");
    var numberOfSlides = slides.length;

    //slidersmall - Privatist
    $("#slidersmall div").addClass("element");
    $("#slidersmall div").addClass("deactivesmall");
    $("#slidersmall div:first").removeClass("deactivesmall");
    $("#slidersmall div:first").addClass("active");

    $("#slidePagersmall a:first").addClass("activeDot");
    $("#slidePagersmall img:first").attr("src", "/images/slideActive.png");

    var slideWidthsmall = 183;
    var slidessmall = $("#slidersmall div");

    //slidersmallVgs
    $("#slidersmallVgs div").addClass("element");
    $("#slidersmallVgs div").addClass("deactivesmall");
    $("#slidersmallVgs div:first").removeClass("deactivesmall");
    $("#slidersmallVgs div:first").addClass("active");

    $("#slidePagersmallVgs a:first").addClass("activeDot");
    $("#slidePagersmallVgs img:first").attr("src", "/images/slideActive.png");

    var slideWidthsmallVgs = 183;
    var slidessmallVgs = $("#slidersmallVgs div");

    //Rotate
    rotate = function () {
        play = setInterval(function () {
            currentPosition = currentPosition + 1;
            $("#slider div.active").animate({ left: slideWidth }, 700).animate({ left: -slideWidth }, 0);
            $active = $('#slider div.active').next();
            $activeDot = $("#slidePager a.activeDot").next();
            if ($active.length == 0) { //If paging reaches the end...
                $active = $('#slider div:first'); //go back to first
                $activeDot = $("#slidePager a:first");
                currentPosition = 0;
            }
            $("#slider div").removeClass('active');
            $active.addClass('active');
            $("#slider div.active").animate({ left: 0 }, 700);

            //paging
            $("#slidePager a").removeClass("activeDot");
            $("#slidePager img").attr("src", "/images/slideDot.png");
            $activeDot.addClass('activeDot');
            $("#slidePager a.activeDot img").attr("src", "/images/slideActive.png");
        }, 7000);
    };

    if (numberOfSlides > 1) {
        rotate();
    }

    //paging onClick
    $("#slidePager a").click(function (e) {
        e.preventDefault();
        $activeDot = $(this);
        if ($activeDot.hasClass("activeDot")) {   //disable click event on active slide
            return false;
        }

        //slide
        $("#slider div.active").animate({ left: slideWidth }, 700).animate({ left: -slideWidth }, 0);
        $("#slider div").removeClass('active');
        var imgPosition = $activeDot.attr("rel") - 1;
        $active = $("#slider div:eq(" + imgPosition + ")");
        $active.addClass('active');
        $("#slider div.active").animate({ left: 0 }, 700);

        //paging        
        $("#slidePager a").removeClass("activeDot");
        $("#slidePager img").attr("src", "/images/slideDot.png");
        $activeDot.addClass('activeDot');
        $("#slidePager a.activeDot img").attr("src", "/images/slideActive.png");

        //Reset Timer
        clearInterval(play); //Stop the rotation
        //return false; //Prevent browser jump to link anchor
        rotate();
    });

    //slideSmall paging onClick
    $("#slidePagersmall a").click(function (e) {
        e.preventDefault();
        $activeDot = $(this);
        if ($activeDot.hasClass("activeDot")) { return false;  }  //disable click event on active slide            

        //slide
        $("#slidersmall div.active").animate({ left: slideWidthsmall }, 700).animate({ left: -slideWidthsmall }, 0);
        $("#slidersmall div").removeClass('active');
        var imgPosition = $activeDot.attr("rel") - 1;
        $active = $("#slidersmall div:eq(" + imgPosition + ")");
        $active.addClass('active');
        $("#slidersmall div.active").animate({ left: 0 }, 700);

        //paging        
        $("#slidePagersmall a").removeClass("activeDot");
        $("#slidePagersmall img").attr("src", "/images/slideDot.png");
        $activeDot.addClass('activeDot');
        $("#slidePagersmall a.activeDot img").attr("src", "/images/slideActive.png");
    });

    //slideSmall Right
    $('.sliderSmallRight').click(function () {
        var slidesSmall = $("#slidersmall div");
        var numberOfSmallSlides = slidesSmall.length;
        $activeDot = $('#slidePagersmall a.activeDot');
        currentPosition = parseInt($activeDot.attr("rel")) + 1;
        
        if (currentPosition > numberOfSmallSlides) { return false; } //disable next if end.

        $("#slidersmall div.active").animate({ left: slideWidthsmall }, 700);
        $active = $('#slidersmall div.active').next();
        $("#slidersmall div").removeClass('active');
        $active.addClass('active');
        $("#slidersmall div.active").animate({ left: 0 }, 700);

        //paging
        $activeDot = $("#slidePagersmall a:eq(" + (currentPosition-1) + ")"); 
        $("#slidePagersmall a").removeClass("activeDot");
        $("#slidePagersmall img").attr("src", "/images/slideDot.png");
        $activeDot.addClass('activeDot');
        $("#slidePagersmall a.activeDot img").attr("src", "/images/slideActive.png");
    });

    //slideSmall Left
    $('.sliderSmallLeft').click(function () {
        var slidesSmall = $("#slidersmall div");
        var numberOfSmallSlides = slidesSmall.length;
        $activeDot = $('#slidePagersmall a.activeDot');
        currentPosition = parseInt($activeDot.attr("rel")) - 1;

        if (currentPosition < 1) { return false; } //disable prev if start.

        $("#slidersmall div.active").animate({ left: -slideWidthsmall }, 700);
        $active = $('#slidersmall div.active').prev();
        $("#slidersmall div").removeClass('active');
        $active.addClass('active');
        $("#slidersmall div.active").animate({ left: 0 }, 700);

        //paging
        $activeDot = $("#slidePagersmall a:eq(" + (currentPosition - 1) + ")");
        $("#slidePagersmall a").removeClass("activeDot");
        $("#slidePagersmall img").attr("src", "/images/slideDot.png");
        $activeDot.addClass('activeDot');
        $("#slidePagersmall a.activeDot img").attr("src", "/images/slideActive.png");
    });

    //slidesmall VGS

    //slideSmallVgs paging onClick
    $("#slidePagersmallVgs a").click(function (e) {
        e.preventDefault();
        $activeDot = $(this);
        if ($activeDot.hasClass("activeDot")) { return false; }  //disable click event on active slide            

        //slide
        $("#slidersmallVgs div.active").animate({ left: slideWidthsmall }, 700).animate({ left: -slideWidthsmall }, 0);
        $("#slidersmallVgs div").removeClass('active');
        var imgPosition = $activeDot.attr("rel") - 1;
        $active = $("#slidersmallVgs div:eq(" + imgPosition + ")");
        $active.addClass('active');
        $("#slidersmallVgs div.active").animate({ left: 0 }, 700);

        //paging        
        $("#slidePagersmallVgs a").removeClass("activeDot");
        $("#slidePagersmallVgs img").attr("src", "/images/slideDot.png");
        $activeDot.addClass('activeDot');
        $("#slidePagersmallVgs a.activeDot img").attr("src", "/images/slideActive.png");
    });

    //slideSmallVgs Right
    $('.sliderSmallRightVgs').click(function () {
        var slidesSmall = $("#slidersmallVgs div");
        var numberOfSmallSlides = slidessmallVgs.length;
        $activeDot = $('#slidePagersmallVgs a.activeDot');
        currentPosition = parseInt($activeDot.attr("rel")) + 1;

        if (currentPosition > numberOfSmallSlides) { return false; } //disable next if end.

        $("#slidersmallVgs div.active").animate({ left: slideWidthsmallVgs }, 700);
        $active = $('#slidersmallVgs div.active').next();
        $("#slidersmallVgs div").removeClass('active');
        $active.addClass('active');
        $("#slidersmallVgs div.active").animate({ left: 0 }, 700);

        //paging
        $activeDot = $("#slidePagersmallVgs a:eq(" + (currentPosition - 1) + ")");
        $("#slidePagersmallVgs a").removeClass("activeDot");
        $("#slidePagersmallVgs img").attr("src", "/images/slideDot.png");
        $activeDot.addClass('activeDot');
        $("#slidePagersmallVgs a.activeDot img").attr("src", "/images/slideActive.png");
    });

    //slideSmallVgs Left
    $('.sliderSmallLeftVgs').click(function () {
        var slidesSmall = $("#slidersmallVgs div");
        var numberOfSmallSlides = slidessmallVgs.length;
        $activeDot = $('#slidePagersmallVgs a.activeDot');
        currentPosition = parseInt($activeDot.attr("rel")) - 1;

        if (currentPosition < 1) { return false; } //disable prev if start.

        $("#slidersmallVgs div.active").animate({ left: -slideWidthsmallVgs }, 700);
        $active = $('#slidersmallVgs div.active').prev();
        $("#slidersmallVgs div").removeClass('active');
        $active.addClass('active');
        $("#slidersmallVgs div.active").animate({ left: 0 }, 700);

        //paging
        $activeDot = $("#slidePagersmallVgs a:eq(" + (currentPosition - 1) + ")");
        $("#slidePagersmallVgs a").removeClass("activeDot");
        $("#slidePagersmallVgs img").attr("src", "/images/slideDot.png");
        $activeDot.addClass('activeDot');
        $("#slidePagersmallVgs a.activeDot img").attr("src", "/images/slideActive.png");
    });

    //END slidesmall VGS

     //Hover function for icons in popupbox
        $('.searchpopupitem').hover(function () {
            $('a', this).css('color', '#ffffff');

        },
            function () {
                $('a', this).removeAttr('style');
            });



    // Hover function for icons in iconpanel
//    $('.item').hover(function () {
//        $('a', this).css('color', '#F38827');

//    },
//        function () {
//            $('a', this).removeAttr('style');
//        });

            $('.menulinklevel2').click(function () {
                $('.menulinklevel2').removeClass("selected");
                $('.menulinklevel2').addClass("notselected");
        $(this).removeClass("notselected");
        $(this).addClass("selected");


    });
    $('.mainmenulevel2 li.noclick').unbind('click');

    $('.closepopupbox').click(function () {
        $('#popupbox').fadeToggle("slow");
    });
    $('#searchnowfrontpagebutton').click(function () {
        $('#popupbox').fadeToggle("slow");
    });

});

