$(document).ready(function(){
		
	jQuery.preloadImages = function() 
	{   
		for(var i = 0; i<arguments.length; i++)   
		{
			  jQuery("<img>").attr("src", arguments[i]);   
		}
	}	
	
	$.preloadImages("http://fundive.n2it.com.br/uploads/fundive/bg_login.png", "http://fundive.n2it.com.br/uploads/fundive/submenuBack.png");
		
	$(".btn-slide").click(function()
    {
		$("#panel").slideToggle("slow");
		$(this).toggleClass("active"); return false;
	});

	$(".menu7").parent().hover(
		function(){
			$(".submenu7").fadeIn(100);
			$(".menu7").css("background-position","0 -12px");
			$(".menu7").parent().css("cursor","pointer");
		}, 
		function(){
			$(".submenu7").fadeOut(400);
			$(".menu7").css("background-position","0 0px");
			$(".menu7").parent().css("cursor","default");
		}
	);
	
	$(".menu4").parent().hover(
		function(){
			$(".submenu4").fadeIn(100);
			$(".menu4").css("background-position","0 -12px");
			$(".menu4").parent().css("cursor","pointer");
		}, 
		function(){
			$(".submenu4").fadeOut(400);
			$(".menu4").css("background-position","0 0px");
			$(".menu4").parent().css("cursor","default");
		}
	);
	
	$(".menu3").parent().hover(
		function(){
			$(".submenu3").fadeIn(100);
			$(".menu3").css("background-position","0 -12px");
			$(".menu3").parent().css("cursor","pointer");
		}, 
		function(){
			$(".submenu3").fadeOut(400);
			$(".menu3").css("background-position","0 0px");
			$(".menu3").parent().css("cursor","default");
		}
	);
	
	$(".menu2").parent().hover(
		function(){
			$(".submenu2").fadeIn(100);
			$(".menu2").css("background-position","0 -12px");
			$(".menu2").parent().css("cursor","pointer");
		}, 
		function(){
			$(".submenu2").fadeOut(400);
			$(".menu2").css("background-position","0 0px");
			$(".menu2").parent().css("cursor","default"); 
		}
	);
	
	//$("table.cab_table tr:even").addClass("oddrow");
	
	$('[name|="m0bec9input_certificadora[]"]').attr('class','selectCertificadora').attr('id','selectCertificadora');
	$('[name|="m0bec9input_tipoprofissioinal[]"]').attr('class','selectTipoProfissioinal').attr('id','selectTipoProfissioinal');
	$('[name|="m0bec9input_gostariademelhorar[]"]').attr('class','selectGostariaMelhorar').attr('id','selectGostariaMelhorar');
	$('[name|="m0bec9input_gostariamelhorarfundive[]"]').attr('class','selectGostariaMelhorarFundive').attr('id','selectGostariaMelhorarFundive');
	
	$('[name|="cntnt01feu_input_certificadora[]"]').attr('class','selectCertificadora').attr('id','selectCertificadora');
	$('[name|="cntnt01feu_input_tipoprofissioinal[]"]').attr('class','selectTipoProfissioinal').attr('id','selectTipoProfissioinal');
	$('[name|="cntnt01feu_input_gostariademelhorar[]"]').attr('class','selectGostariaMelhorar').attr('id','selectGostariaMelhorar');
	$('[name|="cntnt01feu_input_gostariamelhorarfundive[]"]').attr('class','selectGostariaMelhorarFundive').attr('id','selectGostariaMelhorarFundive');
	
	$('#m0bec9input_profissional1').live('click', function()
	{ 
		$('.selectTipoProfissioinal').closest('tr').show();
	});
	
	$('#m0bec9input_profissional2').live('click', function()
	{ 
		$('.selectTipoProfissioinal').closest('tr').hide();
	});
	
	$('#m0bec9input_mergulha1').live('click', function()
	{ 
		$('[name|="m0bec9input_snorkeling"]').closest('tr').show();
		$('[name|="m0bec9input_apneia"]').closest('tr').show();
		$('[name|="m0bec9input_cacasub"]').closest('tr').show();
		$('[name|="m0bec9input_scuba"]').closest('tr').show();
		$('[name|="m0bec9input_certificadora[]"]').closest('tr').show();
		$('[name|="m0bec9input_certificadoraoutros"]').closest('tr').show();
		$('[name|="m0bec9input_profissional"]').closest('tr').show();
		$('[name|="m0bec9input_tipoprofissioinal[]"]').closest('tr').show();
		$('[name|="m0bec9input_quantosmergulhos"]').closest('tr').show();
	});
	
	$('#m0bec9input_mergulha2').live('click', function()
	{ 
		$('[name|="m0bec9input_snorkeling"]').closest('tr').hide();
		$('[name|="m0bec9input_apneia"]').closest('tr').hide();
		$('[name|="m0bec9input_cacasub"]').closest('tr').hide();
		$('[name|="m0bec9input_scuba"]').closest('tr').hide();
		$('[name|="m0bec9input_certificadora[]"]').closest('tr').hide();
		$('[name|="m0bec9input_certificadoraoutros"]').closest('tr').hide();
		$('[name|="m0bec9input_profissional"]').closest('tr').hide();
		$('[name|="m0bec9input_tipoprofissioinal[]"]').closest('tr').hide();
		$('[name|="m0bec9input_quantosmergulhos"]').closest('tr').hide();	
	});
});


// Variables we need
var previous	= new Array();
var lastClicked = '';

// We are going to attach event listeners, no code at the bottom or anything hard coded...
function addEvent(obj, evType, fn)
{ 
	if(obj.addEventListener)
	{
		obj.addEventListener(evType, fn, false);
		return true;
	}
	else if(obj.attachEvent)
	{
		var r = obj.attachEvent('on' + evType, fn);
		return r;
	}
	else
	{
		return false; 
	} 
}

// Let's begin when the DOM is ready
addEvent(window, 'load', begin);

// Attach the handlers to our selects
function begin()
{
	addSelect('selectCertificadora');
	addSelect('selectTipoProfissioinal');
	addSelect('selectGostariaMelhorar');
	addSelect('selectGostariaMelhorarFundive');
}

// We add a couple of handlers to each
function addSelect(id)
{
	var sel = document.getElementById(id);
	addEvent(sel, 'click', whichElement);
	addEvent(sel, 'click', addRemoveClicked);
}

// Find which element we are looking at on this click
function whichElement(e)
{
	if(!e)
	{
		var e = window.event;
	}

	if(e.target)
	{
		lastClicked = e.target;
	}
	else if(e.srcElement)
	{
		lastClicked = e.srcElement;
	}

	if(lastClicked.nodeType == 3) // Safari bug
	{
		lastClicked = lastClicked.parentNode;
	}
}

// Make sure we are displaying the correct items
function addRemoveClicked(e)
{
	if(!previous[this.id])
	{
		previous[this.id] = new Array();
	}

	// Remember what has been used
	if(previous[this.id][lastClicked.value] == 1)
	{
		previous[this.id][lastClicked.value] = 0;
	}
	else
	{
		previous[this.id][lastClicked.value] = 1;
	}

	var selectBox = document.getElementById(this.id);

	// Add correct highlighting
	for(var i = 0; i < selectBox.options.length; i++)
	{
		selectBox.options[i].selected = '';
		
		if(previous[this.id][selectBox.options[i].value] == 1)
		{
			selectBox.options[i].selected = 'selected';
		}
	}
}









