$(function(){
	inputreset();
	movepagination();
	removepagination();
	$("ul.latestVideos li:nth-child(4n+4)").css("margin-right","0");
});



function home(){
	$('#slides').before('<ul id="slideNav">')
	.cycle({
		fx: 'fade',
		speed: 2000,
		timeout: 6000,
		pager: '#slideNav',
		// callback fn that creates a thumbnail to use as pager anchor 
		    pagerAnchorBuilder: function(idx, slide) { 
		        return '<li><a href="#">•</a></li>'; 
		    }
	});
	
	$('#topPlaysSlide').before('<ul id="playNav">')
	.cycle({
		fx: 'scrollHorz',
		speed: 900,
		timeout: 0,
		next:   '#next', 
		prev:   '#prev',
		pager: '#playNav',
		// callback fn that creates a thumbnail to use as pager anchor 
		    pagerAnchorBuilder: function(idx, slide) { 
		        return '<li><a href="#">•</a></li>'; 
		    }
	});
	if ($('#subContent').length) { // implies *not* zero
     $("#content").addClass("noRadiusBottom");
  } else {
    //no idea if something should go here
  }
}




function ratings(id){
	$('.rating a').live("click",function(){
		var clicked = $(this);
		var rating = clicked.text();
		$("#rating_field").val(rating);
		//alert($("#rating_field").val());
		//submit the form
		$(".rating_form").ajaxSubmit({
		    success: function() {
			$(".rating").load("/index.php/embeds/rating_form/"+id+"");
		    }
		});
		return false;
	});
}

function inputreset(){
	$(".search").focus(function(){
		var val = $(this).val();
		if(val == "Search..." || val == "Search for videos"){
			$(this).val("");
		}
	}).blur(function(){
		var val = $(this).val();
			if(val == ""){
				$(this).val("Search...");
			}
		});
		
		//main page email
		$("#email_signup").focus(function(){
			var val = $(this).val();
			if(val == "Email Address"){
				$(this).val("");
			}
		}).blur(function(){
			var val = $(this).val();
				if(val == ""){
					$(this).val("Email Address");
				}
			});
			
			$("#password_signup").focus(function(){
				var val = $(this).val();
				if(val == "Password"){
					$(this).val("");
				}
			}).blur(function(){
				var val = $(this).val();
					if(val == ""){
						$(this).val("Password");
					}
				});
}

function status_update(){
	$("#status_form textarea").keypress(function (e) {
		
	        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
				
				$("#status_form").ajaxSubmit({
				    success: function() {
					$("#status_form textarea").text("");
					$(".status_update .status_update_contain").load("/index.php/player/update_status");
					$("#timeline").load("/index.php/player/timeline");
				    }
				});
				
				return false;
				
	        } else {
	            return true;
	        }
	    });
	
}

function movepagination(){
	$(".videoPagination").insertAfter($('.paginate_after'));
}


function removepagination(){
	//If #subContent exists, then remove the rounded bottom corners of #content... seriously, I know, but per PSD
			if ($('#subContent').length) { // implies *not* zero
		     $("#content").addClass("noRadiusBottom");
		  } 
	
}




