// BANNER SLIDER
$(document).ready(function() {

	//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active");
	

	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageSum = $(".bannerSlider").size();
	var imageReelWidth = imageWidth * imageSum;
	

	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	

	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

		//Slider Animation
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
	}; 
	

	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 5000); //Timer speed in milliseconds (3 seconds)
	};
	rotateSwitch(); //Run function on launch
	

	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	


	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
});


// VIDEO LIGHTBOX
function onYouTubePlayerReady(playerId) { 
ytplayer = document.getElementById("video_overlay"); 
ytplayer.setVolume(100); 
} 


// VALIDA FORM
function validaDados() {
	if (ValidaEmail(document.getElementById('newsletter').value)) {
		$('.notice').trigger('click');
		
		
		return false;
	}
	document.newsletter.submit();
}
function ValidaEmail(Email){
  inval = "\ \"\/\:\,\;\{\}\$\\\\[\]\~\'\^\!\?\=\+\*\#\&\á\é\í\ó\ú\Á\É\Í\Ó\Ú\ü\Ü\â\Â\ê\Ê\î\Î\ô\Ô\û\Û\ç\Ç\à\À\ã\Ã\õ\Õ\%\¨\<\>";

  for (i=0; i<inval.length; i++){
    char_ruim = inval.charAt(i);
    if (Email.indexOf(char_ruim,0) > -1){
      return 1;
    }
  }
  atPos = Email.indexOf("@",1);
  periodPos = Email.indexOf(".",atPos);
  if ((atPos == -1) || (Email.indexOf("@",atPos+1) > -1) || (periodPos == -1) || (periodPos+3 > Email.length)){
    return 1;
  }
  return 0;
}


// JNOTIFY
$(document).ready(function(){
    $(".notice").click(function(e){
	  e.preventDefault();
	  jNotify(
		'Preencha o email corretamente.',
		{
		  autoHide : true, // added in v2.0
		  clickOverlay : false, // added in v2.0
		  MinWidth : 250,
		  TimeShown : 2000,
		  ShowTimeEffect : 200,
		  HideTimeEffect : 200,
		  LongTrip :20,
		  HorizontalPosition : 'center',
		  VerticalPosition : 'center',
		  ShowOverlay : true,
   		  ColorOverlay : '#000',
		  OpacityOverlay : 0.3,
		  onClosed : function(){ // added in v2.0
		  },
		  onCompleted : function(){ // added in v2.0
		  }
		});
	});
	
    $(".success").click(function(e){
	  e.preventDefault();
	  jSuccess(
		'<p font-size="108px">Obrigado!<br />Em breve entraremos em contato.</p>',
		{
		  autoHide : true, // added in v2.0
		  clickOverlay : false, // added in v2.0
		  MinWidth : 250,
		  TimeShown : 2000,
		  ShowTimeEffect : 200,
		  HideTimeEffect : 200,
		  LongTrip :20,
		  HorizontalPosition : 'center',
		  VerticalPosition : 'center',
		  ShowOverlay : true,
   		  ColorOverlay : '#000',
		  OpacityOverlay : 0.3,
		  onClosed : function(){ // added in v2.0
		  },
		  onCompleted : function(){ // added in v2.0
		   
		  }
		});
	});
	$('.success').trigger('click');
});

$(document).ready(function(){
    $(".cadastrado").click(function(e){
	  e.preventDefault();
	  jSuccess(
		'<p font-size="108px">Email cadastrado.<br />Em breve lhe enviaremos nossa newsletter!</p>',
		{
		  autoHide : true, // added in v2.0
		  clickOverlay : false, // added in v2.0
		  MinWidth : 250,
		  TimeShown : 2000,
		  ShowTimeEffect : 200,
		  HideTimeEffect : 200,
		  LongTrip :20,
		  HorizontalPosition : 'center',
		  VerticalPosition : 'center',
		  ShowOverlay : true,
   		  ColorOverlay : '#000',
		  OpacityOverlay : 0.3,
		  onClosed : function(){ // added in v2.0
		  },
		  onCompleted : function(){ // added in v2.0
		   
		  }
		});
	});
	$('.cadastrado').trigger('click');
});

	
//CLEARFIELD
$(function(){
	$(".input1").clearField({
		blurClass: "blur",					
		activeClass: "active"						
	})
});
	
	
//ACCORDION
$(function() {
	$("#accordion").accordion({
		autoHeight: false,
		navigation: true,
		collapsible: true
		});
	$("#accordion").accordion({ 
		active: false 
		});
});


//NA MIDIA
$(function() {
  $("#midia02").click(function () {
      $("#noticia02,.closeMidia").fadeIn();
      $("#noticia03,#noticia04,#noticia05").fadeOut();
    });
  $("#midia03").click(function () {
      $("#noticia03,.closeMidia").fadeIn();
      $("#noticia02,#noticia04,#noticia05").fadeOut();
    });
  $("#midia04").click(function () {
      $("#noticia04,.closeMidia").fadeIn();
      $("#noticia03,#noticia02,#noticia05").fadeOut();
    });
  $("#midia05").click(function () {
      $("#noticia05,.closeMidia").fadeIn();
      $("#noticia03,#noticia04,#noticia02").fadeOut();
    });
  $("#Editorial").click(function () {
      $("#EditorialContent,.closeMidiaHome").fadeIn();
    });
  $("#noticia02,#noticia03,#noticia04,#noticia05,.closeMidia,#videogallery,#EditorialContent,.closeMidiaHome").click(function () {
      $("#noticia02,#noticia03,#noticia04,#noticia05,#EditorialContent,.closeMidia,.closeMidiaHome").fadeOut();
    });
});

