$(document).ready(function(){


    /*********************INICIA MODERNIZR*********************/
   /* Modernizr.load({
        load: 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js',
        if(!window.jQuery){
            load: 'js/jquery/jquery.js';
        }
        test: Modernizr.borderradius,
        nope: ['js/modernizr/border-radius.js', 'js/modernizr/polyfill-border-radius.js']
    });*/
    /*********************ENCERRA MODERNIZR********************/


	parseFormNoLabels( 'BuscaTopo' );
	parseFormNoLabels( 'BuscaRodape' );


	var target = $('.picturesToEnlarge a');
	if( target && target.lightBox ) target.lightBox();

	var target = $('a.picturesToEnlarge');
	if( target && target.lightBox ) target.lightBox();

	// h1
	var flashContainer = $('<div></div>').prependTo( '#topo h1' );
	flashContainer.flash(
		{
		src: './swf/logo.swf',
		width: 177,
		height: 138,
		wmode: 'transparent'
		}
	);

	$('<style media="screen"> body #topo h1 a { display: none; } </style>').appendTo('head');

	// slogan rodape
	$('#slogan').html('');
	$('#slogan').flash(
		{
		src: './swf/slogan.swf',
		width: 936,
		height: 56,
		wmode: 'transparent'
		}
	);

	var interatividade = $('#interatividade ul');
	if( interatividade.length ) {
		interatividade.append( '<li class="favoritos"><a href="javascript:addFav()" title="Adicionar aos Favoritos">Adicionar aos Favoritos</a></li>');
	}

	var produtos = $('#carrinho div.produtos');
	if( produtos.length )
	{
		var CarrinhoStatus = 0; // 0:parado;	1:descendo	2:subindo

		$('#carrinho a.itens').bind( 'mouseenter', function(e) {
			if( CarrinhoStatus==1 ) return;
			CarrinhoStatus=1;
			$('#carrinho div.produtos').stop(true, true).slideDown( 'fast' );
		} );

		$('#carrinho').bind( 'mouseleave', function(e) {
			if( !CarrinhoStatus==2 ) return;
			CarrinhoStatus=2;
			$('#carrinho div.produtos').slideUp( 'fast' );
		} );
	}

	// produtos clicaveis
	$('#conteudo ul.produtos li[class!=quebra], #conteudoInterno ul.produtos li[class!=quebra]').each(
		function( ) {
			var li = $(this);
			var link = li.find('a.nome').attr( 'href' );
			li.click( function() { location.href = link; });
			li.css( 'cursor', 'pointer' );
			li.hover(
				function() { $(this).addClass( 'hover' ); },
				function() { $(this).removeClass( 'hover' ); } );
			/*li.hover(
				function()
			);*/
		}
	);



	if( $('#disclaimer').length ) {

		$('html, body').css( {
			/*'background':'#000',*/
			'height': '100%'
		});

		$('body').addClass('disclaimer');

		//$('#disclaimer').before( '<div id="holder"></div>');
		$('#holder').css(
			{
				'height': $('body').height() +'px',
				'opacity': 0.9
			}
		);

		return;
	}


});



var parseFormNoLabels = function( $tgt )
{
	$( '#' + $tgt ).addClass('parsed');
	jQuery.each( $( '#' + $tgt + ' label' ), function()
	{
		$d = this.innerHTML.replace(/:?(<([^>]+)>)/ig,"");
		var $inputTgt = $( 'input#'+ this.attributes['for'].value );

		if( $inputTgt.length==0 ) return;

		$inputTgt[0].originalValue = $d;
		if( $inputTgt[0].value=='' ) $inputTgt[0].value = $d;

		$inputTgt.bind("focus", function(e){ if(this.value==this.originalValue) this.value=''; });
		$inputTgt.bind("blur", function(e){ if(this.value=='') this.value=this.originalValue; });

		this.style.display = 'none';
	});
	$( '#' + $tgt ).submit(
		function() {
			$( '#' + $tgt + ' label' ).each(
				function(){
					var el = $( 'input#'+ $(this).attr( 'for' ) )[0];
					if( el ) {
						if( el.value==el.originalValue ) el.value = '';
					}
				});
		}
	);

}


function addFav(){
    var url      = location;
    var title    = document.title;
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}
