
function startBannerCarousel(){
    pendingAnimation = false;
    bannerTimer = null;
    activeBanner = 0;
    bannerCount = jQuery(".flash .banners li").length;
    if (bannerCount > 1) {
        $("#menuHolder").css({
            "z-index": 2000
        });
        bannerContainer = $(".flash");
        $(".banners li", bannerContainer).css({
            opacity: 0.0
        });
        $(".banners li:first", bannerContainer).css({
            opacity: 1.0
        });
        bannerTimer = setInterval("rotateBannerCarousel()", 8000);
        $(".nav a", bannerContainer).click(function(e){
            e.preventDefault();
            if (pendingAnimation) {
                return false;
            }
            stopBannerCarousel();
            skipBannerCarousel($(".nav a", bannerContainer).index(this));
            bannerTimer = setInterval("rotateBannerCarousel()", 8000);
        });
        $(".flash .banners li").hover(
            function () {
                stopBannerCarousel();
            },
            function () {
                bannerTimer = setInterval("rotateBannerCarousel()", 8000);
            }
            );
    }
}

function stopBannerCarousel(){
    if (bannerTimer === null) {
        return;
    }
    clearInterval(bannerTimer);
}

function rotateBannerCarousel(){
    pendingAnimation = true;
    $(".banners li:eq(" + activeBanner + ")", bannerContainer).animate({
        opacity: 0.0
    }, 1000, function(){
        $(this).removeClass("active");
    });
    $(".nav li:eq(" + activeBanner + ")", bannerContainer).removeClass("active");
    activeBanner++;
    if (activeBanner >= bannerCount) {
        activeBanner = 0;
    }
    $(".banners li:eq(" + activeBanner + ")", bannerContainer).css({
        opacity: 0.0
    }).addClass("active").animate({
        opacity: 1.0
    }, 1000, function(){
        pendingAnimation = false;
    });
    $(".nav li:eq(" + activeBanner + ")", bannerContainer).addClass("active");
}

function skipBannerCarousel(i){
    pendingAnimation = true;
    $(".banners li:eq(" + activeBanner + ")", bannerContainer).animate({
        opacity: 0.0
    }, 1000, function(){
        $(this).removeClass("active");
    });
    $(".nav li:eq(" + activeBanner + ")", bannerContainer).removeClass("active");
    activeBanner = i;
    $(".banners li:eq(" + activeBanner + ")", bannerContainer).css({
        opacity: 0.0
    }).addClass("active").animate({
        opacity: 1.0
    }, 1000, function(){
        pendingAnimation = false;
    });
    $(".nav li:eq(" + activeBanner + ")", bannerContainer).addClass("active");
}



$(function(){

    /* carousel - starts */

    //startBannerCarousel();

    /* carousel - ends */

    /* chromebug - starts */

    var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
    if(is_chrome){
        $('.index-block2-col1 ol li span').css('float','none');
    }

    /* chromebug - ends */

    /* table - starts */

    $("table.table").each(function(){
        $(this).find('tr:odd').addClass('diff');
    });

    /* table - ends */

    /* main menu - starts */

    $('#nav>li').hover(
        function () {
            $(this).addClass('hover');
        },
        function () {
            $(this).removeClass('hover');
        }
        );

    /* main menu - ends */

    /* change language - starts */

    $('.lang-switcher a').click(function(e) {
        e.preventDefault();
        $(this).toggleClass('active');
        $('.lang').toggleClass('show');
    });


    /* change language - ends */

    /* show popup - starts */

    $('.login a').click(function(e) {			
        if($(this).is('.profile_link')){
            return true;
        }
        $('.login-popup').addClass('on');
        return false;
    });

    $('.login-popup-close a').click(function(e) {
        e.preventDefault();
        $('.login-popup').removeClass('on');
    });


    /* show popup - ends */

    /* form input - starts */

    $('input[type=text], textarea').focus(function() {
        if (this.value == this.defaultValue){
            this.value = '';
        }
        $(this).addClass('focus');
    });
    $('input[type=text], textarea').blur(function() {
        if (this.value == ''){
            this.value = this.defaultValue;
        }
        $(this).removeClass('focus');
    });

    /* form input - ends */

    /* benefits - starts */

    $('.benefits-block-left a').click(function(e) {
        e.preventDefault();
        $('.benefits-block-left li').removeClass('active');
        $(this).parents('li').addClass('active');
        li_id = $(this).parents('li').attr('id');
        $('.benefits-block-right-info').removeClass('active');
        $('#'+li_id+'-info').addClass('active');
    });

    /* benefits - ends */

    /* external link - starts */

    $('a[rel~="external"]').click(function(){
        $(this).attr({
            'target':'_blank'
        });
    });

/* external link - ends */

});

//----------------------------------------------------------------------------------------------------------------------------------

/* google maps - starts */

function showMap() {

    var myOptions = {
        zoom: 14,
        center: new google.maps.LatLng(55.6945604, 21.199230400000033 ),
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        scrollwheel: false
    }
    var map = new google.maps.Map(document.getElementById("map"), myOptions);

    setMarkers(map, offices);

}

var offices = [['FEZ', 55.6919604, 21.199230400000033 , 1]];

function setMarkers(map, locations) {
    var image = new google.maps.MarkerImage('images/icon.png',
        // This marker is 20 pixels wide by 32 pixels tall.
        new google.maps.Size(122, 99),
        // The origin for this image is 0,0.
        new google.maps.Point(0,0),
        // The anchor for this image is the base of the flagpole at 0,32.
        new google.maps.Point(57, 99));

    for (var i = 0; i < locations.length; i++) {
        var office = locations[i];
        var myLatLng = new google.maps.LatLng(office[1], office[2]);
        var marker = new google.maps.Marker({
            position: myLatLng,
            map: map,
            icon: image,
            title: office[0],
            zIndex: office[3]
        });
    }
}

$(function(){
    if($('#map').length > 0){
        showMap();
    }
});

$(function(){
    var contact_form = $('.smb_form');
    if(contact_form.length){
        var inputs = contact_form.find('input');
        var h = contact_form.find('input[name="cprstr"]');
        if(h.length){
            inputs.focus(function(){
                h.val('1789');
            });
        }
    }
});


/* google maps - ends */
