$(function(){
    $('#subpage-content, .sub-page').fadeIn(500);
    $('#content').fadeIn(700);
    
    $('#marquee').marquee().hover(function(){
        $(this).trigger('stop');
    },function(){
        $(this).trigger('start');
    });
    
    $('#vertical-menu li').hover(function() {
        $(this).children('.inactive_top').removeClass().addClass('active_top');
        $(this).children('.inactive_sub').removeClass().addClass('active_sub');
        $(this).children('.inactive_bottom').removeClass().addClass('active_bottom');
    },function(){
        $(this).children('.active_top').removeClass().addClass('inactive_top');
        $(this).children('.active_sub').removeClass().addClass('inactive_sub');
        $(this).children('.active_bottom').removeClass().addClass('inactive_bottom');
    });

    var total   = 52;
    var pos     = 0;
    var step    = 18
    var vis_c   = 10;
    
    $('#choose').hover(function() {
        $('#c_main').height(step*vis_c);
        if( pos > 0 )                   $('#arrow_top').show();
        if( pos  < (total - vis_c) )    $('#arrow_bottom').show();
    },function(){
        $('#c_main').height(step);
        $('#arrow_top').hide(0.001);
        $('#arrow_bottom').hide(0.001);
    });
    
    $('#arrow_bottom').click(function(){
        var curr_padd = parseInt($('#inner').css('margin-top'));

        if( pos < (total - vis_c) ) {
            pos++;
            curr_padd -= step;
            $('#inner').css('margin-top', curr_padd );
        }

        if( pos == (total - vis_c) ) {
            $('#arrow_bottom').hide(0.001);
        }
        
        if( pos != 0 ) {
            $('#arrow_top').show();
        }

    });
    
    $('#arrow_top').click(function(){
        var curr_padd = parseInt($('#inner').css('margin-top'));

        if( pos > 0 ) {
            pos--;
            curr_padd += step;
            $('#inner').css('margin-top', curr_padd );
        }
        
        if( pos === 0 ) {
            $('#arrow_top').hide(0.001);
        }
        
        
        if( pos < (total - vis_c) ) {
            $('#arrow_bottom').show();
        }

    });
    
    //akcija
    $('#akcija_main img:last').click(function(){
            window.location = "/Akcijos/";
    });
    $('#akcija_close').click(function(){
        $('#akcija_main').hide();
        $('#akcija_back').hide();
    });
    $(document).keypress(function(e){
        if( e.keyCode == 27 ) {
            $('#akcija_main').hide();
            $('#akcija_back').hide();
        }
    })
    
    
    //logo pulsing
    $('#logo').fadeTo( 1000, 0.5);
    $('#logo').fadeTo( 1000, 1);

    
    //ahover
    $('#menu li.button').mouseover(function(){
        var pos = $(this).position();
        $('#amiddle').stop().animate({ width: $(this).width() }, { duration: 800 });
        $('#ahover').stop().animate({ left: pos.left + 65, top: pos.top + 282 }, { duration: 500 });
        $('#ahover').show();

        /*} else {
            $('#ahover').css({left: pos.left + 65, top: pos.top + 282 });
            $('#amiddle').width( $(this).width() );
            
        }*/
    });
    $('#menu').mouseout(function(){
        $('#ahover').hide();
    });
    var tmp = $('#menu li.button:first').position();
    $('#ahover').css({left: tmp.left + 65, top: tmp.top + 282 });

});

$(window).load(function(){
    var akcija_main = $('#akcija_main');
    if( akcija_main.length == 1 ) {
        var lf = parseInt( ($(window).width() - akcija_main.width()) / 2  );
        var tp = parseInt( ($(window).height() - akcija_main.height()) / 2 );
        if( lf < 0 ) lf = 0;
        if( tp < 0 ) tp = 0;
        akcija_main.css( {left: lf, top: tp});
        akcija_main.fadeIn(1000);
    }
});
