/*
* JS 1minuto v1.0
*
*/
$(document).ready(function(){
	// BROWSER DETECTION
	// Figure out what browser is being used
	var userOSAgent = navigator.userAgent.toLowerCase();
	jQuery.platform = {
	        mac: /mac/.test(userOSAgent),
	        osx: /mac os x/.test(userOSAgent),
	        win: /win/.test(userOSAgent),
	        linux: /linux/.test(userOSAgent)
	};
	// change default foint
	if( jQuery.platform.win == true )
	{
		// display old-browsers (IE6 & 7) alert
		jQuery.each(jQuery.browser, function(i) {
			jQuery.each(jQuery.browser, function(i, val) {
				if(val == true)
					$.browser.versionName = i;
			});
			if($.browser.msie){
				if( $.browser.version == '6.0' ||  $.browser.version == '7.0')
				{
					var $flash = $( '<div class="flash_message">Seu navegador está desatualizado. Para uma melhor experiência de navegação no site do Festival do Minuto, recomendamos o uso de um dos seguintes navegadores gratuitos e mais modernos:<br /><a href="http://www.mozilla.com/en-US/firefox/" target="_blank">Mozilla Firefox</a><br /><a href="http://www.google.com/chrome/" target="_blank">Google Chrome</a><br /><a href="http://www.microsoft.com/windows/downloads/" target="_blank">Internet Explorer 8+</a><br /><br />Your browser is out of date. To experience a better navigation across the One Minute Festival website, we recommend updating to one of the following free and modern browsers:<br /><a href="http://www.mozilla.com/en-US/firefox/" target="_blank">Mozilla Firefox</a><br /><a href="http://www.google.com/chrome/" target="_blank">Google Chrome</a><br /><a href="http://www.microsoft.com/windows/downloads/" target="_blank">Internet Explorer 8+</a><p class="close"><a href="javascript://" onclick="$( this ).parents( \'.flash_message\' ).fadeOut(500)">X</a></p></div>' );
					$('body').prepend( $flash );
				}
			}
		});	
	}

	// textarea maxlength
	// http://that-matt.com/2010/04/updated-textarea-maxlength-with-jquery-plugin/
	var onEditCallback = function(remaining){
		$(this).siblings('.charsRemaining').text("Characters remaining: " + remaining);

		if(remaining > 0){
			$(this).css('background-color', 'white');
		}
	}

	var onLimitCallback = function(){
		$(this).css('background-color', 'red');
	}

	$('textarea[maxlength]').limitMaxlength({
		onEdit: onEditCallback,
		onLimit: onLimitCallback
	});

});

// SCROLL/SLIDE
jQuery.fn.getIntSize = function(orientation){
	if (orientation == 'horizontal')
		measurement = 'width';
	else
		measurement = 'height';

	if ($(this).css(measurement))
            return parseInt($(this).css(measurement).substring(0,$(this).css(measurement).search('px')));
	else
		return -1;
}

jQuery.fn.getIntOrientation = function(orientation){
	if (orientation == 'horizontal')
		measurement = 'left';
	else
		measurement = 'top';

	if (($(this).css(measurement))&&($(this).css(measurement)!='auto'))
            {
		return parseInt($(this).css(measurement).substring(0,$(this).css(measurement).search('px')));
            }
	else
		return -1;
}

jQuery.fn.rollerMenu = function(settings){

	if ($(this).size() > 1){
		$(this).each(function(){
			$(this).rollerMenu(settings);
		})
		return true;
	}

	ul = $(this).find('ul');
	if($(this).find('.slider').size()==0){
		$(ul).parent().prepend($('<div class="slider"></div>'));
		$('.slider',this).append($('ul',this)).css({'position':'relative','display':'block','overflow':'hidden','height':'570px'});
		$('.slider ul',this).css({'position':'absolute','display':'block', 'height':'auto'})
	}

	/* setas scroll  */
        fator = 0;
	$('.arrow.forward, .arrow.back',this).attr('href','javascrip://').click(function(){
                if(settings.orientation == "horizontal")
                {
                    if ($(this).hasClass('forward'))
                    {
                        fator = fator-1;
                    }
                    else if($(this).hasClass('back'))
                    {
                        fator = fator+1;
                    }
                }
                else
                {
                    if ($(this).hasClass('forward'))
                        fator = 1;
                    else if($(this).hasClass('back'))
                        fator = -1;
                }
		roller(this,settings.orientation,fator,settings.step);
	}).click(function(){return false}).css({'cursor':'pointer','border':'1px'});

}

/*************************
funÃ§Ã£o roller
obj Ã© o item clicado
orientation Ã© a orientaÃ§Ã£o do movimento se Ã© horizontal ou vertical
fator Ã© o que faz a direÃ§Ã£o valer -1 Ã© backward e 1 Ã© forward
*/
function roller(obj,orientation,fator,step){
	if (orientation=='horizontal'){
		tmp = $('.pane',$(obj).parent()).getIntSize(orientation);
		slider = $('.wrapper',$(obj).parent()).getIntSize(orientation);
                //position = ($('.pane ul',$(obj).parent()).getIntOrientation(orientation) + (step*fator));
                position = ($('.pane ul',$(obj).parent()).getIntOrientation(orientation) + (step*fator) - fator );
		if (-1*(tmp-slider)>=position) position = -1 * ( (tmp) - (slider) );
		if (position > 0) position = 0;
		if (position <= 0)
                    $('.pane',$(obj).parent()).animate({'left':position+'px'})
		if (fator*position < tmp){
                    $('.pane',obj).animate({'left':position+'px'})
		}
	}else{
		var tmp = 0
		$('.slider ul li',$(obj).parent().parent()).each(function(){
			tmp = tmp + $(this).getIntSize(orientation) + 19;
		})
		slider = $('.slider',$(obj).parent().parent()).getIntSize()
		position = ($('.slider ul',$(obj).parent().parent()).getIntOrientation(orientation) + step*fator);
		if (-1*(tmp-slider)>=position) position = -1*(tmp-slider);
		if (position > 0) position = 0;
		if (position <= 0)
			$('.slider ul',$(obj).parent().parent()).animate({'top':position+'px'})
		if (fator*position < tmp)
			$(obj).animate({'top':position+'px'})
	}
}

$().ready(function(){
	$('.player-videos-relacionados').rollerMenu({'orientation':'vertical','step':220});

	$('.carousel-panes').each(function(){
		var tmp = 0;
		$(this).find('.pane ul li').each(function(){
			tmp = tmp + $(this).getIntSize('horizontal');
		})

		fator = ($(this).find('.pane ul li').size()/4);
		if (fator < 3)
			fator = 3
		$('.pane',this).css({'width':(tmp/fator)+'px','top':'0px'});
	})

	$('.carousel-panes .slider .pane',this).css({'position':'absolute','display':'block'})

	$('.carousel-panes').rollerMenu({'orientation':'horizontal','step':135});

})

// Fim do Nu Design

$(document).ready(function(){
    // Nu Design
    $( '#header .search' ).hover( function(){
        $( this ).find( 'ul.sub' ).fadeIn( 150 );
    }, function(){
        $( this ).find( 'ul.sub' ).fadeOut( 150 );
    });
    $( '.search .sub a' ).click( function(){
        var $scope = $( this ).attr( 'scope' );
        $( '#search_scope').attr( 'value' , $scope );
        $( '.search .sub a').removeClass( 'selected' );
        $( this ).addClass( 'selected' );
        if(document.search.keyword.value!='' && document.search.keyword.value!='Type here your search'){
            document.search.submit();
        }
    });

    $('.player-videos-relacionados').rollerMenu({
        'orientation':'vertical',
        'step':220
    });
    $('.carousel-panes').each(function(){
        var tmp = 0;
        $(this).find('.pane ul li').each(function(){
            tmp = tmp + $(this).getIntSize('horizontal');
        });

        fator = parseInt(($(this).find('.pane ul li').size()/4));
        if (fator < 3)
            fator = 3
        $('.pane',this).css({
            //'width':(tmp/fator)
            'width':(tmp/4)+"px"
        });
    });

    $('.carousel-panes .slider .pane',this).css({
        'position':'absolute',
        'display':'block'
    });
    $('.carousel-panes').rollerMenu({
        'orientation':'horizontal',
        'step':135
    });
    //Fim do Nu Design


    // Placeholder Text
    $('input[type=text]').focus(function(){
        if($(this).val() == $(this).attr('defaultValue')){
            $(this).val('');
        }
    });

    $('input[type=text]').blur(function(){
        if($(this).val() == ''){
            $(this).val($(this).attr('defaultValue'));
        }
    });

    $('input[type=password]').focus(function(){
        if($(this).val() == $(this).attr('defaultValue')){
            $(this).val('');
        }
    });

    $('input[type=password]').blur(function(){
        if($(this).val() == ''){
            $(this).val($(this).attr('defaultValue'));
        }
    });

    // Menu

    $("#header .menu li").hover(
        function(){
            $(this).find(".sub").fadeIn(150);
        },
        function(){
            $(this).find(".sub").fadeOut(150);
        }
        );

    // Flags
    $("#header .flags").hover(
        function(){
            $(this).find(".sub").fadeIn(150);
        },
        function(){
            $(this).find(".sub").fadeOut(150);
        }
        );

    // Filtro
    $("#content .filtro a").click(function(){
        $(this).parent().find("a").removeClass("active");
        $(this).addClass("active");

        el = $( $(this).attr("href") );

        if( el.hasClass("resumido") ){
            el.removeClass("resumido");
        } else {
            el.addClass("resumido");
        }

        return false;
    });



    //FuncÃµes para selecionar a barra superior de thumbs de videos
    $('#tag_thumbs_recomendados').click(
        function() {
            $("#tag_thumbs_recomendados").addClass("active");
            $('#tag_thumbs_premiados').removeClass("active");
            $("#tag_thumbs_recentes").removeClass("active");
            $("#tag_thumbs_discutidos").removeClass("active");
            $("#tag_thumbs_vistos").removeClass("active");
            $("#tag_thumbs_votados").removeClass("active");
            $("#tag_thumbs_favoritos").removeClass("active");
            $("#tag_thumbs_destaques").removeClass("active");

            $("#thumbs_recomendados").show(1);
            $('#thumbs_premiados').hide(1);
            $("#thumbs_recentes").hide(1);
            $("#thumbs_discutidos").hide(1);
            $("#thumbs_vistos").hide(1);
            $("#thumbs_votados").hide(1);
            $("#thumbs_favoritos").hide(1);
            $("#thumbs_destaques").hide(1);
        });
    $('#tag_thumbs_premiados').click(
        function() {
            $("#tag_thumbs_recomendados").removeClass("active");
            $('#tag_thumbs_premiados').addClass("active");
            $("#tag_thumbs_recentes").removeClass("active");
            $("#tag_thumbs_discutidos").removeClass("active");
            $("#tag_thumbs_vistos").removeClass("active");
            $("#tag_thumbs_votados").removeClass("active");
            $("#tag_thumbs_favoritos").removeClass("active");
            $("#tag_thumbs_destaques").removeClass("active");

            $("#thumbs_recomendados").hide(1);
            $('#thumbs_premiados').show(1);
            $("#thumbs_recentes").hide(1);
            $("#thumbs_discutidos").hide(1);
            $("#thumbs_vistos").hide(1);
            $("#thumbs_votados").hide(1);
            $("#thumbs_favoritos").hide(1);
            $("#thumbs_destaques").hide(1);
        });
    $('#tag_thumbs_recentes').click(
        function() {
            $("#tag_thumbs_recomendados").removeClass("active");
            $('#tag_thumbs_premiados').removeClass("active");
            $("#tag_thumbs_recentes").addClass("active");
            $("#tag_thumbs_discutidos").removeClass("active");
            $("#tag_thumbs_vistos").removeClass("active");
            $("#tag_thumbs_votados").removeClass("active");
            $("#tag_thumbs_favoritos").removeClass("active");
            $("#tag_thumbs_destaques").removeClass("active");

            $("#thumbs_recomendados").hide(1);
            $('#thumbs_premiados').hide(1);
            $("#thumbs_recentes").show(1);
            $("#thumbs_discutidos").hide(1);
            $("#thumbs_vistos").hide(1);
            $("#thumbs_votados").hide(1);
            $("#thumbs_favoritos").hide(1);
            $("#thumbs_destaques").hide(1);
        });
    $('#tag_thumbs_discutidos').click(
        function() {
            $("#tag_thumbs_recomendados").removeClass("active");
            $('#tag_thumbs_premiados').removeClass("active");
            $("#tag_thumbs_recentes").removeClass("active");
            $("#tag_thumbs_discutidos").addClass("active");
            $("#tag_thumbs_vistos").removeClass("active");
            $("#tag_thumbs_votados").removeClass("active");
            $("#tag_thumbs_favoritos").removeClass("active");
            $("#tag_thumbs_destaques").removeClass("active");

            $("#thumbs_recomendados").hide(1);
            $('#thumbs_premiados').hide(1);
            $("#thumbs_recentes").hide(1);
            $("#thumbs_discutidos").show(1);
            $("#thumbs_vistos").hide(1);
            $("#thumbs_votados").hide(1);
            $("#thumbs_favoritos").hide(1);
            $("#thumbs_destaques").hide(1);
        });
    $('#tag_thumbs_vistos').click(
        function() {
            $("#tag_thumbs_recomendados").removeClass("active");
            $('#tag_thumbs_premiados').removeClass("active");
            $("#tag_thumbs_recentes").removeClass("active");
            $("#tag_thumbs_discutidos").removeClass("active");
            $("#tag_thumbs_vistos").addClass("active");
            $("#tag_thumbs_votados").removeClass("active");
            $("#tag_thumbs_favoritos").removeClass("active");
            $("#tag_thumbs_destaques").removeClass("active");

            $("#thumbs_recomendados").hide(1);
            $('#thumbs_premiados').hide(1);
            $("#thumbs_recentes").hide(1);
            $("#thumbs_discutidos").hide(1);
            $("#thumbs_vistos").show(1);
            $("#thumbs_votados").hide(1);
            $("#thumbs_favoritos").hide(1);
            $("#thumbs_destaques").hide(1);
        });
    $('#tag_thumbs_votados').click(
        function() {
            $("#tag_thumbs_recomendados").removeClass("active");
            $('#tag_thumbs_premiados').removeClass("active");
            $("#tag_thumbs_recentes").removeClass("active");
            $("#tag_thumbs_discutidos").removeClass("active");
            $("#tag_thumbs_vistos").removeClass("active");
            $("#tag_thumbs_votados").addClass("active");
            $("#tag_thumbs_favoritos").removeClass("active");
            $("#tag_thumbs_destaques").removeClass("active");

            $("#thumbs_recomendados").hide(1);
            $('#thumbs_premiados').hide(1);
            $("#thumbs_recentes").hide(1);
            $("#thumbs_discutidos").hide(1);
            $("#thumbs_vistos").hide(1);
            $("#thumbs_votados").show(1);
            $("#thumbs_favoritos").hide(1);
            $("#thumbs_destaques").hide(1);
        });
    $('#tag_thumbs_favoritos').click(
        function() {
            $("#tag_thumbs_recomendados").removeClass("active");
            $('#tag_thumbs_premiados').removeClass("active");
            $("#tag_thumbs_recentes").removeClass("active");
            $("#tag_thumbs_discutidos").removeClass("active");
            $("#tag_thumbs_vistos").removeClass("active");
            $("#tag_thumbs_votados").removeClass("active");
            $("#tag_thumbs_favoritos").addClass("active");
            $("#tag_thumbs_destaques").removeClass("active");

            $("#thumbs_recomendados").hide(1);
            $('#thumbs_premiados').hide(1);
            $("#thumbs_recentes").hide(1);
            $("#thumbs_discutidos").hide(1);
            $("#thumbs_vistos").hide(1);
            $("#thumbs_votados").hide(1);
            $("#thumbs_favoritos").show(1);
            $("#thumbs_destaques").hide(1);
        });
    $('#tag_thumbs_destaques').click(
        function() {
            $("#tag_thumbs_recomendados").removeClass("active");
            $('#tag_thumbs_premiados').removeClass("active");
            $("#tag_thumbs_recentes").removeClass("active");
            $("#tag_thumbs_discutidos").removeClass("active");
            $("#tag_thumbs_vistos").removeClass("active");
            $("#tag_thumbs_votados").removeClass("active");
            $("#tag_thumbs_favoritos").removeClass("active");
            $("#tag_thumbs_destaques").addClass("active");

            $("#thumbs_recomendados").hide(1);
            $('#thumbs_premiados').hide(1);
            $("#thumbs_recentes").hide(1);
            $("#thumbs_discutidos").hide(1);
            $("#thumbs_vistos").hide(1);
            $("#thumbs_votados").hide(1);
            $("#thumbs_favoritos").hide(1);
            $("#thumbs_destaques").show(1);
        });

	// start highlight box
	if( $('#videos_highlights_box').attr('id') == 'videos_highlights_box' )
		videHighlightsBox( '#videos_highlights_box' );
});

/*** HIGHLIGHT BOX ***/
var $highlights = window.setInterval( "startHighlights( '1' , '#videos_highlights_box'  );" , 5000 );
var $highlightstimeout;
var $animationSpeed = 800;

// funcao do destaque
function startHighlights( $index , $obj ) {

	if ( $index == 1 ) clearInterval( $highlights );

	var $curr = $( $obj+' .index li.active' ).index();
	
	// se nao tiver mais indices, volta para o primeiro
	if ( $( $obj+' .index li' ).eq( $curr + 1 )[0] == undefined ) {
		$curr  = 0;
		$index = 0;
	}
	
	/* logica da animacao */
	// item a ser mostrado
	var $class = $( $obj+' .index li' ).eq( $curr + 1 ).attr( 'id' );
	// se for ele mesmo que ja esta sendo mostrado, retorna falso
	if( $( $obj+' .highlights .'+$class ).css( 'display' ) != 'none' ) return false;
	// animaco para esconder o item visivel
	$( $obj+' .highlights .entry:visible' ).fadeOut( $animationSpeed ).find( '.titles div' ).stop( false , true ).animate( {marginTop : '+=50'} , $animationSpeed , function() {$( this ).css( 'margin-top' , '-50px' )});
	// animacao para mostrar o item desejado
	$( $obj+' .highlights .'+$class ).fadeIn( $animationSpeed ).find( '.titles div' ).stop( false , true ).animate( {marginTop : '+=50'} , $animationSpeed );
	// animacao do indice
	$( $obj+' .index li.active' ).stop( false , true ).animate( {backgroundColor : '#770000'} , $animationSpeed ).removeClass( 'active' );
	$( $obj+' .index li' ).eq( $curr + 1 ).css( 'background-color' ,'#ff0000' ).addClass( 'active' );
	
	$index++;

	$highlightstimeout = setTimeout( "startHighlights( "+$index+" , '"+$obj+"' )" , 5000 );

}

// core da animacao do destaque
function videHighlightsBox( $obj )
{
	// velocidade padrao das animacoes
	var $animationSpeed = 800;

	$.ajax({
		type: 'GET' ,
		url: './xml/videos.xml' , // url do xml
		dataType: 'xml' ,
		success: function( xml ) {
			
			var $intCount = 0;
			var $totIndex = Math.floor( parseInt( $( $obj+' .highlights' ).height() )/30 );

			/**
			 * Crio a caixa de destaque e populo com o xml retornado na consulta acima
			 */
			$( '<div class="highlights"></div><div class="index"><ul><li class="pause_repeat pause"></li></ul></div>' ).appendTo( $obj );
			$( xml ).find( 'entry' ).each(function(){
				
				var $totIndex = Math.floor( parseInt( $( $obj+' .highlights' ).height() )/30 )-2;
				if ( $intCount >= $totIndex ) return false;
				
				// itens do XML
        var $title 	  = $( this ).find( 'title' ).text();
        if($title.length > 35){
          $title = $title.substring(0,35)+"...";
        }
        var $subtitle = $( this ).find( 'subtitle' ).text();
        if($subtitle.length > 35){
  				$subtitle = $subtitle.substring(0,35)+"...";
        }
				var $href  	  = $( this ).find( 'link' ).attr( 'href' );
				var $target   = $( this ).find( 'link' ).attr( 'target' );
				var $image    = $( this ).find( 'image' ).attr( 'src' );

				// caixa com o link
				$( '<a href="'+$href+'" target="'+$target+'"><div class="entry entry_'+$intCount+'"></div></a>' ).appendTo( $obj+' .highlights' );

				// imagens e textos
				$( '<div class="img"><img src="'+$image+'" target="'+$target+'" /></div>' ).appendTo( $obj+' .highlights .entry_'+$intCount );
				$( '<div class="titles"><div><h2>'+$title+'</h2><h3>'+$subtitle+'</h3></div></div>' ).appendTo( $obj+' .highlights .entry_'+$intCount );

				// idice numerico
				$('<li id="entry_'+$intCount+'">'+($intCount+1)+'</li>').appendTo( $obj+' .index ul' );

				$intCount++;

			}); // close each
			
			/**
			 * Metodo para carregar todas as imagens antes de mostrar o destaque
			 * Este metodo foi criado para evitar o aparecimento "duro" da imagem
			 * Com este metodo, elas aparece suavemente
			 */
			/*
			$( $obj+' .entry img' ).each( function( i , $img ) {
				var $src = $( this ).attr( 'src' );
				var objImagePreloader = new Image();
				objImagePreloader.onload = function() {
					$( this ).attr( 'src' , $src );
					objImagePreloader.onload=function(){};
				};
				objImagePreloader.src = $src;
			});
			*/
			
			// esconde todos
			$( $obj+' .highlights .entry:not(:first)' ).hide();
			// faz animacao padrao no primeiro item da lista
			$( $obj+' .highlights .entry:first' ).fadeIn( $animationSpeed ).find( '.titles div' ).stop( false , true ).animate( {marginTop : '+=50'} , $animationSpeed );
			// ativo o primeiro indice numerico
			$( $obj+' .index li:not(.pause_repeat):first' ).css( 'background-color' ,'#ff0000' ).addClass( 'active' );
			// mostra a caixa de destaque
			$( $obj ).fadeIn( $animationSpeed );
			
			
			/**
			 * Evento click nos numeros
			 * Quando clicar, esconde o item visivel atual e mostra o item desejado
			 */
			$( $obj+' .index li:not(.pause_repeat)' ).click(
				function(){

					// pauso a animacao
					clearTimeout( $highlightstimeout );
					
					// troco o icone de pause pelo repeat
					$( $obj+' .index li.pause_repeat' ).removeClass( 'pause' ).addClass( 'repeat' );

					// item a ser mostrado
					var $class = $( this ).attr( 'id' );
					// se for ele mesmo que ja esta sendo mostrado, retorna falso
					if( $( $obj+' .highlights .'+$class ).css( 'display' ) != 'none' ) return false;
					// animaco para esconder o item visivel
					$( $obj+' .highlights .entry:visible' ).fadeOut( $animationSpeed ).find( '.titles div' ).stop( false , true ).animate( {marginTop : '+=50'} , $animationSpeed , function() {$( this ).css( 'margin-top' , '-50px' )});
					// animacao para mostrar o item desejado
					$( $obj+' .highlights .'+$class ).fadeIn( $animationSpeed ).find( '.titles div' ).stop( false , true ).animate( {marginTop : '+=50'} , $animationSpeed );
					// animacao do indice
					$( $obj+' .index li.active' ).stop( false , true ).animate( {backgroundColor : '#770000'} , $animationSpeed ).removeClass( 'active' );
					$( this ).css( 'background-color' ,'#ff0000' ).addClass( 'active' );
					
				}
			);
			
			$( $obj+' .index li.pause_repeat' ).click( function() {
				if ( $( this ).hasClass( 'repeat' ) ){
					// troco o icone de repeat pelo de pause
					$( $obj+' .index li.pause_repeat' ).removeClass( 'repeat' ).addClass( 'pause' );
					// continuo a animacao
					startHighlights( $( this ).index() , $obj );
				} else {
					// pauso a animacao
					clearTimeout( $highlightstimeout );
					// troco o icone de pause pelo repeat
					$( $obj+' .index li.pause_repeat' ).removeClass( 'pause' ).addClass( 'repeat' );
				}
			});

			/*
			 * Carrega a biblioteca jQuery UI
			 * Necessaria para a mudanca das cores dos numeros
			 */
			$.getScript( '../js/jquery.ui.js' , function() {
				
				// Evento hover nos numeros
				$( $obj+' .index li:not(.pause_repeat)' ).hover(
					function() {
						if ( $( this ).hasClass( 'active' ) ) return false;
						$( this ).stop().animate( {backgroundColor : '#ff0000'} , $animationSpeed );
					},
					function() {
						if ( $( this ).hasClass( 'active' ) ) return false;
						$( this ).stop().animate( {backgroundColor : '#770000'} , $animationSpeed );
					}
				);
				// Evento hover botao pause/repeat
				$( $obj+' .index li.pause_repeat' ).hover(
					function() {
						$( this ).stop().animate( {backgroundColor : '#000000'} , $animationSpeed );
					},
					function() {
						$( this ).stop().animate( {backgroundColor : '#555555'} , $animationSpeed );
					}
				);

			} );

		} // close success
	}); // close $.ajax
}

// textarea maxlength
// http://that-matt.com/2010/04/updated-textarea-maxlength-with-jquery-plugin/
jQuery.fn.limitMaxlength = function(options){

	var settings = jQuery.extend({
		attribute: "maxlength",
		onLimit: function(){},
		onEdit: function(){}
	}, options);

	// Event handler to limit the textarea
	var onEdit = function(){
		var textarea = jQuery(this);
		var maxlength = parseInt(textarea.attr(settings.attribute));

		if(textarea.val().length > maxlength){
			textarea.val(textarea.val().substr(0, maxlength));

			// Call the onlimit handler within the scope of the textarea
			jQuery.proxy(settings.onLimit, this)();
		}

		// Call the onEdit handler within the scope of the textarea
		jQuery.proxy(settings.onEdit, this)(maxlength - textarea.val().length);
	}

	this.each(onEdit);

	return this.keyup(onEdit)
				.keydown(onEdit)
				.focus(onEdit)
				.live('input paste', onEdit);
}

