window.addEvent('domready', function() {

	// Accordion Content
	if ($('accordion')) {
		var accordion = new Accordion('h3.atStart', 'div.atStart', {
			opacity: false,
			display: -1,
			alwaysHide: true,
			onActive: function(toggler, element){
				toggler.setStyle('font-weight', 'bold');
				toggler.setStyle('color', '#fff');
				toggler.setStyle('background-position', '0 -50px');
			},
		 
			onBackground: function(toggler, element){
				toggler.setStyle('font-weight', 'normal');
				toggler.setStyle('color', '#000');
				toggler.setStyle('background-position', '0 0');
			}
		}, $('accordion'));
	}
	
	if ($('accordion_documentos')) {
		var accordion = new Accordion('h3.atStart', 'div.atStart', {
			opacity: false,
			display: 0,
			alwaysHide: true,
			onActive: function(toggler, element){
				toggler.setStyle('font-weight', 'bold');
				toggler.setStyle('color', '#fff');
				toggler.setStyle('background-position', '0 -50px');
			},
		 
			onBackground: function(toggler, element){
				toggler.setStyle('font-weight', 'normal');
				toggler.setStyle('color', '#000');
				toggler.setStyle('background-position', '0 0');
			}
		}, $('accordion_documentos'));
	}
	
	if ($('accordion_arquivos')) {
		var accordion = new Accordion('h3.atStart', 'div.atStart', {
			opacity: false,
			display: 1,
			alwaysHide: true,
			onActive: function(toggler, element){
				toggler.setStyle('font-weight', 'bold');
				toggler.setStyle('color', '#fff');
				toggler.setStyle('background-position', '0 -50px');
			},
		 
			onBackground: function(toggler, element){
				toggler.setStyle('font-weight', 'normal');
				toggler.setStyle('color', '#000');
				toggler.setStyle('background-position', '0 0');
			}
		}, $('accordion_processos'));
	}
	
	if ($('accordion_processos')) {
		var accordion = new Accordion('h3.atStart', 'div.atStart', {
			opacity: false,
			display: 2,
			alwaysHide: true,
			onActive: function(toggler, element){
				toggler.setStyle('font-weight', 'bold');
				toggler.setStyle('color', '#fff');
				toggler.setStyle('background-position', '0 -50px');
			},
		 
			onBackground: function(toggler, element){
				toggler.setStyle('font-weight', 'normal');
				toggler.setStyle('color', '#000');
				toggler.setStyle('background-position', '0 0');
			}
		}, $('accordion_processos'));
	}
	
	
	// Slideshow
	if ($('slides_destaques')) {
		var destaque_SlideShow;
		
		destaque_SlideShow = new SlideShow('slides_destaques',{
			delay: 8000,
			autoplay: true
		});
	
		$('bt_avancar').addEvent('click',function(){
			destaque_SlideShow.showNext();
			destaque_SlideShow.pause();
			destaque_SlideShow.play();
		});
	
		$('bt_voltar').addEvent('click',function(){
			destaque_SlideShow.showPrevious();
			destaque_SlideShow.pause();
			destaque_SlideShow.play();
		});
	}
	
	if ($('slides_mercados')) {
		var mercados_SlideShow;
		
		mercados_SlideShow = new SlideShow('slides_mercados',{
			delay: 4000,
			autoplay: true
		});
		
	}

});

// pop ajax swf
function loadSWF(url,targetID){
	//Check for existing SWF
	if(isObject(targetID)){
		//replace object/element with a new div
		replaceSwfWithEmptyDiv(targetID);
	}
	
	//Embed SWF
	if (swfobject.hasFlashPlayerVersion("8")) {
		var attributes = { data: url, width:"100%", height:"100%" };
		var params = { wmode:"transparent", menu:"false", quality:"high" };
		var obj = swfobject.createSWF(attributes, params, targetID);
	}
	
	//Show div
	document.getElementById("pop").style.display="block";void(0);

}

function isObject(targetID){
	var isFound = false;
	var el = document.getElementById(targetID);
	if(el && (el.nodeName === "OBJECT" || el.nodeName === "EMBED")){
		isFound = true;
	}
	return isFound;
}

function replaceSwfWithEmptyDiv(targetID){
	var el = document.getElementById(targetID);
	if(el){
		var div = document.createElement("div");
		el.parentNode.insertBefore(div, el);
		//Remove the SWF
		swfobject.removeSWF(targetID);
		//Give the new DIV the old element's ID
		div.setAttribute("id", targetID);
	};
};


//abre janela nova
function popUp(theURL,winName,w,h,scroll){	
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	features = "height="+h+",width="+w+",top="+TopPosition+",left="+LeftPosition+",scrollbars="+scroll+",status=yes";
	janela=window.open(theURL,winName,features);
	janela.focus();
};