$( document ).ready(function(){
	/*
	$( '.mnn_bandeira').click(function(){
		$( '.bg_grid' ).toggle();
	});
	*/
	$( '.bg_grid').click(function(){
		$( this ).toggle();
	});
	$( '.menu li').hover(function(){
//		$( this ).find('ul').slideDown( 350 );
		$( this ).find('ul').fadeIn(150);
	},function(){
//		$( this ).find('ul').slideUp( 250 );
		$( this ).find('ul').fadeOut(150);
	});

	$( '.editions_browser_trigger' ).hover(function(){
//		$( this ).parent().find( '.editions_browser' ).slideDown( 350 );
		$( this ).parent().find( '.editions_browser' ).fadeIn(150);
	}, function(){
//		$( this ).parent().find( '.editions_browser' ).slideUp( 250 );
		$( this ).parent().find( '.editions_browser' ).fadeOut(150);
	});
	
	$( '.show_gallery_thumb' ).click( function(){
		$dest_src = $( this ).attr( 'href' );
		$image_container = $( this ).parents( '.newsGallery' ).find( '.newsGalleryImage' );
		$image_container.find( '.loading' ).fadeIn(150);
		$image = $image_container.find( 'img' );
		$image.load( function(){
			$image_container.find( '.loading' ).fadeOut( 150 );
		});
		$image.attr( 'src' , $dest_src.replace( /\/grid_[0-9]\// , '/grid_12/' ) );
		return false;
	});
	
	$( '.form_submit' ).click( function(){ $( this ).parents( 'form' ).submit() });

	if( $( '.ck_message' ).hasClass( 'ck_message' ) )
	{
		CKEDITOR.replace( 'message' , { 
									customConfig : '../js/ckeditor_config.js',
									toolbar : 'Message',
									height: '320px',
									enterMode : 'CKEDITOR.ENTER_P',
									shiftEnterMode : 'CKEDITOR.ENTER_BR'
								 });
		
	}
	
	// CLEAN UP SEARCH FIELDS ON FOCUS
	(function($){
		$.fn.clearDefault = function(){
			return this.each(function(){
				var default_value = $(this).val();
				var original_value = $( this ).attr('original_value');
				if( original_value == default_value )
				{
					$(this).focus(function(){
						if ($(this).val() == default_value) $(this).val("");
					});
					$(this).blur(function(){
						if ($(this).val() == "") $(this).val(default_value);
					});
				}
			});
		};
	})(jQuery);
	$('input[type="text"]').clearDefault();
});

