$(document).ready(function() {
	
	var TWITTER_USERNAME = 'CLOVESSyndrome';
	
	if( $('#tweets').length > 0 ) {
		$('#tweets').tweet({
			count: 3,
			username: TWITTER_USERNAME,
			loading_text: 'Loading latest tweets... please wait'
		});
	};	
	
	
	$('.top').click(function () {
		$('html , body').animate({
			scrollTop: 0
		});
		return false;
	 });
	
	$('.field')
		.focus(function(){
			if( $(this).val() == $(this).attr('title') ) {
				$(this).val('');
			}
		}).blur(function(){
			if( $(this).val() == '' ) {
				$(this).val( $(this).attr('title') );
			}
		});
	
	$('#slider .carousel ul').jcarousel({
		'scroll' : 1,
		'auto': 5,
		'buttonNextHTML': '',
		'buttonPrevHTML': '',
		'initCallback':  init_carousel,
		'itemFirstInCallback': set_active,
		'wrap': 'both'
	});
	

	
  // RYANS DROP DOWN CODE

	$('#navigation ul li ul').hide();

	$('#navigation ul li').hover(
		function(){
			$('#navigation ul li').not($('ul', this)).stop();
			$('ul li:first-child', this).before('<li class="arrow">arrow</li>');
			$('ul li.arrow', this).css('border-bottom', '0');
			$('ul', this).slideDown();
		},
		function(){
			$('ul', this).slideUp();
			$('ul li.arrow', this).remove();
		}
	);
		
		
   $("#emailsignup").submit( function(e){
      e.preventDefault();
      
      var firstname = $("#firstname").val();
      var lastname = $("#lastname").val();
      var email = $("#email").val();   
   
      $.post('ctloader.cfc?method=addEmailSignup', {firstname:firstname,lastname:lastname,email:email},
  	   function(data,status){
				data = $.trim(data)
					if (data == 'failure') {
						alert('Update Failed!');
					} else {
					 
					 $("#signupform").html('<h2>SIGNUP ADDED</h2><h3>Thank you for joining our email list!</h3>');
					 
					}				
					return false;
			 })		
	     return false;  
   });
   



   $("#uptodate").submit( function(e){
      e.preventDefault();
      
      var email = $("#emailhead").val();
      var zip = $("#zip").val();
  
   
      $.post('ctloader.cfc?method=upToDateSignup', {email:email,zip:zip},
  	   function(data,status){
				data = $.trim(data)
					if (data == 'failure') {
						alert('Update Failed!');
					} else {
					 
					 $("#headform").html('<div style="position:absolute;right: 28px;top: 20px;width: 624px;"><h3 style="font-size:20px;">Thank You For Subscribing to Stay Up To Date!</h3></div>');
					 
					}				
					return false;
			 })		
	     return false;  
   });

		
		
	
});



function init_carousel(carousel) {
	$('#slider .nav a.prev').click(function(){
		carousel.prev();
		return false;
	});
	
	$('#slider .nav a.next').click(function(){
		carousel.next();
		return false;
	});
	
	$('#slider .nav a').click(function(){
		if( $(this).hasClass('prev') || $(this).hasClass('next') ) {
			return;
		}
		var slider_number =  $(this).parents('.nav').find('a').index(this)+1;
		carousel.scroll( slider_number );
		return false;
	});
};

function set_active(carousel, item, idx, state){
	$('#slider .nav a').removeClass('active');
	$('#slider .nav a').eq(idx-1).addClass('active');
}















