
$(document).ready(function() {


	
	//slide for the home page
    $('#homeImages').cycle({
		fx: 'fade' 
	});
	
	//location gmaps popup
	$(".googlePop").fancybox({
				'width'				: '75%',
				'height'			: '75%',
				'autoScale'			: false,
				'overlayColor'		: '#333333',
				'type'				: 'iframe'
	});
	
	$(".videoPop").fancybox({
				'width'				: 660,
				'height'			: 500,
				'autoScale'			: false,
				'overlayColor'		: '#333333',
				'type'				: 'iframe'
	});
	
	$(".purchasePop").fancybox({
				'width'				: 360,
				'height'			: 250,
				'autoScale'			: false,
				'overlayColor'		: '#333333',
				'type'				: 'iframe'
	});
	
	$(".packagePop").fancybox({
				'width'				: 600,
				'autoScale'			: false,
				'overlayColor'		: '#333333',
				'type'				: 'inline'
	});
	
	$(".fancyPop").fancybox();
	
	$('.cycleHolder').cycle({
		fx: 'fade',
		sync: 1,
		timeout: 5000,
		cleartypeNoBg: true
		//before: onAfter
	});
	
	$('#video_holders').cycle({
		fx: 'scrollHorz',
		next: '#next',
		prev: '#prev',
		speed: 200,
		cleartypeNoBg: true,
		timeout: 0
	});

	function onAfter(curr, next, opts, fwd) {
		var index = opts.currSlide;
		//get the height of the current slide
		var $ht = $(this).height();
		//set the container's height to that of the current slide
		$(this).parent().animate({height: $ht});
	}

	
	
	/*START STARS AND DOTS HANDLING*/
	function showAndTell(element){
		var pop = element.replace('-star','-pop');
		pop = pop.replace('-dot','-pop');
		pop = pop.replace('-link','-pop');
		//be lame for IE
		if ($.browser.msie) {
			$('.locPop').hide();
			$('#'+pop).show();
		}else{
			$('.locPop').fadeOut();
			$('#'+pop).fadeIn();
		}
	}
	
	
	$('.locHolder').click(function(){
		showAndTell($(this).attr('id'));
		return false;
	});
	
	$('.locHolder_sub').click(function(){
		showAndTell($(this).attr('id'));
		return false;
	});
	$('.dot-holder').click(function(){
		showAndTell($(this).attr('id'));
		return false;
	});
	/*END STARS AND DOTS*/
		
	
	//close all the popups
	$('.closePopup').click(function(){
		if ($.browser.msie) {
			$('.locPop').hide();
		}else{
			$('.locPop').fadeOut();
		}
		return false;
	});
	$('#mapHolder').click(function(){
		if ($.browser.msie) {
			$('.locPop').hide();
		}else{
			$('.locPop').fadeOut();
		}
		
	})

	
	//validate the vip signup form
	$('#vip-signup').validate({
		rules : {
			'first_name' : 'required',
			'last_name' : 'required',
			'address' : 'required',
			'city' : 'required',
			'state' : 'required',
			'zip' : 'required',
			'location_id' : 'required',
			'email' : {
                'required'  : true,
                'email'     : true
            },
            'password' : 'required',
            'password2' : {
            	'required' : true,
            	'equalTo' : "#password"
            }
    	}
	});
	
	//page scroll to element
	$('.scroller').click(function(){
		// lets clean the href, it could be something like "/something/something/#id"
		var splitVar = $(this).attr("href");
		var partsArray = splitVar.split('#');
		//we'll cram in into a nice "#id"
		var elementClicked = "#"+partsArray[1];
		var destination = $(elementClicked).offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
		
		//Let's try and glow the object we're scrolling to. Might me lame. Might be cool.
		//meh, all this does is bind it to a hover-- cool plugin, but not what we need.
		//$(elementClicked).addGlow({ textColor: 'white', haloColor: '#fff', radius: 100 });
		
		return false;
	});
	
	
	$('.poppers a').fancybox({
					'width'				: 930,
					'height'			: 610,
			        'autoScale'     	: false,
			        'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'iframe'
				});
	
	$('#postThumb a').click(function(){
				$('#postThumb a').removeClass('active');
				$('#postImageHolder').removeClass();
				$('#imageName').val('');
				var linkers = $(this).attr('href');
				$(this).addClass('active');
				$('#postImageHolder').addClass(linkers);
				$('#imageName').val(linkers);
				return false;
			});
			
			$('#textHolder').focus(function(){
				if ($(this).val() == 'Click here and start typing...'){
					$(this).val('');
				}
				
			});
			
			$('#textHolder').blur(function(){
				if ($(this).val() == 'Click here and start typing...' || $(this).val() == ''){
					$(this).val('Click here and start typing...');
				}
				
			});
			
			$('#sendPosterNow').click(function(){
				$('#sendPoster').submit();
				return false;
			});
			
	$('#xthuhi-xthuhi').focus(function(){
		if($(this).val() == "email@domain.com"){
			$(this).val('');
		};
	});	
	$('#xthuhi-xthuhi').blur(function(){
		if($(this).val() == ""){
			$(this).val('email@domain.com');
		};
	});		
	$("#subFormSubmit").click(function() { 
	
		// First, disable the form from submitting
		$('form#subForm').submit(function() { return false; });
		
		// Grab form action
		var formAction = $("form#subForm").attr("action");
		
		// Hacking together id for email field
		// Replace the xxxxx below:
		// If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
		var id = "xthuhi";
		var emailId = id + "-" + id;
		
		// Serialize form values to be submitted with POST
		var str = $("form#subForm").serialize();
		
		// Add form action to end of serialized data
		// CDATA is used to avoid validation errors
		//<![CDATA[
		var serialized = str + "&action=" + formAction;
		// ]]>
		
		
		
		// Submit the form via ajax
		$.ajax({
			url: "proxy.php",
			type: "POST",
			data: serialized,
			success: function(data){
				// Server-side validation
				if (data.search(/invalid/i) != -1) {
					alert('The email address you supplied is invalid and needs to be fixed before you can subscribe to this list.');
				}else{
					$("#theForm").slideUp(); // If successfully submitted hides the form
					$("#confirmation").slideDown("slow");  // Shows "Thanks for subscribing" div
					$("#confirmation").tabIndex = -1;
					$("#confirmation").focus(); // For screen reader accessibility
				}
			}
		});
		
		return false;
	}); // close AJAX CM email submit form function
     

});

