﻿//########################################
//pobiera query z adresu strony
function getId(n) {
    var split = String(document.location).split("?");
    var query = split[1].split("&");
    for (i = 0; i < query.length; i++) {
        var nazwa = query[i].split("=")[0];
        var wartosc = query[i].split("=")[1];
        if (nazwa == n) return unescape(wartosc)
    }
}

//########################################
//wlacza animacje eventow
$(document).ready(function() {
    animate = true;
    lista = $('#events ul');
    lista.mouseover(function() {
        animate = false;
    }).mouseout(function() {
        animate = true
    });
    if (('#events ul li').length > 2) $('#events ul').simpleSpy();

    //animacja dolnych logow :D
    var $wraperLogos = $('#wraperLoga')
    var $divLogos = $('div:first', $wraperLogos);

    var $items = $('img', $divLogos);
    var $widthElementow = 0;
    var $widthWrapera = $('#wraperLoga').width();
    var $newPosition = $items.eq(0).width();
    $items.each(function() {
        $widthElementow += $(this).width();
    });

    function scrollCaruselLogos() {
        $divLogos.animate({
            left: -$newPosition
        }, 1000, function() {

            $divLogos.append($divLogos.find('a:first').clone());
            $divLogos.find('a:first').remove();

            $newPosition = $divLogos.find('a:first').width();
            $divLogos.css('left', 0)
        })
    }

    //elementy zajmuja wiecej niz wraper
    if ($widthElementow > $widthWrapera) {
        $wraperLogos.append('<img src="Images/gradient_l.png" style="z-index:100; top:0; left:0; position:absolute" />')
        $wraperLogos.append('<img src="Images/gradient_r.png" style="z-index:100; top:0; right:0; position:absolute" />')
        for (x = 0; x < $items.length; x++) {
            var $element = $items.eq(x);
            $divLogos.append($element.parent().clone())
            $divLogos.width($divLogos.width() + $element.width())
        }
        var animation = null;
            animation = setInterval(function() { scrollCaruselLogos() }, 2000);
        $('#wraperLoga div a').mouseover(function() {
            clearInterval(animation);
        });
        $('#wraperLoga div a').mouseout(function() {
            animation = setInterval(function() { scrollCaruselLogos() }, 2000);
        });
    } else {
        $wraperLogos.css('text-align', 'center');
    }

});
