﻿$(function () {
    $('#menu ul li').hover(function () {
        if ($(this).children('ul').length) {
            $(this).children('ul').show();
        }
    }, function () {
        if ($(this).children('ul').length) {
            $(this).children('ul').hide();
        }
    });

    //Init offer slideshow
    if ($('#slides > ul li').length > 1) {
        $('#slides > ul').cycle({
            fx: 'fade',
            speed: 2000,
            delay: 2000,
            before: function () {
                moveMarker($(this).index());
            }
        });
    }

    $('#slides .balk li').click(function () {
        $('#slides > ul').cycle($(this).index('#slides .balk li'));
        $('#slides .balk li').removeClass('active');
        $(this).addClass('active');
    });

    //Init active images
    $('#partners .left img,#partners .right img').each(function () {
        $('<img src="' + $(this).attr('data-hover') + '" class="hover" />').insertBefore(this).css({ opacity: 0 });
    });
    $('#partners .left li,#partners .right li').hover(function () {
        $(this).find('.hover').stop().animate({
            opacity: 1
        });
    }, function () {
        $(this).find('.hover').stop().animate({
            opacity: 0
        });
    });

});

//moveMarker(index)
//Moves the offer marker to the correct position
function moveMarker(index) {

    var items = $('#slides .balk li');
    var current = $('#slides .balk li:eq(' + index + ')');
    var previous = $('#slides .balk li:eq(' + (index == 0 ? (items.length - 1) : index - 1) + ')');

    $(current).addClass("active");
    $(previous).removeClass("active");
}
