var Email = {
	IMG: null,
    NEWS:1,
    EVENT:2,
    WORD:3,
    EXTRA:4,
    ENVIRONMENT:5,
    SYSTEM:6,
    OPPORTUNITY:7,
    POLL:8,
    CONNECT:9,
	PROF:10,
	colors:[ '' , '#243B5A' , '#FFFFFF' , '#474747' , '#8A8F29' ,
			 '#3F707F' , '#4C7636' , '#474747' , '#474747' , '#474747' , '#825c5c' ],
	color:null,
    values: [],
    content:null,
    added:{ word:false, event:false, environment:false, poll:false , connect: false , opportunity: false },

    add: function( col ){
        var $div = $("<div>"),val;
        
        if( this.content == this.NEWS ||
            this.content == this.SYSTEM ||
            this.content == this.ENVIRONMENT ||
			this.content == this.PROF ||
            this.content == this.EXTRA )
        {
            val = $( "#content-news" ).html().replace( '{content}' , this.values[this.content-1][col] );
            $div.html( val );

            $("#left").append( $div );

            $div.find("li").draggable({
                connectToSortable: '#left',
                revert: 'invalid',
                containment: 'parent'
            });

        }

        if( this.content == this.WORD ){
            val = $( "#content-word" ).html().replace( '{content}' , this.values[this.content-1][col] );
            $div.html( val );

            $("#word").append( $div );
        }

        if( this.content == this.EVENT ){

			$editBox = $("#event").find(".edit-event");

			if( $editBox[0] ){
				val = $( "#content-event-fragment" ).html().replace( '{content}' , this.values[this.content-1][col] );
				$div.html( val );
				$div.addClass("edit-box edit-event");

				$( $editBox[0] ).parent().append( $div );
			}else{
				val = $( "#content-event" ).html().replace( '{content}' , this.values[this.content-1][col] );
				$div.html( val );

				$("#event").append( $div );
			}
		}

        if( this.content == this.OPPORTUNITY ){
            val = $( "#content-opportunity" ).html().replace( '{content}' , this.values[this.content-1][col] );
            $div.html( val );

            $("#opportunity").append( $div );
        }

        if( this.content == this.POLL ){
            val = $( "#content-poll" ).html().replace( '{content}' , this.values[this.content-1][col] );
            $div.html( val );

            $("#poll").append( $div );
        }

        if( this.content == this.CONNECT ){
            val = $( "#content-connect" ).html().replace( '{content}' , this.values[this.content-1][col] );
            $div.html( val );

            $("#connect").append( $div );
        }

		
        $div.find(".button-delete").click(function(){
            $(this).parent().parent().parent().parent().remove();
        });

		$edit = $div.find(".button-edit");
		$edit.data( 'color' , this.colors[this.content] );
		$edit.attr( 'accept' , this.colors[this.content] );
        $edit.click(function(){

			Email.color = $(this).data('color');
			
			if( Email.active ){
				alert("Existe outra área em edição no momento.");
				return false;
			}

            var $main = $(this).parent().parent().parent().parent(),
                $hd = $main.find(".hd"),
                $bd = $main.find(".bd"),
                $textarea = $bd.parent().find("textarea");
                
            $textarea.val( $bd.html() );

            $bd.hide();
            $hd.find('.button-normal').hide();
            $hd.find('.button-editable').show();

			Email.active = true;

            $textarea.rte();
        });
    },

	upload: function(){
		$("#upload").show();
		$("#overlayer").show();
	},

	link: function(){
		$("#link").show();
		$("#overlayer").show();
	}
}
