$(document).ready(function(){
	//apagar campo de usuário
	$("#usr_usuario").focus(function(){
		//alert($(this).val());
		if($(this).val() == 'Usuario'){
			$(this).val('');
		}
	});
	
	//apagar campo de senha
	$("#sn_usuario").focus(function(){
		//alert($(this).val());
		if($(this).val() == 'Senha'){
			$(this).val('');
		}
		//$(this).val('');
	});
	
	$('#gallery a').lightBox();
	$('#gallery a').lightBox();
	/*Falsh não sobrepor menu*/
	//$('#conteudo embed').hide();
	$('#conteudo embed').attr('wmode','transparent');
	$('#conteudo object').append('<param name="wmode" value="transparent" />');
	//$('embed').attr("wmode","transparent");

	/*
		PARA TRATAR EDITORES DO PRODUTO
	*/
	
	// ### DESCRICAO ###
	//$('#ds_conteudo').hide();
	$('#save_ds').hide();

	$('#ins_ds').click(function(){
		createEditor('ds');
	});
	
	$('#save_ds').click(function(){
		removeEditor('ds');		
	});
	//##################
	
	
	// ### ESPECIFICACOES ###
	//$('#ds_conteudo').hide();
	$('#save_esp').hide();

	$('#ins_esp').click(function(){
		createEditor('esp');
	});
	
	$('#save_esp').click(function(){
		removeEditor('esp');		
	});
	//##################
	
	// ### CARACTERÍSTICAS ###
	//$('#ds_conteudo').hide();
	$('#save_carac').hide();

	$('#ins_carac').click(function(){
		createEditor('carac');
	});
	
	$('#save_carac').click(function(){
		removeEditor('carac');		
	});
	//##################
	
	
	// ### FORNECIMENTO ###
	//$('#ds_conteudo').hide();
	$('#save_forn').hide();

	$('#ins_forn').click(function(){
		createEditor('forn');
	});
	
	$('#save_forn').click(function(){
		removeEditor('forn');		
	});
	//##################
	
	// ### PROTEÇÃO ###
	//$('#ds_conteudo').hide();
	$('#save_prot').hide();

	$('#ins_prot').click(function(){
		createEditor('prot');
	});
	
	$('#save_prot').click(function(){
		removeEditor('prot');		
	});
	//##################
	
	// ### ACESSORIOS###
	//$('#ds_conteudo').hide();
	$('#save_aces').hide();

	$('#ins_aces').click(function(){
		createEditor('aces');
	});
	
	$('#save_aces').click(function(){
		removeEditor('aces');		
	});
	//##################
	
	// ### TESTES ###
	//$('#ds_conteudo').hide();
	$('#save_testes').hide();

	$('#ins_testes').click(function(){
		createEditor('testes');
	});
	
	$('#save_testes').click(function(){
		removeEditor('testes');		
	});
	//##################
	
	// ### REFERÊCIAS ###
	//$('#ds_conteudo').hide();
	$('#save_ref').hide();

	$('#ins_ref').click(function(){
		createEditor('ref');
	});
	
	$('#save_ref').click(function(){
		removeEditor('ref');		
	});
	//##################
	
	// ### OPCIONAIS ###
	//$('#ds_conteudo').hide();
	$('#save_op').hide();

	$('#ins_op').click(function(){
		createEditor('op');
	});
	
	$('#save_op').click(function(){
		removeEditor('op');		
	});
	//##################
	
	// ### CONFIGURAÇÕES ###
	//$('#ds_conteudo').hide();
	$('#save_conf').hide();

	$('#ins_conf').click(function(){
		createEditor('conf');
	});
	
	$('#save_conf').click(function(){
		removeEditor('conf');		
	});
	//##################
	
	// ### NORMAS ###
	//$('#ds_conteudo').hide();
	$('#save_norm').hide();

	$('#ins_norm').click(function(){
		createEditor('norm');
	});
	
	$('#save_norm').click(function(){
		removeEditor('norm');		
	});
	//##################
		
	
});//.ready
var editor;
/*
FUNÇÕES PARA CRIAR E 'SALVAR' OSCONTEÚDOS
*/
function createEditor(tp){
	if ( editor )
		return;

	var html = $('#'+tp+'_edit_conteudo').html();

	// Create a new editor inside the <div id="editor">
	editor = CKEDITOR.appendTo( 'editor_'+tp );
	editor.setData( html );
	$('#save_'+tp+'').show();
}

function removeEditor(tp){
	if ( !editor )
		return;

	// Retrieve the editor contents. In an Ajax application, this data would be
	// sent to the server or used in any other way.
	//document.getElementById( 'editorcontents' ).innerHTML = editor.getData();
	//alert(tp);
	//alert(editor.getData());
	
	$('#'+tp+'_edit_conteudo').html(editor.getData());
	$('#'+tp+'_conteudo').fadeIn();
	
	//$('#'+tp+'_conteudo').style('display','');
	//document.getElementById( 'contents' ).style.display = '';
	//document.getElementById( 'teste' ).value= editor.getData();
	$('#'+tp+'_hidden').val(editor.getData());
	$('#save_'+tp+'').hide();

	// Destroy the editor.
	editor.destroy();
	editor = null;
}



/*
	FIM DAS FUNCS CRIAR E SALVAR
*/
/*
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/

// This file is not required by CKEditor and may be safely ignored.
// It is just a helper file that displays a red message about browser compatibility
// at the top of the samples (if incompatible browser is detected).

// Firebug has been presented some bugs with console. It must be "initialized"
// before the page load to work.
// FIXME: Remove the following in the future, if Firebug gets fixed.
if ( typeof console != 'undefined' )
	console.log();


if ( window.CKEDITOR )
{
	(function()
	{
		var showCompatibilityMsg = function()
		{
			var env = CKEDITOR.env;

			var html = '<p><strong>Your browser is not compatible with CKEditor.</strong>';

			var browsers =
			{
				gecko : 'Firefox 2.0',
				ie : 'Internet Explorer 6.0',
				opera : 'Opera 9.5',
				webkit : 'Safari 3.0'
			};

			var alsoBrowsers = '';

			for ( var key in env )
			{
				if ( browsers[ key ] )
				{
					if ( env[key] )
						html += ' CKEditor is compatible with ' + browsers[ key ] + ' or higher.';
					else
						alsoBrowsers += browsers[ key ] + '+, ';
				}
			}

			alsoBrowsers = alsoBrowsers.replace( /\+,([^,]+), $/, '+ and $1' );

			html += ' It is also compatible with ' + alsoBrowsers + '.';

			html += '</p><p>With non compatible browsers, you should still be able to see and edit the contents (HTML) in a plain text field.</p>';

			document.getElementById( 'alerts' ).innerHTML = html;
		};

		var onload = function()
		{
			// Show a friendly compatibility message as soon as the page is loaded,
			// for those browsers that are not compatible with CKEditor.
			if ( !CKEDITOR.env.isCompatible )
				showCompatibilityMsg();
		};

		// Register the onload listener.
		if ( window.addEventListener )
			window.addEventListener( 'load', onload, false );
		else if ( window.attachEvent )
			window.attachEvent( 'onload', onload );
	})();
}
