$(document).ready(function() {
    /**
     *Rozwinięcie po załadowaniu
     */
    var hidebbox = true;        
    $('.bBoxStart div.top').animate({
        opacity: 0.7
    },500);
    $("#ePageBody").mousemove(function(event) {
        if(hidebbox) {
        setTimeout(function(){
            $('.bBoxStart div.top').animate({
                top: '0',
                opacity:1
            },500)
        },1000);
        hidebbox = false;
        }
    });
    
    /**
     * Poruszanie się przycisku
     */
    var tik = 3;
    var tikt = 100;
    setInterval(function(){
        if(slideIndexOver)
            return false
        $('.bBoxStart div.top .more').animate({
            "top": "+="+tik+"px"
        },tikt,'linear',$('.bBoxStart div.top .more').animate({
            "top": "-="+tik+"px"
        },tikt,'linear',$('.bBoxStart div.top .more').animate({
            "top": "+="+tik+"px"
        },tikt,'linear',$('.bBoxStart div.top .more').animate({
            "top": "-="+tik+"px"
        },tikt,'linear',function(){
            $('.bBoxStart div.top .more').animate({
                "top": "5px"
            },tikt)
        }))));
    },4000);
    /*
     * Najechanie na boksa - rozjaśnienie pozostałych
     */
    var slideIndex = false;
    $('.bBoxStart').hover( function(){
        if(slideIndex)
            return false;
        $('.bBoxStart').removeClass('hover').addClass('nhover');
        $(this).removeClass('nhover').addClass('hover');
        $('.bBoxStart').stop(true,true);
        $('.bBoxStart.hover').animate({
            opacity: 1
        }, 50);
        $('.bBoxStart.nhover').animate({
            opacity: 0.5
        }, 500);
    }, function(){
        $('.bBoxStart.nhover').animate({
            opacity: 1
        }, 500).removeClass('hover').addClass('nhover');
    });
    /*
     * Kliknięcie w boksa - rozsunięcie
     */
    var slideIndexOver = false;
    $('.bBoxStart div.top').click( function(){
        $(this).find('.addon').css('cursor','auto');
        if(slideIndexOver && $(this).css('top')!='0px' )
        {       
            $(this).attr('rel','');
            $(this).animate({
                top: '0'
            },500);
            slideIndexOver = false;
        }else{
            slideIndexOver = true;
            if( $.browser.msie==true )
            {
                $(this).click( function(){
                    window.location = $(this).find('a').attr('href');
                    return true;
                });
            }else{
                //Sprawdź, czy nie kliknięto w linka
                $(this).find('a').click( function(){
                    return true;
                });
        
                $(this).attr('rel','top');
                $(this).animate({
                    top: '-120px'
                },500);
                slideIndexOver = true;
            }
        } 
    });
    
    
    if( $.cookie('spotR') == 'played' ) {
        var flashvars = {
            startaccess: 1,
            wmode: "transparent"
        };
    } else {
        var flashvars = {
            startaccess: 0,
            wmode: "transparent"
        };
    }

    var params = {
        menu: "false",
        wmode: "transparent"
    };

    var attributes = {
        id: "mainVideo",
        name: "mainVideo",
        wmode: "transparent"
    };

    swfobject.embedSWF("./public/swf/main_video.swf", "mainVideo", "902", "330", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
});
