/**
* Inicializa as funções assim que os elementos (DOM) são carregados
@author Douglas Rodrigues <douglas.rodrigues@gommo.com.br>
*/
$(document).ready(function() {
	Naturanos._init();
});

var Naturanos = {
    /**
    * Função de chamada das outras funções que inicializam o site
    * @author Douglas Rodrigues <douglas.rodrigues@gommo.com.br>
    * @modified 
    */
    _init: function() {
        try {
            Naturanos._openMenu();
            Naturanos._openAbasBusca();
            Naturanos._openMenuToggle();
            Naturanos._pngFix();
            Naturanos._flashFix();
            //Naturanos._resizeImageConteudo();
            //Naturanos._resizeImageUpload();
        } catch (e) {
            //console.log('Error: ' + e.description);
        }
    },

    /**
    * Exibe o menu dropdown
    * @author Douglas Rodrigues <douglas.rodrigues@gommo.com.br>
    * @modified 
    */
    _openMenu: function() {
        $('li.ico').live('mouseover',
			function() {
			    $('ul', this)
				.css('display', 'block')
				.parent()
				.find('a')
				.addClass('active');

			    if ($(this).parent().attr("id") == "main-menu")
			        $('ul', this).css('top', $(this).position().top + $(this).height() + 1)
			});

        $('li.ico').live('mouseout',
            function() {
                $('ul', this)
				.css('display', 'none')
				.parent()
				.find('a')
				.removeClass('active');
            }).each(function() {
                // Para resolver o problema dos selects ficarem por cima dos menus no IE6
                try {
                    $('ul', this).bgiframe();
                } catch (e) {
                }
            });
    },
    /**
    * Abas da pagina de busca
    * @author Douglas Rodrigues <douglas.rodrigues@gommo.com.br>
    * @modified 
    */
    _openAbasBusca: function() {
        $('.content_tabs').hide();
        $('.content_tabs:first').show();
        $('ul#tabs li a:first').addClass('selected');
        $('ul#tabs li a').click(function() {
            $('.content_tabs').hide();
            $('ul#tabs li a').removeClass('selected');
            $(this).addClass('selected');
            $($(this).attr('href')).show();
            return false;
        });

    },
    /**
    * Menu accordion da pagina Meu Espaço
    * @author 
    * @modified 
    */
    _openMenuToggle: function() {

        //inicia abas com a seta para baixo
        $('div.titulo').find('a').addClass('open');

        $('div.titulo').click(function() {
            if ($(this).parents('.containerTitulo').next().is(':hidden')) {
                $(this).parents('.containerTitulo').next().slideToggle('slow');
                $(this).find('a').addClass('open');
            } else {
                $(this).parents('.containerTitulo').next().slideUp('slow');
                $(this).find('a').removeClass('open');
            }
        });

    },

    /**
    * Ativa pngfix
    * @author Douglas Rodrigues <douglas.rodrigues@gommo.com.br>
    * @modified 
    */
    _pngFix: function() {
        //Apenas IE 6, se apenas um elemento MSIE for encontrado e conter o valor 6
        if (!/msie [^6]\.0/i.test(navigator.userAgent) && /msie 6\.0/i.test(navigator.userAgent)) {
            DD_belatedPNG.fix('img, .pngfix', "pngmanualfix");

            $("img.pngmanualfix").each(function() {
                imageAlphaFilter(this);
            });
        };
    },

    _flashFix: function() {
        $("object").append('<param name="wmode" value="transparent">');
        $("embed").attr("wmode", "transparent");
    }
//    ,

//    //jQuery Image Resizer - Conteudo
//    _resizeImageConteudo: function() {
//         var tempo = setTimeout(function() {
//            $('div.conteudoPost').find('img').each(function() {

//                var maxWidth = 580; // Max width for the image

//                var maxHeight = 580; // Max height for the image

//                var ratio = 0;  // Used for aspect ratio

//                var width = $(this).width();    // Current image width

//                var height = $(this).height();  // Current image height


//                // Check if the current width is larger than the max

//                if (width > maxWidth) {

//                    ratio = maxWidth / width;   // get ratio for scaling image

//                    $(this).css("width", maxWidth); // Set new width           

//                    width = width * ratio;    // Reset width to match scaled image

//                }

//                // Check if the current height is larger than the max

//                if (height > maxHeight) {

//                    ratio = maxHeight / height;   // get ratio for scaling image

//                    $(this).css("height", maxHeight); // Set new height

//                    height = height * ratio;    // Reset height to match scaled image

//                }
//            });
//        }, 1000);
//    },

//    //jQuery Image Resizer - Upload
//    _resizeImageUpload: function() {
//        var tempo = setTimeout(function() {
//            $('div.imgUpload').find('img').each(function() {

//                var maxWidth = 170; // Max width for the image

//                var maxHeight = 130; // Max height for the image

//                var ratio = 0;  // Used for aspect ratio

//                var width = $(this).width();    // Current image width

//                var height = $(this).height();  // Current image height


//                // Check if the current width is larger than the max

//                if (width > maxWidth) {

//                    ratio = maxWidth / width;   // get ratio for scaling image

//                    $(this).css("width", maxWidth); // Set new width           

//                    width = width * ratio;    // Reset width to match scaled image

//                }

//                // Check if the current height is larger than the max

//                if (height > maxHeight) {

//                    ratio = maxHeight / height;   // get ratio for scaling image

//                    $(this).css("height", maxHeight); // Set new height

//                    height = height * ratio;    // Reset height to match scaled image

//                }
//            });
//        }, 1000);
//    }

};

function imageAlphaFilter(img) {
	if (img.src.match(/.+\.png$/)) {
		url = img.src;
		width = img.clientWidth;
		height = img.clientHeight;
		img.src = "../../img/blank.gif";
		img.style.width = width + "px";
		img.style.height = height + "px";
		img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod='crop')";
	}
}


    

    
