function gete(id){return document.getElementById(id);}

function menu(indice){

	podeMarcarAtual = false;
	
	if(gete('m'+indice).className == 'esq esqP')gete('m'+indice).className = 'esq2 esqP2';
	else if(gete('m'+indice).className == 'esq')gete('m'+indice).className = 'esq2';

	gete('sm'+indice).className = "subMenu db";
	desabMenus(indice);
}

function desabMenus(indice){

    try{
	    if(indice != 1)gete('m1').className = "esq esqP";
	    if(indice != 2)gete('m2').className = "esq";
	    if(indice != 3)gete('m3').className = "esq";
	    if(indice != 4)gete('m4').className = "esq";
	    if(indice != 5)gete('m5').className = "esq";
	    if(indice != 6)gete('m6').className = "esq";

	    if(indice != 1)gete('sm1').className = "subMenu";
	    if(indice != 2)gete('sm2').className = "subMenu";
	    if(indice != 3)gete('sm3').className = "subMenu";
	    if(indice != 4)gete('sm4').className = "subMenu";
	    if(indice != 5)gete('sm5').className = "subMenu";
	    if(indice != 6)gete('sm6').className = "subMenu";

	}catch(e){}
}
var menuAtual = 0;
var podeMarcarAtual = true;
function marcaAtual(){
    if(podeMarcarAtual){
	    menu(menuAtual);
	}
}

$(document).ready(function(){
    //Coloca hover nos botões
    overBtn();
    
    //Posicionando o rodape
    $("body").attr('onload','changeHeightSite()');
    $(window).resize(function(){changeHeightSite();});
    
    $("#divMenu2").bind("mouseleave", function(){window.setTimeout('marcaAtual()',500);podeMarcarAtual = true;});
    $("#divMenu2").bind("mouseover", function(){podeMarcarAtual = false;});
    
    if(menuAtual == 0){menuAtual = 1;}
    menu(menuAtual);
});


//Menu interno de BMG Institucional
function menuInter(indice){
	if(gete('mi'+indice).className == 'esq esqP')gete('mi'+indice).className = 'esq2 esqP2';
	else if(gete('mi'+indice).className == 'esq')gete('mi'+indice).className = 'esq2';
	
	desabMenusInter(indice);
	showBlockInter(indice);
}
function showBlockInter(indice) {
    
    gete('bm1').className = "blockInterMenu";
    gete('bm2').className = "blockInterMenu";
    gete('bm3').className = "blockInterMenu";
    gete('bm4').className = "blockInterMenu";
    gete('bm5').className = "blockInterMenu";
    
    gete('bm'+indice).className = "blockInterMenu db";
}
function desabMenusInter(indice){
	if(indice != 1)gete('mi1').className = "esq esqP";
	if(indice != 2)gete('mi2').className = "esq";
	if(indice != 3)gete('mi3').className = "esq";
	if(indice != 4)gete('mi4').className = "esq";
	if(indice != 5)gete('mi5').className = "esq";
}


// Detect Browser
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function overBtn(){
    var r = /(.*)\.(.+)$/;

    $("img.btnOver").mouseover(function(){
        var s = this.src.match(r);
        this.src = this.src.replace("."+s[2],"_off."+s[2])});    
    $("img.btnOver").mouseout(function(){
        var s = this.src.match(r);
        this.src = this.src.replace("_off."+s[2],"."+s[2])});    
}

//Funções para inserção de SWF nas páginas
function swfTitulo(texto, font_size, width, height, id){

    var flashvars = {
	    title: texto,
	    size: font_size,
	    width: width,
	    border:false
    };
    var params = {
    allowFullScreen:"true",
    wmode: "transparent"
    }

	swfobject.embedSWF("swf/title.swf", id, width, height, "8.0.0","",flashvars,params);

}

function getPageSize(){
  	var xScroll, yScroll;

  	if (window.innerHeight && window.scrollMaxY) {	
  		xScroll = document.body.scrollWidth;
  		yScroll = window.innerHeight + window.scrollMaxY;
  	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
  		xScroll = document.body.scrollWidth;
  		yScroll = document.body.scrollHeight;
  	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
  		xScroll = document.body.offsetWidth;
  		yScroll = document.body.offsetHeight;
  	}

  	var windowWidth, windowHeight;

  	if (self.innerHeight) {	// all except Explorer
  		windowWidth = self.innerWidth;
  		windowHeight = self.innerHeight;
  	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
  		windowWidth = document.documentElement.clientWidth;
  		windowHeight = document.documentElement.clientHeight;
  	} else if (document.body) { // other Explorers
  		windowWidth = document.body.clientWidth;
  		windowHeight = document.body.clientHeight;
  	}	
  	var pageHeight, pageWidth;

  	// for small pages with total height less then height of the viewport
  	if(yScroll < windowHeight){
  		pageHeight = windowHeight;
  	} else { 
  		pageHeight = yScroll;
  	}

  	// for small pages with total width less then width of the viewport
  	if(xScroll < windowWidth){	
  		pageWidth = windowWidth;
  	} else {
  		pageWidth = xScroll;
  	}

  	return {
  		pageWidth: pageWidth ,
  		pageHeight: pageHeight , 
  		windowWidth: windowWidth, 
  		windowHeight: windowHeight
  	};
}

function changeHeightSite(){
			
	var heightTopo = 116;
	var heightRodape = 28;
	var size = getPageSize();
	var height = size.windowHeight - heightTopo - heightRodape;

	if($('#corpo').outerHeight() != null){
		if($('#corpo').outerHeight() < height){
			$('#corpo').css("height",height+"px");
		}
	}
}

function closeMesg(obj){
    try{
        $(obj.parentNode).hide();
    }catch(e){}
}
