var timeout = 0;
$(document).ready(function() {	
    var height = $('#blockB a').height();    
	
    function nextA() {
        clearTimeout(timeout);		
        $('#blockB').css({
            bottom: 0
        });
        $('#blockB').animate({
            bottom: -height
        }, 600);
        $('#blockB a:last-child').prependTo('#blockB');        	         
        $myclone = $('#blockB a:last-child').clone();	
        sliderimage = $myclone.attr('rev');
        $myclone.find('img').attr('src', sliderimage);
        $('#blockA').html($myclone);
        $('#blockA img').removeClass("min").addClass("max");        
        $('#blockA img').css({
            opacity: 0
        }).animate({
            opacity: 1
        }, 600);
        timeout = setTimeout(function() {
            nextA();
        }, 5000);
    };
	
    // mouse  events
    $('#slider')
    .mouseenter(function() {
        $('#bi-button').css({
            display: "block"
        });
    })
    .mouseleave(function() {
        $('#bi-button').css({
            display: "none"
        });
    });
    $('#bi-button')
    .css({
        opacity: 1
    })
    .bind('keydown mousedown', function(){
        $(this).addClass('btn-down');
    })
    .bind('keyup blur mouseup mouseleave', function(){
        $(this).removeClass('btn-down');
    })
    .click(function() {
        nextA();
    });

    nextA();
});
$(function(){
    $("#blockA a").live('click', function(){
        clearTimeout(timeout);
        var viewtype = $(this).attr('class');
        if(viewtype == 'image'){
            videosrc = $(this).attr('rel');
            window.location.href=videosrc;
        }
        else{
            embedsrc = $(this).find('input[name=videosource]').val();
            $('#slider #blockA').html(embedsrc);
        }
        return false;
    });
})
