$(document).ready(function(){

	/*$('#marquee_box').hover(
                                function(){
                                                $(this).stop(true,true).animate({'color' : '#fff'}, 100);
                                },
                                function(){
                                                $(this).stop(true,true).animate({'color' : '#07242E'}, 500);                                              
                });*/     
		
	$('.flickr-mini-gallery img').click(function() { $('.galleria-image-nav-right').click(); });;

	$("#mcs_container").mCustomScrollbar("vertical",400,"easeOutCirc",1.05,"auto","yes","yes",10);

	$("#form").validate();
		
	var validate = function(){
		if( $('#your-name').val() == 'Please enter your First and Last Name' || $.trim( $('#your-name').val() ) == '' ){
			$('#your-name').addClass('error');
		}
	
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	 		var emailaddressVal = $("#your-email").val();
			
			if( emailaddressVal == 'Please enter your email address' || emailaddressVal == '') {
				$('#your-email').addClass('error');
			}
	 
			else if(!emailReg.test(emailaddressVal)) {
				$('#your-email').addClass('error');
			}

		/*
		if( $('#phone').val() == 'Please enter your mobile phone number' || $.trim( $('#phone').val() ) == '' ){
			$('#phone').addClass('error');
		}
		*/
		/*if( $('#location').val() == 'Please enter the current city you live in' || $.trim( $('#location').val() ) == '' ){
			$('#location').addClass('error');
		} */
		if( $('#age').val() == 'Please enter your age' || $.trim( $('#age').val() ) == '' ){
			$('#age').addClass('error');
		}
		
		if( $('#favdj').val() == 'Please enter your favorite DJ' || $.trim( $('#favdj').val() ) == '' ){
			$('#favdj').addClass('error');
		}
	};
	
	// Contact Form Footer Ajax
	$('button.subscribe-btn').click(function(){ 
		var form = $("#form");
		validate();$("#form").validate();

		if(form.find('input.error').length > 0) $('#message').html("<h2>Contact Form Error!</h2>") 		
		if(form.find('input.error').length > 0) return false; 
		send = form.serialize() + "&type=ajax&submit=Send";
		
		$.ajax({  
		  type: "POST",  
		  url: "http://www.ultramusicfestival.com/subscribe",  
		  data: dataString,  
		  success: function() {   return false; 
			//$('#form').html("<div id='message'>qww</div>");  
			$('#message').html("<h2>Contact Form Submitted!</h2>")  
			.append("<p>We will be in touch soon.</p>")  
			.hide()  
			.fadeIn(1500, function() {  
			  $('#message').append("<img id='checkmark' src='images/check.png' />");  
			});  
			return false; 
		  }  
		});  
	
	return false; 

	});


	if( $('.wpcf7-mail-sent-ok').length){
		$('.wpcf7-form').css({'padding-top':'40px'});
		$('.wpcf7-form p').hide();
	};
	
	if( $('.wpcf7-validation-errors').length){
			$('.wpcf7-form').css({'padding-top':'40px'});
	};
	

	//LOADING POPUP
	
	// this fixes IE JS error
    if (!window.console) console = {log: function() {}};
	
	$('#nojs').remove();
	$('#header ul>li>a, #header>ol>li>a, #header h1 a, #umf_menu ul>li>a, .videos a, #btn-enter').prepend('<span>ultra</span>');

	$('.blank, #menu-item-2127 a, .presslist a').click(function(){ window.open(this.href);return false });	

	tooltip();
	
	$('#umf_menu').hide();
	
	 setTimeout( function(){ $('#btn-map').click(); }, 800); 
	$('#btn-map').toggle(function(){
		$('#umf_menu').removeClass('tempHold');
		$('#umf_menu').show();
	},
	function(){
		$('#umf_menu').hide();
		$('#umf_menu').addClass('tempHold');
	});

	$('#btn-fb').mousedown(
		function(){
			$(this).text('COMING SOON')
			$(this).addClass('active');
			return false;
	});
	
	$('#vid-home a').hover(
		function(){$(this).stop().animate({'color' : '#000'}, 50);}, 
		function(){$(this).stop().animate({'color' : '#818181'}, 300);	
	});	
	
	$("#box_artists .prev, #box_artists .next").hover(
		function(){$(this).stop().animate({'color' : '#000'}, 50);}, 
		function(){$(this).stop().animate({'color' : '#818181'}, 300);	
	});	
	
	$('#header ol li a').hover(
		function(){$(this).stop().animate({'color' : '#fff'}, 50);}, 
		function(){$(this).stop().animate({'color' : '#ccc'}, 300);	
	});	
	
	$('#nav>div>a, #header>ol>li>a, .videos a, #btn-enter').hover(
		function(){$(this).find('span').stop().fadeTo(50, 1);}, 
		function(){$(this).find('span').stop().fadeTo(500, 0);}
	);
	$('#tickets>li>a').prepend('<i>ultra</i>');	
	$('#tickets>li>a').hover(
		function(){$(this).find('i').stop().fadeTo(50, .5);}, 
		function(){$(this).find('i').stop().fadeTo(500, 0);}
	);
	
	$('#header h1 a').hover(
		function(){$(this).find('span').stop().fadeTo(100, 1);}, 
		function(){$(this).find('span').stop().fadeTo(500, 0);}
	);
	 	
	$('#header ul>li>a, #umf_menu ul>li>a').hover(
		function(){
			$(this).stop().animate({'color' : '#fff'}, 100);
			$(this).find('span').stop().fadeTo(100, 1);
		}, 
		function(){
			$(this).stop().animate({'color' : '#aaa'}, 500);
			$(this).find('span').stop().fadeTo(500, 0);	
	});		
		

	if($("#gal").length)
	{	
		$("a[rel=lbx]").fancybox({
				'transitionIn'		: 'fade',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
						return '<span id="fancybox-title-over">' +  (currentIndex + 1) + ' / ' + currentArray.length + '<\/span>';
			}			
		});
		$("a.iframe").fancybox({
			'width'				: 790,
			'height'			: '90%',
			'autoScale'			: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe',
			'scrolling'			: 'auto'	
		});		
	}
	if($(".flickr-mini-gallery").length)
	{	
		
		setTimeout (function() {
		Galleria.loadTheme('http://www.ultramusicfestival.com/wp-content/themes/umf/js/galleria/themes/classic/galleria.classic.js');
            $(".flickr-mini-gallery").galleria({
                width: 605,
                height: 500,
				transition: 'fade',
				thumbCrop: true,
			// 	imageCrop: true,
				autoplay: 5000
            });	
		},300);
		
		$('.flickr-mini-gallery img').fadeIn(300);
		
		
		setTimeout (function() { $('.galleria-image').click( function(){  $('.flickr-mini-gallery').find('.galleria-image-nav-right').click();  });   }, 350 );
		//	setTimeout (function() { $('.flickr-mini-gallery').fadeIn(300);},150);
	}


	if($(".2g-gallery").length)
	{	
		$('.g-gallery div').cycle({ 
			fx:     'fade', 
			speed:  1500, 
			delay: 1000,
			timeout: 4000 

		});	
	}
	if($("#dock").length)
	{
		$('#dock').cycle({
				fx: 'fade',
				timeout: 5000,
				next: '#next',
				speed: 2400,
				delay: 0
		});
	}
	

	// 	$("ul#menu-sidebar-navigation a[href=" + location + "]").addClass('active');
		
  //  if (!window.console) console = {log: function() {}};

	if($("#fRight").length)
	{
		$('#fRight div ul').cycle({
				fx: 'scrollHorz', 
				easing: 'easeInOutExpo',
				timeout: 0,
				// manualTrump: false,
				next: '#fRight .next',
				prev: '#fRight .prev',				
				speed: 1000,
				delay: 1200
		});
	}	
	if($("#vid-home").length)
	{
		$('#vid-home ul').cycle({
				fx: 'scrollHorz', 
				easing: 'easeInOutExpo',
				timeout: 0,
				// manualTrump: false,
				next: '#vid-home .next',
				prev: '#vid-home .prev',				
				speed: 1000,
				delay: 0
		});
	}	
	if($("#box_slider").length)
	{
		$('#box_slider ul').cycle({
				fx: 'fade', 
				timeout: 5000,			
				speed: 1000,
				delay: 1200
		});
	}	
	if($("#box_artists").length)
	{
		$('#box_artists ul').cycle({
				fx: 'uncover', 
				easing: 'easeOutExpo',
				timeout: 3000,
				// manualTrump: false,
				next: '#box_artists .next',
				prev: '#box_artists .prev',
				pause: 1,
				pauseOnPagerHover: 1,				
				speed: 1000,
				delay: 0
		});
	}	
	if($("#gal-home").length)
	{
		$('#gal-home ul').cycle({
				fx: 'scrollHorz', 
				easing: 'easeInOutExpo',
				timeout: 0,
				// manualTrump: false,
				next: '#gal-home .next',
				prev: '#gal-home .prev',				
				speed: 1000,
				delay: 0
		});
	}		
	if($(".ad-banner").length)
	{
		$('.ad-banner ul').cycle({
				fx: 'fade', 
				// easing: 'easeInOutExpo',
				timeout: 5000,
				// manualTrump: false,
				//next: '#gal-home .next',
				//prev: '#gal-home .prev',				
				speed: 1000,
				delay: 1200
		});
	}	
	if($(".ad-banner2").length)
	{
		$('.ad-banner2 ul').cycle({
				fx: 'fade', 
				// easing: 'easeInOutExpo',
				timeout: 18000,
				// manualTrump: false,
				//next: '#gal-home .next',
				//prev: '#gal-home .prev',				
				speed: 1000,
				delay: 1200
		});
	}	
	
	
	// #show-vids #show-gals #gal-home #vid-home
	
	$('#show-gals').click(function(event){
		$('#show-vids').removeClass('vid-active');
		$('#gal-home').fadeIn(300)
		$('#vid-home').fadeOut(0);
		$(this).addClass('gal-active');
		event.preventDefault();
	});	
	$('#show-vids').click(function(event){
		$('#show-gals').removeClass('gal-active');
		$('#vid-home').fadeIn(300)
		$('#gal-home').fadeOut(300)
		$(this).addClass('vid-active');
		event.preventDefault();
	});

	//Click the button event!
	$("#btn-subscribe").click(function(e){
		e.preventDefault();
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
		
		
	// Cookie Session Date
	checkVisitor();
	$("#btn-enter, #backgroundPopup2").click(addVisitor); 

	function checkVisitor()
	{
		if($.cookie("new_umf_visitor") != "true")
		{
			showPopup();
		} else {
							
			if($("#bg-ss").length)
			{
				$('#bg-ss').cycle({
						fx: 'fade', 
						easing: 'easeInOutExpo',
						timeout: 5000,
						// manualTrump: false,
						next: '#home-slideshow .padded',
						//prev: '#gal-home .prev',				
						speed: 1000,
						delay: 1200,
						slideExpr: 'div'
						//randomizeEffects: 1
				});
			}
				
			if($("#home-slideshow").length)
			{
				/*$('#home-slideshow div').cycle({
						fx: 'fade', 
						easing: 'easeInOutExpo',
						timeout: 5000,
						// manualTrump: false,
						 next: '#home-slideshow .padded',
						//prev: '#gal-home .prev',				
						speed: 1000,
						delay: 1200
						//randomizeEffects: 1
				});*/
			}	
		};
	}
	
	function showPopup()
	{
		$('#landerPopup').fadeIn(600);		
		$('#backgroundPopup2').fadeTo(600, .9);	
	}
	
	function addVisitor(e)
	{
		$.cookie("new_umf_visitor", "true", {expires: 1});
		// Cookie addied do this
		/* $('body').prepend('<script type="text/javascript">window.location = "http://www.ultramusicfestival.com/"</script>'); 	 */
	
		$('#landerPopup').fadeOut(600);		
		$('#backgroundPopup2').fadeOut(600);
	
	
			if($("#bg-ss").length)
			{
				$('#bg-ss').cycle({
						fx: 'fade', 
						easing: 'easeInOutExpo',
						timeout: 5000,
						// manualTrump: false,
						next: '#home-slideshow .padded',
						//prev: '#gal-home .prev',				
						speed: 1000,
						delay: 1200,
						slideExpr: 'div'
						//randomizeEffects: 1
				});
			}
				
			if($("#home-slideshow").length)
			{
				$('#home-slideshow div').cycle({
						fx: 'fade', 
						easing: 'easeInOutExpo',
						timeout: 5000,
						// manualTrump: false,
						 next: '#home-slideshow .padded',
						//prev: '#gal-home .prev',				
						speed: 1000,
						delay: 1200
						//randomizeEffects: 1
				});
			}	 
				
		e.preventDefault();
		return false;		
	}

	$("#btn-clear").click(function(){
			$.cookie("new_umf_visitor3", null)
			$.cookie("new_umf_visitor1", null)
			$.cookie("new_umf_visitor2", null)						
			$.cookie("new_umf_visitor", null)			
	});


	$('#btn-movie-start, #btn-movie-start2').click(function(){ 
		
		$('#landerPopup').fadeOut(600);		
		$('#backgroundPopup2').fadeOut(600);	
							
	}); 
	
	$('#backgroundPopup2').click(function(){
		$('#landerPopup').fadeOut(600);		
		$('#backgroundPopup2').fadeOut(600);	
	});
		
		
	if($("#bg-ss").length)
			{
				$('#bg-ss').cycle({
						fx: 'fade', 
						easing: 'easeInOutExpo',
						timeout: 5000,
						// manualTrump: false,
						next: '#home-slideshow .padded',
						//prev: '#gal-home .prev',				
						speed: 1000,
						delay: 1200,
						slideExpr: 'div'
						//randomizeEffects: 1
				});
			}
				
			if($("#home-slideshow").length)
			{
				$('#home-slideshow div').cycle({
						fx: 'fade', 
						easing: 'easeInOutExpo',
						timeout: 5000,
						// manualTrump: false,
						 next: '#home-slideshow .padded',
						//prev: '#gal-home .prev',				
						speed: 1000,
						delay: 1200
						//randomizeEffects: 1
				});
			}	 
					
	/*			
		$(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
			$('#loader').fadeOut(1200);	
		});		
	*/

});

