/*
$(function() {
	
	$("#signup_button").click(function() {
		// validate and process form here
		var theName = $("input#signup_name").val();
		var theEmail = $("input#signup_email").val();
		if (theName == "" || theName == $("input#signup_name").attr('title') || theEmail == "" || theEmail == $("input#signup_email").attr('title') ){return false;}
		var theDataString = 'name='+ theName + '&email=' + theEmail;
		var theAction = $("#signup_form").attr('action'); //retrieves the value of the action attribute of the form
		
		$.ajax({
      type: "POST",
      url: theAction,  
      data: theDataString,
      success: function() {
        $('#home_signup').html("<div id='signup_message'></div>");
        $('#signup_message').html("<h2 align='center'>Thanks for Signing Up!</h2>")
        .hide()
        .fadeIn(1500, function() {
          $('#signup_message');
        });
      }
    });
		
		return false;
	});
 
}); 

*/


// Triggers scrolling from right to left on carousel (used on timer to trigger auto scroll)
function scrollCarousel(){
	$('.jcarousel-next').trigger('click');
}

jQuery(function($){

	document.getElementById("carousel").style.display = "block";
	// Home page carousel
	var carousel_arr = [];
	
	// Temporary containers for form data in carousel
	var form_data = [];
	var new_item;
	
	var msie = $.browser.msie;
	
	// Initialization 
	function carouselInitCallback(carousel){
		$.each($('#carousel ul').children(),function(){
			carousel_arr.push($(this).html());
		});
		$('.jcarousel-next,.jcarousel-prev').insertAfter('#carousel-wrap');
		var auto_carousel = setInterval("scrollCarousel()", 5000);
		$('#carousel, .jcarousel-next, .jcarousel-prev').mouseover(function(e){
			e.stopPropagation();
			
			carousel.options.animation = 500;
			carousel.options.easing = 'easeOutCubic';
			clearInterval(auto_carousel);
			carousel.startAuto(0);
			
			// Adds mouseover function for body, to resume auto carousel motion
			// Added 2009-03-25
			$('body').mouseover(function(){
				carousel.options.animation = 1500;
				carousel.options.easing = 'easeInOutCubic';
				$('.jcarousel-next').trigger('click');
				auto_carousel = setInterval("scrollCarousel()", 5000);
				$(this).unbind('mouseover');
			});
			
		});
	}
	
	// Fired before carousel moved, appends new item to carousel to give illusion of infininate list
	function carouselInCallback(carousel, item, i, state, evt){
		var idx = carousel.index(i, carousel_arr.length);
		new_item = carousel.add(i,carousel_arr[idx - 1]);
		// Apply PNG Fix for IE6
		$('#carousel .desc-wrap, #carousel .lbl').ifixpng();
	}
	
	// Fired after carousel move, removes item from end of carousel (same one which was appended beforehand)
	function carouselOutCallback(carousel, item, i, state, evt){
		carousel.remove(i);
	}
	
	// Invoke home page carousel
	$('#carousel ul').jcarousel({
		scroll:1,
		auto: 5,
		wrap: 'circular',
		initCallback: carouselInitCallback,
		itemVisibleInCallback: {onBeforeAnimation: carouselInCallback},
		itemVisibleOutCallback: {onAfterAnimation: carouselOutCallback},
		easing:'easeInOutCubic',
		animation:1500
	});
	
	// If IE, apply some PNG fixes and allow for hover state on previous and next buttons
	if(msie){
		$('#carousel .desc-wrap, #carousel .lbl, .jcarousel-prev, .jcarousel-next').ifixpng();
		$('.jcarousel-prev,.jcarousel-next').hover(function(){
			$(this).iunfixpng().css('background-position','-61px 0');
		},function(){
			$(this).css('background-position','0 0').ifixpng();
		});
	}
	
});



