// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function countSpinner() {
    // Check to see if the counter has been initialized
    if ( typeof countSpinner.counter == 'undefined' ) {
        // It has not... perform the initilization
        countSpinner.counter = 0;
    }
    return ++countSpinner.counter;
}

function spinnerLive( button, value)
{
    if( countSpinner() % 4 != 0 )
    {
        button.val(button.val()+".");
    }
    else
    {
        button.val(value);
    }
    
    setTimeout(function(){
        spinnerLive(button, value)
    }, 300);
}

$(document).ready(function(){
    $('.spinner').live('click', function(){
        $(this).addClass("spinned");
        spinnerLive ( $(this), $(this).val());
    });
    
    $('.markup').live('blur', function(){
        if( $(this).val() == "")
        {
            $(this).attr("style", "border-color: red;");
        }
        else
        {
            $(this).attr("style", "border-color: green;");
        }
    });
    
    flash();


    var videos = $('.video');
    if(videos.length > 0){
        videos.hover(function(){
            videos.not(this).css({
                opacity: 0.4
            });
        }, function(){
            videos.css({
                opacity: 1.0
            });
        });
    }

    if($('.slider').length > 0){
        $('.slider').cycle({
            fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
            timeout: 7000,
            speed: 1400
        });
    }

    if($('.slider2').length > 0){
        $('.slider2').cycle({
            fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
            timeout: 7000,
            speed: 1400
        });
    }
});


function flash(){
    if($('#flash') )
    {
        $('#flash').slideDown(1500).delay(6000).slideUp(1500);
    }
}

