﻿/// <depends path="$skin/scripts/jquery/jquery.js" />
/// <depends path="$skin/scripts/jquery/plugins/jquery.cookie.js" />
/// <depends path="$skin/scripts/slides.min.jquery.js" />

$(document).ready(function () {

    /* aktuális menüpont kijelölés */
    var url = document.location.href;
    var domain = document.location.host;
    var currentLocation = url.split(domain)[1].toLowerCase();

    if (currentLocation.indexOf('~~') > 0) {
        currentLocation = '/' + currentLocation.split('~~')[1];
    }

    if (!((currentLocation.length == 0) || (currentLocation == '/'))) {
        $('.CosmoMainMenu li').each(function () {

            var menuUrl = ($(this).find('a').attr('href').indexOf(domain) > 0) ? $(this).find('a').attr('href').split(domain)[1].toLowerCase() : $(this).find('a').attr('href').toLowerCase();

            if (((currentLocation.search(menuUrl) != -1) || ((currentLocation + "/").search(menuUrl) != -1)) && (menuUrl.length > 1)) {
                $(this).addClass('selected');
            }
        });
    }

    /* search */
    $("input.CosmoQuickSearchInput").click(
    function () {
        var text = "";
        $("input.CosmoQuickSearchInput").val(text);
    });

    // promo slider
    $('#CosmoSlider').slides({
        container: 'CosmoFavs',
        paginationClass: 'CosmoFavPager',
        preload: true,
        preloadImage: '/Root/Skins/cosmo/images/loading.gif',
        play: 5000,
        pause: 2500,
        hoverPause: true,
        effect: 'fade',
        hoverPause: true
    });

    /* article gallery */
    if ($('#CosmoArticleGallery').length > 0) {
        var noOfImages = $('#CosmoArticleGallery .item').length;

        var posControls = function () {
            var imageWidth = $('#CosmoArticleGallery .item:visible img').width();
            $('#CosmoArticleGallery .controls').css({ 'left': imageWidth + 25 + 'px', 'display': 'block' });
        };

        var checkIndex = function () {
            var actualIndex = $('#CosmoArticleGallery .item:visible').index();
            $('.info .actual').text(actualIndex);

            if (actualIndex == noOfImages) {
                $('.btn_prev').css({ 'visibility': 'visible' });
                $('.btn_next').css({ 'visibility': 'hidden' });
            }
            else if ($('.item:visible').index() == 1) {
                $('.btn_prev').css({ 'visibility': 'hidden' });
                $('.btn_next').css({ 'visibility': 'visible' });
            }
            else {
                $('.btn_prev').css({ 'visibility': 'visible' });
                $('.btn_next').css({ 'visibility': 'visible' });
            }
        };
        var showPrev = function (e) {
            e.preventDefault();
            $('#CosmoArticleGallery .item:visible').prev('.item').show().siblings('.item').hide();
            checkIndex();
        };
        var showNext = function (e) {
            e.preventDefault();
            $('#CosmoArticleGallery .item:visible').next('.item').show().siblings('.item').hide();
            checkIndex();
        };

        $('.btn_prev').click(showPrev);
        $('.btn_next').click(showNext);

        $(document).keydown(function (e) {
            if (e.keyCode == 37) {
                $('.btn_prev').trigger('click');
                return false;
            }
            if (e.keyCode == 39) {
                $('.btn_next').trigger('click');
                return false;
            }
        });

        //$('#CosmoArticleGallery .item:eq(0) img').load(function () { posControls() });
    };
});


