jQuery.noConflict();
jQuery(document).ready(function($) {
	//Parallax
	jQuery('#parallax .back').plaxify({"xRange":40,"yRange":40})
	jQuery('#parallax .front').plaxify({"xRange":20,"yRange":20})
	//jQuery('#plax-sphere-3').plaxify({"xRange":40,"yRange":40,"invert":true})
	jQuery.plax.enable()
	
	//Page Load effect
	jQuery("#the_lights").fadeTo(1,0);
	var content = jQuery('#content');
	var lights = jQuery('#the_lights'); 
	var href = '/show-e-eventos/';   
	jQuery('#home-link-eventos').live('click', function( e ){  
		e.preventDefault();
		jQuery('html, body').animate({
			scrollTop: jQuery('.inicial').offset().top
		}, 1000, function() {
			lights.css({'z-index' : '99999'});
			lights.css({'display' : 'block'});
			lights.fadeTo("slow",1);
	   });
		jQuery.ajax({  
			url: href,  
			success: function( response ){
				var data = jQuery( '<div>'+response+'</div>' ).find('#content').html();  
				window.setTimeout( function(){
					jQuery("body").addClass("shows_eventos");
					jQuery("body").removeClass("inicial");
					jQuery('#menu').html('<a href="/" title="Grifiart" rel="home" class="link-website">Voltar para o website</a>');  
					jQuery(".home-eventos-link").toggle();
					jQuery(".home-eventos-side").toggle();
					jQuery("#parallax .back").attr("src",'/wp-content/themes/grifiart/images/parallax/back-evento.png');
					jQuery("#parallax .front").attr("src",'/wp-content/themes/grifiart/images/parallax/front-evento.png');
					jQuery(".btn-news").attr("src",'/wp-content/themes/grifiart/images/newsletter/news-enviar-evento.png');
					content.html( data );
					Cufon.replace('h1, h2, h3, .lista-filhas li a', { hover: true });
					Cufon.replace('.link-website', {textShadow: '1px 1px 0 #404141', hover: true});
					Cufon.replace('#sidebar h2', {textShadow: '1px 1px 0 #5e5e5e'});
					lights.fadeTo("fast",0.2);
					lights.fadeTo("fast",0.9);
					lights.fadeTo("fast",0.2);
					lights.fadeTo("slow",0, function() {
					  	lights.css({'z-index' : '-9999'});
					});
					
				}, 100 );  
			}  
		});  

	});
	jQuery(".shows_eventos .btn-news").hover( function () {
		jQuery(this).attr("src",'/wp-content/themes/grifiart/images/newsletter/news-enviar-evento-h.png');
	},function () {
		jQuery(this).attr("src",'/wp-content/themes/grifiart/images/newsletter/news-enviar-evento.png');
	}
);
	
	//Banners
	/*
	jQuery(".banner-container").delegate("li", "mouseover mouseout", function(e) {
		if (e.type == 'mouseover') {
			jQuery(".banner-container li").not(this).dequeue().animate({opacity: "0.5"}, 300);
			jQuery(this).find('div.caption').stop(false,true).slideDown(200);
    	} else {
			jQuery(".banner-container li").not(this).dequeue().animate({opacity: "1"}, 300);
			jQuery(this).find('div.caption').stop(false,true).slideUp(200);
   		}
	});
	*/
});
/* Banners
-------------------------------------------------*/
jQuery(function() {
//custom animations to use
//in the transitions
var animations		= ['right','left','top','bottom','rightFade','leftFade','topFade','bottomFade'];
var total_anim		= animations.length;
//just change this to one of your choice
var easeType		= 'swing';
//the speed of each transition
var animSpeed		= 450;
//caching
var $hs_container	= jQuery('.banner-container');
var $hs_areas		= $hs_container.find('.banner_item');

//first preload all images
$hs_images          = $hs_container.find('img');
var total_images    = $hs_images.length;
var cnt             = 0;
$hs_images.each(function(){
	var $this = jQuery(this);
	jQuery('<img/>').load(function(){
		++cnt;
		if(cnt == total_images){
			$hs_areas.each(function(){
				var $area 		= jQuery(this);
				//when the mouse enters the area we animate the current
				//image (random animation from array animations),
				//so that the next one gets visible.
				//"over" is a flag indicating if we can animate 
				//an area or not (we don't want 2 animations 
				//at the same time for each area)
				$area.data('over',true).bind('mouseenter',function(){
					if($area.data('over')){
						$area.data('over',false);
						//how many images in this area?
						var total		= $area.children().length;
						//visible image
						var $current 	= $area.find('img:visible');
						//index of visible image
						var idx_current = $current.index();
						//the next image that's going to be displayed.
						//either the next one, or the first one if the current is the last
						var $next		= (idx_current == total-1) ? $area.children(':first') : $current.next();
						//show next one (not yet visible)
						$next.show();
						//get a random animation
						var anim		= animations[Math.floor(Math.random()*total_anim)];
						switch(anim){
							//current slides out from the right
							case 'right':
								$current.animate({
									'left':$current.width()+'px'
								},
								animSpeed,
								easeType,
								function(){
									$current.hide().css({
										'z-index'	: '1',
										'left'		: '0px'
									});
									$next.css('z-index','9999');
									$area.data('over',true);
								});
								break;
							//current slides out from the left
							case 'left':
								$current.animate({
									'left':-$current.width()+'px'
								},
								animSpeed,
								easeType,
								function(){
									$current.hide().css({
										'z-index'	: '1',
										'left'		: '0px'
									});
									$next.css('z-index','9999');
									$area.data('over',true);
								});
								break;
							//current slides out from the top	
							case 'top':
								$current.animate({
									'top':-$current.height()+'px'
								},
								animSpeed,
								easeType,
								function(){
									$current.hide().css({
										'z-index'	: '1',
										'top'		: '0px'
									});
									$next.css('z-index','9999');
									$area.data('over',true);
								});
								break;
							//current slides out from the bottom	
							case 'bottom':
								$current.animate({
									'top':$current.height()+'px'
								},
								animSpeed,
								easeType,
								function(){
									$current.hide().css({
										'z-index'	: '1',
										'top'		: '0px'
									});
									$next.css('z-index','9999');
									$area.data('over',true);
								});
								break;
							//current slides out from the right	and fades out
							case 'rightFade':
								$current.animate({
									'left':$current.width()+'px',
									'opacity':'0'
								},
								animSpeed,
								easeType,
								function(){
									$current.hide().css({
										'z-index'	: '1',
										'left'		: '0px',
										'opacity'	: '1'
									});
									$next.css('z-index','9999');
									$area.data('over',true);
								});
								break;
							//current slides out from the left and fades out	
							case 'leftFade':
								$current.animate({
									'left':-$current.width()+'px','opacity':'0'
								},
								animSpeed,
								easeType,
								function(){
									$current.hide().css({
										'z-index'	: '1',
										'left'		: '0px',
										'opacity'	: '1'
									});
									$next.css('z-index','9999');
									$area.data('over',true);
								});
								break;
							//current slides out from the top and fades out	
							case 'topFade':
								$current.animate({
									'top':-$current.height()+'px',
									'opacity':'0'
								},
								animSpeed,
								easeType,
								function(){
									$current.hide().css({
										'z-index'	: '1',
										'top'		: '0px',
										'opacity'	: '1'
									});
									$next.css('z-index','9999');
									$area.data('over',true);
								});
								break;
							//current slides out from the bottom and fades out	
							case 'bottomFade':
								$current.animate({
									'top':$current.height()+'px',
									'opacity':'0'
								},
								animSpeed,
								easeType,
								function(){
									$current.hide().css({
										'z-index'	: '1',
										'top'		: '0px',
										'opacity'	: '1'
									});
									$next.css('z-index','9999');
									$area.data('over',true);
								});
								break;		
							default:
								$current.animate({
									'left':-$current.width()+'px'
								},
								animSpeed,
								easeType,
								function(){
									$current.hide().css({
										'z-index'	: '1',
										'left'		: '0px'
									});
									$next.css('z-index','9999');
									$area.data('over',true);
								});
								break;
						}	
					}
				});
			});
			
			//when clicking the hs_container all areas get slided
			//(just for fun...you would probably want to enter the site
			//or something similar)
			$hs_container.bind('click',function(){
				$hs_areas.trigger('mouseenter');
			});
		}
	}).attr('src',$this.attr('src'));
});			


});
/* Menu
-------------------------------------------------*/
jQuery(function() {
	jQuery('#menu-menu-topo > li').hover(
		function () {
			var $this = jQuery(this);
			jQuery('a',$this).stop(true,true).animate({
					'top':'0'
				}, 300);
		},
		function () {
			var $this = jQuery(this);
			jQuery('a',$this).stop(true,true).animate({
					'top':'40px'
				}, 300);
		}
	);
});

/* Newsletter
-------------------------------------------------*/
function CheckForm151(f) {
	var fname = "CustomFields_460_151";
	var fld = document.getElementById(fname);
	if (fld.value == "") {
		alert("Por favor, preencha um valor para campo Nome");
		fld.focus();
		return false;
	}
	var email_re = /[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
	if (!email_re.test(f.email.value)) {
		alert("Por favor, preencha seu endereço de email.");
		f.email.focus();
		return false;
	}
	if (email_re.test(f.email.value) && fld.value != "") {
		jQuery("#side-bloco-news-form").animate({"bottom": "-=132px"}, "slow", function() {
		 	jQuery("#side-bloco-news-resposta").animate({"bottom": "+=132px"}, "slow");
	    });
		jQuery.ajax({type:'POST', url: 'http://painel2.softmail.com.br/form.php?form=151', data:jQuery('#formnewsletter').serialize(), success: function(response){}});
		return false;
	}
		return true;
}
