$(document).ready(function() {

	$('a[rel*=modal]').facebox();

	$.itemWidth = 940;
	$.channelTotal = 4;
	$.armsDown = true;
	$.currentItem = 0;
	
	$.featureWidth = $.itemWidth * $.channelTotal;
	$("#feature").width($.featureWidth);
	$("#feature").css('left','0px');
	
	function disableUV(){
	if (isThisUv) {
			resetArms();
			$('link[rel=stylesheet][href=/css/ultraviolet.css]').remove();
			setTimeout(function(){			
			Cufon.refresh('h2, h3.cufon');
			Cufon.replace('h3.smallHeading, div.homePageNews h4', { fontFamily: 'FontSite Sans' });
			Cufon.replace('h2 span', { fontFamily: 'mutantFont'});
			
			lineColor = "blue";
			
			$(".spanGlow").attr("src","");
			$(".spanGlow2").attr("src","");
			 },100);
		//alert("this is uv!");  
	} else {
		//alert("this aint no uv!");  
	}
	}
	
	function myfunc(navItem) {
		disableUV();
		if(navItem == $.currentItem){
			return;
		}
		$.currentItem = navItem;
		$.scrollAmountTemp = $.itemWidth * navItem;		
		$.scrollAmount = "-"+$.scrollAmountTemp;
		//alert($.scrollAmount);
		if ($.armsDown == true && navItem != 0){
			// move the arms out
			if(resetArms()){
				// raise the arms with a delay
				$.armsDown = false;
				$("#powerArms").animate({opacity: 1.0}, 500).animate({"top": -400}, 1000, "easeInBack");
				$("#feature").animate({opacity: 1.0}, 1000).fadeOut(500).animate({"left": $.scrollAmount}, 0).fadeIn(500);
			} else {
				// raise the arms normally
				$.armsDown = false;
				$("#powerArms").animate({"top": -400}, 1000, "easeInBack");
				$("#feature").animate({opacity: 1.0}, 500).fadeOut(500).animate({"left": $.scrollAmount}, 0).fadeIn(500);
			}
		
		} else {
			$("#feature").fadeOut(500).animate({"left": $.scrollAmount}, 0).fadeIn(500);
			//$("#feature");
		}
		
		
		if(navItem == 0){
		//lower the arms, set a flag
			$("#powerArms").animate({opacity: 1.0}, 500).animate({"top": -4}, 1000, "easeOutBack");
			$.armsDown = true;
		
		}
	}
	
	function resetArms(){
		if($("#leftArm").data('Complete') == true || $("#rightArm").data('Complete') == true){
			$("body").removeClass('ultraviola');
			$("#leftArm").data('Complete', false);
			$("#rightArm").data('Complete', false);
	
			$("#stand").animate({"top": 100},500, "easeOutBack");
			$("#leftArm").animate({marginLeft:0}, {duration:500});
			$("#rightArm").animate({marginRight:0}, {duration:500});
			amplitude = 2;
			return true;
		} else {
			return false
		}
	}
	
	//myfunc(3);
	
	$('#featureNav li a').click(function(){
		//alert( $('#featureNav li a').index(this) );
		$('#featureNav li a').attr("class", "");
		
		myfunc($('#featureNav li a').index(this));
		
		$(this).attr("class", "active");
		return false;
	});
	
	var isThisUv = false;
	
	$('#button').click(function(){
		$("body").addClass('ultraviola');
		//$('h2').css("color","#5235ee");
		//$('h3').css("color","#5235ee");
		//var styleSheet = $("<link>");
		//css = $("head").children(":last");
		/*styleSheet.attr({
		  rel:  "stylesheet",
		  type: "text/css",
		  href: "/css/ultraviolet.css"
		});
		$("head").append(styleSheet);*/
		
		isThisUv = true;
		
		$(".spanGlow").attr("src","images/home/uv/span_highlight_bg.png");
		$(".spanGlow2").attr("src","images/home/uv/span_highlight_bg.png");
		
		setTimeout(function(){
			Cufon.refresh('h2, h3.cufon');
			Cufon.replace('h3.smallHeading, div.homePageNews h4', { fontFamily: 'FontSite Sans' });
			Cufon.replace('h2 span', { fontFamily: 'mutantFont'});
			
			lineColor = "UV";
//ctx.strokeStyle = "rgba(40, 15, 175, 0.05)";
	    },100);
		
		return false;
	});
	
	//turn off the uv mode!
	
	$('body').click(function() {
		disableUV();
	//	resetArms();
	});
	//ricards stuff
	
		//init
		$("#leftArm").data('Complete', false);
		$("#rightArm").data('Complete', false);
	
		//left connection
		$("#leftArm").hover(function(){
			
			$(this).data('Off', false);
			// move the arm
			$(this).animate({marginLeft:50},1000, "easeOutBackArm", function() {
						$(this).data('Complete', true);
						checkPower();
			    }
			);
		});
		
		//right connection
		$("#rightArm").hover(function(){
			
			$(this).data('Off', false);			
			//move arm
			$(this).animate({marginRight:40},400, "easeOutBackArm", function() {
						$(this).data('Complete', true);
						checkPower();
			    }
			);
		});
		
		function checkPower(){
			//check both couplers are connected
			if($("#rightArm").data('Complete') == true && $("#rightArm").data('Complete') == true){
				$("#stand").animate({"top": 0},500, "easeOutBack");
				
				/*$("body").addClass('ultraviola');
				$('h2').css("color","#5235ee");
				$('h3').css("color","#5235ee");
				Cufon.refresh('h2, h3.cufon');*/
				amplitude = 12;
				framesPerCycle = 18;
			} else if($("#leftArm").data('Complete') == true || $("#rightArm").data('Complete') == true){
				amplitude = 6;
				framesPerCycle = 24;
				
			}
			
		}
	//end richards
		
	$('#emailCapture #submit').click(function(){
		
		var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
		$('#emailCapture #error').fadeOut('fast');
		if(document.emailCapture.name.value.match(re)){
			//sign up
			$.get("http://www.mutantlabs.com/signup.php?email="+document.emailCapture.name.value);
			// showthankyou
			$('#emailCapture input').fadeOut('slow', function() {
			    $('#emailCapture #thankyou').fadeIn('slow');
			  });
			  
		} else {
			$('#emailCapture #error').fadeIn('slow');
		}
	
		return false;
	});
	
});

