(function ($) {
    $.fn.vAlign = function(container) {
        return this.each(function(i){
	   if(container == null) {
	      container = 'div';
	   }
	   var paddingPx = 10; //change this value as you need (It is the extra height for the parent element)
	   $(this).html("<" + container + ">" + $(this).html() + "</" + container + ">");
	   var el = $(this).children(container + ":first");
	   var elh = $(el).outerHeight(); //new element height
	   var ph = $(this).height(); //parent height
	   if(elh > ph) { //if new element height is larger apply this to parent
	       $(this).height(elh + paddingPx);
	       ph = elh + paddingPx;
	   }
	   var nh = (ph - elh) / 2; //new margin to apply
	   $(el).css('margin-top', nh);
        });
     };
})(jQuery);

jQuery(document).ready(function(){
	
	jQuery("#chamadaBlog ul li:last").addClass('last');
	
  	jQuery('#painel ul').anythingSlider({
		width: 687,
		height: 310,
		toggleControls: false,
		startStopped: false,
		buildArrows:false,
		buildNavigation:false,
		enablePlay:false,
		startPanel:1,
		infiniteSlides: false,
		delay: 6000
	}).bind('slide_complete', function(e, slider){
		 selecionaLink(slider.currentPage);
	});

	jQuery('#btProximo').click(function() {
		jQuery('#painel ul').data('AnythingSlider').goForward(); 
	});

	jQuery('#btVoltar').click(function() {
		jQuery('#painel ul').data('AnythingSlider').goBack(); 
	});
	
	jQuery('#painelLinks a#linkCursos').click(function() {
		jQuery('#painel ul').anythingSlider(1);
	});
	
	jQuery('#painelLinks a#linkIntensivo').click(function() {
		jQuery('#painel ul').anythingSlider(2);
	});
	
	jQuery('#painelLinks a#linkShows').click(function() {
		jQuery('#painel ul').anythingSlider(3); 
	});
	
	jQuery('#painelLinks a#linkInCompany').click(function() {
		jQuery('#painel ul').anythingSlider(4); 
	});
	
	jQuery('input[type="text"], textarea').focus(function() {  
		if (this.value == this.defaultValue){  
			this.value = '';  
			this.style.color = "#ffffff";
		}  
		if(this.value != this.defaultValue){  
			this.select();  
		}  
	});
	jQuery('input[type="text"], textarea').blur(function() {  
		if (this.value == ''){  
			this.value = (this.defaultValue ? this.defaultValue : ''); 
			this.style.color = "#81C7E0"; 
		}  
	});
	
	jQuery('#sideEsquerda').css({ height: jQuery('#conteudo').height() - 50 });
	
	jQuery('#conteudo.cursos div#contInterna').css({ height: jQuery('#conteudo.cursos div#sideInterna ').height() - 25 });
	
	jQuery('#historico, #listaModular').masonry({
	  singleMode: true, 
	  itemSelector: '.dataHistorico' 
	});
	
	jQuery('input[name=para_radio]').get(0).click();
	
	jQuery('input[name=para_radio]').click(function() {
			
		
			selecionado = jQuery(this).val();

			
			if(selecionado == "Joinville") {
				jQuery('#para').val("contato@dancajoinville.com.br");
			} else if(selecionado == "Jaraguá do Sul") {
				jQuery('#para').val("contato@dancajaraguadosul.com.br");
			}
		});

});

var selecionado;

var selecionaLink = function(num) {
	jQuery("#painelLinks a").removeClass("view");
	
	if(num == 1) {
		jQuery('#linkCursos').toggleClass("view");
	} else if(num == 2) {
		jQuery('#linkIntensivo').toggleClass("view");
	} else if(num == 3) {
		jQuery('#linkShows').toggleClass("view");
	} else if(num == 4) {
		jQuery('#linkInCompany').toggleClass("view");
	}
}
