// JavaScript Document
var epRightActivated = false;
var epLeftActivated = false;
var clipRightActivated = false;
var clipLeftActivated = false;
var currentEps = 1;
var currentClip = 1;

function buttonCheck(){
	if(currentEps == epDivTotal){
		epRightActivated = false;
		$("#episode_horiz .rightBox").css("background-image","url(images/horizontal_bar_right.png)").css("cursor","default");		
	}
	if(currentEps == 1){
		epLeftActivated = false;
		$("#episode_horiz .leftBox").css("background-image","url(images/Horizontal_bar_left.png)").css("cursor","default");		
	}
	
	if(currentClip == clipDivTotal){
		clipRightActivated = false;
		$("#clip_horiz .rightBox").css("background-image","url(images/horizontal_bar_right.png)").css("cursor","default");		
	}
	if(currentClip == 1){
		clipLeftActivated = false;
		$("#clip_horiz .leftBox").css("background-image","url(images/Horizontal_bar_left.png)").css("cursor","default");		
	}
	
}

function setupEpSliders(){
	
	if(epDivTotal > 1){
		$("#episode_horiz .rightBox").css("background-image","url(images/horizontal_bar_rightoff.png)").css("cursor","pointer");	
			epRightActivated = true;
		for(var i=2; i <= epDivTotal; i++){
			var moveLeft = "#eps"+ i;
			$(moveLeft).css("left","860px");
		}
	}
	
	if(clipDivTotal > 1){
		$("#clip_horiz .rightBox").css("background-image","url(images/horizontal_bar_rightoff.png)").css("cursor","pointer");	
			clipRightActivated = true;
		for(var i=2; i <= clipDivTotal; i++){
			var moveLeft = "#clips"+ i;
			$(moveLeft).css("left","860px");
		}
	}
}

$(function(){
	
	$("#episode_horiz .rightBox").hover(function(){
		if(epRightActivated){
			$("#episode_horiz .rightBox").css("background-image","url(images/horizontal_bar_righton.png)");
		}
	 },function(){
		if(epRightActivated){
			$("#episode_horiz .rightBox").css("background-image","url(images/horizontal_bar_rightoff.png)");
		} 
	 });
	
	$('#episode_horiz .rightBox').click(function(){
		if(epRightActivated){
			var moveOff = "#eps"+ currentEps;
			var moveOn = "#eps"+ (currentEps + 1);
			$(moveOff).animate({left:"-860px"}, 250);
			$(moveOn).animate({left:"0px"},250);
			currentEps++;
			buttonCheck();
			$('#episode_horiz .leftBox').css("background-image","url(images/Horizontal_bar_leftoff.png)").css("cursor","pointer");
			epLeftActivated = true;
		}										 
	 });
	
	$("#episode_horiz .leftBox").hover(function(){
		if(epLeftActivated){
			$("#episode_horiz .leftBox").css("background-image","url(images/Horizontal_bar_lefton.png)");
		}
	 },function(){
		if(epLeftActivated){
			$("#episode_horiz .leftBox").css("background-image","url(images/Horizontal_bar_leftoff.png)");
		} 
	 });
	
	$("#episode_horiz .leftBox").click(function(){
		if(epLeftActivated){
			var moveOff = "#eps"+ currentEps;
			var moveOn = "#eps"+ (currentEps - 1);
			$(moveOff).animate({left:"860px"}, 250);
			$(moveOn).animate({left:"0px"},250);
			currentEps--;
			buttonCheck();
			$("#episode_horiz .rightBox").css("background-image","url(images/horizontal_bar_rightoff.png)").css("cursor","pointer");
			epRightActivated = true;
		}										 
	 });
	
	//FUNCTIONALITY FOR CLIPS BUTTONS
	
	$("#clip_horiz .rightBox").hover(function(){
		if(clipRightActivated){
			$("#clip_horiz .rightBox").css("background-image","url(images/horizontal_bar_righton.png)");
		}
	 },function(){
		if(clipRightActivated){
			$("#clip_horiz .rightBox").css("background-image","url(images/horizontal_bar_rightoff.png)");
		} 
	 });
	
	$('#clip_horiz .rightBox').click(function(){
		if(clipRightActivated){
			var moveOff = "#clips"+ currentClip;
			var moveOn = "#clips"+ (currentClip + 1);
			$(moveOff).animate({left:"-860px"}, 250);
			$(moveOn).animate({left:"0px"},250);
			currentClip++;
			buttonCheck();
			$('#clip_horiz .leftBox').css("background-image","url(images/Horizontal_bar_leftoff.png)").css("cursor","pointer");
			clipLeftActivated = true;
		}										 
	 });
	
	$("#clip_horiz .leftBox").hover(function(){
		if(clipLeftActivated){
			$("#clip_horiz .leftBox").css("background-image","url(images/Horizontal_bar_lefton.png)");
		}
	 },function(){
		if(clipLeftActivated){
			$("#clip_horiz .leftBox").css("background-image","url(images/Horizontal_bar_leftoff.png)");
		} 
	 });
	
	$("#clip_horiz .leftBox").click(function(){
		if(clipLeftActivated){
			var moveOff = "#clips"+ currentClip;
			var moveOn = "#clips"+ (currentClip - 1);
			$(moveOff).animate({left:"860px"}, 250);
			$(moveOn).animate({left:"0px"},250);
			currentClip--;
			buttonCheck();
			$("#clip_horiz .rightBox").css("background-image","url(images/horizontal_bar_rightoff.png)").css("cursor","pointer");
			clipRightActivated = true;
		}										 
	 });
	
	// FUNCTIONALITY FOR SUBMITING REGISTER FORM -------------
	
	$("#actualRegForm").validate({
		errorLabelContainer: ".errorMessage",
		rules: {
			email:{
				required: true,
				email: true
			},
			password:{ required:true, minlength:6, maxlength:18,  },
			confirm: {required:true, equalTo:"#password"},
			first_name:"required",
			last_name:"required",
			month:"required",
			days: "required",
			city: "required",
			state: "required",
			zip_code: "required",
			read: "required"
			
		}, messages:{
			email:{
				required: "Please enter an E-mail Address<br />",
				email: "Please enter a valid E-mail Address<br />"
			},
			password:{ required:"Please enter a password<br />", minlength:6, maxlength:18,  },
			confirm: {required:"Please confirm your password<br />", equalTo:"Confirmation does not match<br />"},
			first_name:"Please enter your first name<br />",
			last_name:"Please enter your last name<br />",
			month:"Please enter a month<br />",
			days: "Please enter a day<br />",
			city: "Please enter your City<br />",
			state: "Please select a State<br />",
			zip_code: "Please enter your Zip Code<br />",
			read: "Please acknowledge you've read the required materials.<br />"
		}
		});
		
		var addComment = true;
		$("#commentForm").hide("fast");
		$(".addComment").click(function(){
			if(addComment){
				$("#commentForm").show("slow");
				$(".addComment").empty().append("Hide");
				addComment = false;
			} else {
				addComment = true;
				$("#commentForm").hide("slow");
				$(".addComment").empty().append("Add Comment");
			}
		});
	
		   
});