function abreEstado( uf )
{
	window.location = "/estados/" + uf.toLowerCase() + ".aspx" ;
}

$( function general()
{
	
	
	if( $.browser.msie && $.browser.version == 6 )
	{
		var theImg = $( "div.theImg > div" );
		
		$( "body" ).addClass( "ie6" );
		
		$( "ul.menuHome li a" ).addClass( "png24" );
		
		DD_belatedPNG.fix( '.png24' );
		
		theImg.css( "width", theImg.siblings( "img" ).width() + 6 );
		
	}

	if( $.browser.msie && $.browser.version < 8 )
	{
		
		// Top Right - 45px / Bottom Left - 25px
		DD_roundies.addRule( "div.sidebar", "0px 45px 0px 25px");
		
		// Top Right, Bottom Left - 10px
		DD_roundies.addRule( ".borderModel_trbl, div.informations, div.searchBox, div.sidebar span.inputText", "0px 10px 0px 10px");
		
		// Top Left, Bottom Right - 10px
		DD_roundies.addRule( ".borderModel_tlbr, div.newsList, div.linksExtras ul li, .overview img", "10px 0px 10px 0px");
		
		// Top Left - 10px
		DD_roundies.addRule( ".borderModel_tl", "10px 0px 0px 0px");

		// Bottom Right - 10px
		$( "ul.defaultList li:last:not('bright')" ).addClass( "borderModel_br" );
		DD_roundies.addRule( ".borderModel_br", "0px 0px 10px 0px");
		
		// Modal - Texto Foto grande - Top Left, Bottom Right - 35px
		DD_roundies.addRule( ".borderModelModal_tlbr", "35px 0px 35px 0px");

	} else
	{
		
		// Top Right - 45px / Bottom Left - 25px
		$( "div.sidebar" ).corner( "tr 45px" ).corner( "bl 25px" );
		
		// Top Right, Bottom Left - 10px
		$( ".borderModel_trbl, div.informations, div.searchBox, div.sidebar span.inputText" ).corner( "tr bl 10px" );
		
		// Top Left, Bottom Right - 10px
		$( ".borderModel_tlbr, div.newsList, div.linksExtras ul li, .overview img" ).corner( "tl br 10px" );
		
		// Top Left - 10px
		$( ".borderModel_tl" ).corner( "tl 10px" );

		// Bottom Right - 10px
		$( "ul.defaultList li:last:not('bright')" ).addClass( "borderModel_br" );
		$( ".borderModel_br" ).corner( "br 10px" );

		// Modal - Texto Foto grande - Top Left, Bottom Right - 35px
		$( ".borderModelModal_tlbr" ).corner( "tl br 35px" );
		
		// Top Left, Bottom Right - 6px
		!$.browser.msie
			&& $( "div.pagination ul li.active" ).corner( "tl br 6px" );
	}
	
	$.browser.safari
		&& $( "body" ).addClass( "safari" );
	$.browser.msie
		&& $( "body" ).addClass( "msie" );
	$.browser.opera
		&& $( "body" ).addClass( "opera" );
	
	// Adiciona class Last nas divs de Notícias
	$( "li:last", $( "div.newsList ul, div.pageNews ul, div.pageNews ul.cImage" ) ).addClass( "last" );
	
	$( "a.bt_modal" ).click( function()
	{
		$.ajax(
		{
			url: this.href,
			success: function( response )
			{
				var modal = $( response ).appendTo( "body" ),
					galeria = $( "div.galeria ", modal ),
					placeHolder = $( "div.fotoGrande", modal ),
					scrollElement = $( "div.fotos", galeria ),
					first = $( "li:first div a", scrollElement ),
					//firstDescription = first.parents( "li" ).find( "p > a " ).text();
					firstDescription = first.parents( "li" ).find( "p.desc" ).text(),
					showVideo = function( url )
					{
						//alert('test');
						$( "img", placeHolder ).remove();
						swfobject.embedSWF("../_global/swf/mediaPlayer.swf?" + new Date().getTime(), "replaceFlash", "518", "262", "9.0.0", "", 
							{
								url: url
							},
							{
				            	menu: "false",
				                scale: "noscale",
								wmode: 'transparent'
				            },
							{
								salign: 't',
								wmode: 'transparent'
				            }
						);
						$( "#replaceFlash", placeHolder ).show();
					},
					showImage = function( url, description )
					{
						$( "#replaceFlash", placeHolder ).empty().hide();
						
						$( "<img />" )
							.appendTo( placeHolder)
							.attr( "src", url )
							.attr( "alt", description )
							.show();
					},
					descriptionHolder = $( "div.txt", modal ),
					changeDescription = function( description )
					{
						$( "p", descriptionHolder ).html( description );
					};
				
				changeDescription( firstDescription );
					
				first.is( ".bt_play" )
					? showVideo( first[ 0 ].href )
					: showImage( first[ 0 ].href, firstDescription )
				
				scrollElement.scrollAnimate(
				{
					buttonLT: $( ".bt_avancar", galeria ),
					buttonRB: $( ".bt_voltar", galeria ),
					itemSize: 156,
					velocity: 500
				});
				
				$( "li div a", scrollElement ).click( function()
				{
					var $this = $( this ),
						description = $this.parents( "li" ).find( "p" ).text();
					
					$this.is( ".bt_play" )
						? showVideo( this.href )
						: showImage( this.href, description )
					
					changeDescription( $this.parents( "li" ).find( "p" ).text() );
					return false;
				});
				
				modal.modal();
			}
		});
		
		return false;
	});	
	
	$( "ul.detailedInformations li h4" )
		.click( function()
		{
			var actual = $( this ).parent(),
				content = $( "div", actual );

			content.slideToggle( function()
			{
				actual.toggleClass( "active" )
			});

			actual
				.siblings( ".active" )
					.removeClass( "active" )
					.find( "div" ).slideUp();
		
			return false;
		})
		.bind( "mouseover mouseout", function( e )
		{
			$( this ).toggleClass( "hover" );
		});
		
	// SElECTS
	( function()
	{
		var selects = $( "div.searchBox" );
		
		$( "> a", selects ).click( function()
		{
			var $this = $( this );
			
			$this.siblings( "div" ).slideToggle();
			return false;
		});
		
		$( "div a", selects ).click( function()
		{
			var $this = $( this ),
				parent = $this.parent().parent().parent();
			
			parent
				.slideUp()
				.siblings( "a" ).text( $this.text() ).end()
				.next( "input" ).val( $this.attr( "value" ) );
				//.siblings( "a" ).text( $this.attr({"href":$this.attr( "value" )}) ).end()
				//.next( "input" ).val( $this.attr( "value" ) );
			
			//return false;
		})
		
		/*
		selects.bind( "mouseover mouseout", function( e )
		{
			var $this = $( this ),
				time;
			
			if( e.originalEvent.type == "mouseout" )
			{
				time = setTimeout( function()
				{
					$( "div", $this ).slideUp();
				}, 1000 )
			}
			else
			{
				clearTimeout( time );
			}
		});*/
	})();
	
	// Home
	if( $( "body.home" ).length )
	{
		
		var bt = $( "ul.menuHome li.about a:first" );
		
		// Menu DropDown
		bt.click( function()
		{
            var $this = $(this),
				div = $this.siblings( "div:first" ),
				estaOculto = div.is( ":hidden" );

            //bt.next( "div" ).hide();

            div.toggle();
            bt.parent().toggleClass( "active" );
            
			return false;
        });

        $( document.body ).click( function( e )
		{
            ( !$( e.target ).is( "ul.menuHome li.about div" ) || $( e.target ).is( "#general" ) )
				&& $( "ul.menuHome li.about div:visible" ).hide()
				&& bt.parent().removeClass( "active" );
        });
		
		
		
		
		// Frutas de fundo
		swfobject.embedSWF( "../_global/swf/bg_home_Header_spanBgFruit.swf", "replace_fruitFundo", "444", "313", "9.0.0", "", "",
			{
            	menu: "false",
                scale: "noscale",
				wmode: 'transparent'
            },
			{
				salign: 't',
				wmode: 'transparent'
            }
		);
		
		/* Família
		swfobject.embedSWF( "../_global/swf/bg_home_header_spanFamily.swf", "replace_family", "302", "411", "9.0.0", "", "",
			{
            	menu: "false",
                scale: "noscale",
				wmode: 'transparent'
            },
			{
				salign: 't',
				wmode: 'transparent'
            }
		);*/
		
		/* Legumes
		swfobject.embedSWF( "../_global/swf/bg_home_header_spanLegumes.swf", "replace_legumes", "1042", "244", "9.0.0", "",
			{
				url: ''
			},
			{
            	menu: "false",
                scale: "noscale",
				wmode: 'transparent'
            },
			{
				salign: 't',
				wmode: 'transparent'
            }
		);*/
		
		// Vídeo
		swfobject.embedSWF("../_global/swf/mediaPlayer.swf?" + new Date().getTime(), "replaceFlashHome", "350", "190", "9.0.0", "", 
			{
				url: '/media/5403/organicos.flv',
				home: 'true'
			},
			{
            	menu: "false",
                scale: "noscale",
				wmode: 'transparent'
            },
			{
				salign: 't',
				wmode: 'transparent'
            }
		);
		
		// mapa
		swfobject.embedSWF("../_global/swf/mapaEstados.swf?" + new Date().getTime(), "replace_mapFlash", "275", "260", "9.0.0", "",
			{
				call: "abreEstado"
			},		
			{
            	menu: "false",
                scale: "noscale",
				wmode: 'transparent'
            },
			{
				salign: 't',
				wmode: 'transparent'
            }
		);

	}
	
	$('select#selectGovernment').change(function(){
		var $this = $(this);
		if($this.val() != ""){
			window.open($this.val(),'window','toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,menubar=yes,resizable=yes');
		}
		$this[0].selectedIndex = 0;
	});
	
});