
var isplaying = true;
function show_controls() {
	var T = '    ';
	var output = '';

	output += T+T+'<div class="carrousel_controls">'+"\n";
	output += T+T+T+'<div class="carrousel_pager"></div>'+"\n";
    output += T+T+T+T+'<a class="btn_stop">&#9632;</a>'+"\n";
    output += T+T+T+T+'<a class="btn_start">&#9654;</a>'+"\n";
    output += T+T+T+'</div>'+"\n";
	document.write(output);
}

var stop = function() {
    isplaying = false;
    jQuery('div#carrousel').cycle('pause');
    jQuery('div.carrousel_controls a.btn_start').show();
    jQuery('div.carrousel_controls a.btn_stop').hide();
}

var start = function() {
    isplaying = true;
    jQuery('div#carrousel').cycle('resume');
    jQuery('div.carrousel_controls a.btn_start').hide();
    jQuery('div.carrousel_controls a.btn_stop').show();
}

jQuery(document).ready(function() {
    $('div#carrousel').cycle({
        fx:         'fade',
        speed:      'slow',
        timeout:    6000,
        pager:      '.carrousel_pager'
    });
    
    jQuery('div.carrousel_controls a.btn_start').hide();
    
    jQuery('div.carrousel_controls a.btn_stop').click(stop);  
    jQuery('div.carrousel_controls a.btn_start').click(start); 
    
    $('div#carrousel').mouseover(function() {
        $('div.overlay').animate({
            height: '160'
        }, {queue: false, duration: 500} );
    }).mouseleave(function(event) {
        $('div.overlay').animate({
            height: '48px'
        }, {queue: false, duration: 500} );
        
    });

    var focusflag = false;
    jQuery("input, textarea").focus(function() {
        focusflag = true;
    }).blur(function() {
        focusflag = false;
    });

    jQuery(document).keypress(function(e) {
        if (e.which == 32 && focusflag === false) {
            e.preventDefault();
            (isplaying === true) ? stop() : start();
        }
    });
});

