jQuery.noConflict();
jQuery(document).ready(function($){
	
	// Datepicker
	$('#datepicker').datepicker({
		inline: true
	});
	
	$('#datepicker-2').datepicker({
		inline: true
	});
			
	//filme
	$('#embed EMBED').attr("width", "290");
	$('#embed EMBED').attr("height", "218");
	
	//colunas principais home
	var col1 = $('#sectionA-1').height();
	var col2 = $('#sectionA-2').height();
	var col3 = $('#sectionA-3').height();
	
	if((col1 > col2) && (col1 > col3))
		var maxH = col1;
	else if((col2 > col1) && (col2 > col3))
		var maxH = col2;
	else if((col3 > col1) && (col3 > col2))
		var maxH = col3;
	
	$('#sectionA-1').css('height', maxH);
	$('#sectionA-2').css('height', maxH);
	$('#sectionA-3').css('height', maxH);
	
	
	
	//colunas internas da coluna do meio e área de notícia
	/*var col2a = $('#sectionA-2-1a').height();
	var col2b = $('#sectionA-2-1b').height();
	var colAN = $('.area-noticia').height();
	
	if((col2a > col2b) && (col2a > colAN))
		var maxH = col2a;
	else if((col2b > col2a) && (col2b > colAN))
		var maxH = col2b;
	else if((colAN > col2a) && (colAN > col2b))
		var maxH = colAN;
	
	$('#sectionA-2-1a').css('height', (maxH + 1));
	$('#sectionA-2-1b').css('height', (maxH + 1));
	$('.area-noticia').css('height', maxH);*/
	
	
	
	//colunas principais páginas internas
	var colInt = $('#sectionA-int').height();
	var col3A = $('#sectionA-3A').height();
	
	var maxH = (colInt > col3A) ? colInt : col3A;
	
	$('#sectionA-int').css('height', (maxH + 25));
	$('#sectionA-3A').css('height', maxH);
	
	
	//box's
	var box1 = $('#sectionB-box1').height();
	var box2 = $('#sectionB-box2').height();
	var box3 = $('#sectionB-box3').height();
	
	if((box1 > box2) && (box1 > box3))
		var maxH = box1;
	else if((box2 > box1) && (box2 > box3))
		var maxH = box2;
	else if((col3 > box1) && (col3 > box2))
		var maxH = box3;
	
	$('#sectionB-box1').css('height', maxH);
	$('#sectionB-box2').css('height', (maxH + 2));
	$('#sectionB-box3').css('height', maxH);
	
	//botao de comprar evento
	$('.splitter FORM :image').attr("src", "./img/btn.comprar.png");
	
	
	
	
	// xhtml 1.0 strict way of using target _blank
	jQuery('.sexy-bookmarks a.external').attr("target", "_blank");

	// this block sets the auto vertical expand when there are more than 
	// one row of bookmarks.
	var sexyBaseHeight=jQuery('.sexy-bookmarks').height();
	var sexyFullHeight=jQuery('.sexy-bookmarks ul.socials').height();
	if (sexyFullHeight>sexyBaseHeight) {
		jQuery('.sexy-bookmarks-expand').hover(
			function() {
				jQuery(this).animate({
						height: sexyFullHeight+'px'
				}, {duration: 400, queue: false});
			},
			function() {
				jQuery(this).animate({
						height: sexyBaseHeight+'px'
				}, {duration: 400, queue: false});
			}
		);
	}
	// autocentering
	if (jQuery('.sexy-bookmarks-center') || jQuery('.sexy-bookmarks-spaced')) {
		var sexyFullWidth=jQuery('.sexy-bookmarks').width();
		var sexyBookmarkWidth=jQuery('.sexy-bookmarks:first ul.socials li').width();
		var sexyBookmarkCount=jQuery('.sexy-bookmarks:first ul.socials li').length;
		var numPerRow=Math.floor(sexyFullWidth/sexyBookmarkWidth);
		var sexyRowWidth=Math.min(numPerRow, sexyBookmarkCount)*sexyBookmarkWidth;
		
		if (jQuery('.sexy-bookmarks-spaced').length>0) {
			var sexyLeftMargin=Math.floor((sexyFullWidth-sexyRowWidth)/(Math.min(numPerRow, sexyBookmarkCount)+1));
			jQuery('.sexy-bookmarks ul.socials li').css('margin-left', sexyLeftMargin+'px');
		} else if (jQuery('.sexy-bookmarks-center'.length>0)) {
			var sexyLeftMargin=(sexyFullWidth-sexyRowWidth)/2;
			jQuery('.sexy-bookmarks-center').css('margin-left', sexyLeftMargin+'px');
		}
		
	}
	
	jQuery('.data-filtro').mask("99/99/9999");
	
	jQuery("#id_departamento_filtro").change(function(){ 
		var idDepartamento = jQuery(this).val(); //pegando o value do option selecionado                
		//alert(idDepartamento); //apenas para debugar a variável 
		
		$.getJSON(
				  'inc/Utils.php', //script server-side que deverá retornar um objeto jSON 
				  {action: "selectDivisoesTecnicas", id_departamento: idDepartamento}, //enviando as variáveis
				  function(data){
							//alert(data);//apenas para debugar a variável

						if( data != 0 )
						{
							var option = new Array();//resetando a variável
						 
							resetaCombo('id_divisao');//resetando o combo
						  
							jQuery.each(data, function(i, obj){                                   
								option[i] = document.createElement('option');//criando o option
								
								jQuery( option[i] ).attr( {value : obj.id_divisao} );//colocando o value no option
								jQuery( option[i] ).append( obj.ds_titulo );//colocando o 'label'                                                
								jQuery("select[name='id_divisao']").append( option[i] );//jogando um à um os options no próximo combo                                
							});
						}
						else
						{
							resetaCombo('id_divisao');//resetando o combo
						}
				  });
	});
});

function resetaCombo( el )        
{                
	jQuery("select[name='"+el+"']").empty();//retira os elementos antigos                
	
	var option = document.createElement('option');
	
	jQuery( option ).attr( {value : '0'} );
	jQuery( option ).append( '' );
	
	jQuery("select[name='"+el+"']").append( option );
}  
