var video = {
	cur_pos: 1,
	max_pos: null,

	scroll: function(direction) {
		if (this.max_pos==null) {
			this.max_pos=Math.ceil($("div.Video", "div.VideoMoreBy").length/5);
			if (this.max_pos==0) { this.max_pos=1; }
		}

		if (this.cur_pos==1 && direction=="prev") { return false; }
		if ((this.cur_pos+1)>this.max_pos && direction=="next") { return false; }
		if (direction=="next") {
			this.cur_pos++;
		} else {
			this.cur_pos--;
		}
		$("div.VideosScroll").animate({
			left: (-1*(this.cur_pos-1)*850)+"px"
		}, "fast");
	},

	buttons_hover: function(container, element) {
		$(element, container).each(
			function() {
				$(this).hover(
					function() {
						var src=this.src.replace('_off', '_on');
						this.src=src;
					},
					function() {
						var src=this.src.replace('_on', '_off');
						this.src=src;
					}
				);
			}
		);
	},

	video_hover: function() {
		$("div.Video").each(function(){
			$(this).hover(
				function() {
					$("div.HoverLayer", this).show();
					$("img.BtnPlay", this).attr("src", $("img.BtnPlay", this).attr("src").replace("_off", "_on"));
				},
				function() {
					$("div.HoverLayer", this).hide();
					$("img.BtnPlay", this).attr("src", $("img.BtnPlay", this).attr("src").replace("_on", "_off"));
				}
			);	
		});
	},

	tab_toggle: function() {
		$("div", "div.Tabs").click(function(){
			$("div", "div.Tabs").removeClass("selected");
			$("div.Videos", "div.VideoMore").hide();
			$("#"+this.className).show();
			$(this).addClass("selected");
		});
	},

	chk_all_comments: function() {
		$("input", "div.Comment2").each(function() {
			this.checked=true;
		});
	},

	del_sel_comments: function() {
		if (confirm("Are sure you want to delete these comments?")) {
			document.forms["del_comments"].submit();
		}
	},

	show_comments: function() {
		$("div.Comment2").show();
	},

	toggle_profanity: function() {
		var profanity=$("#Comments").attr("profanity");
		if (profanity=="on") {
			profanity="off";
		} else {
			profanity="on";
		}

		if (window.location.search!="") {
			self.location=window.location+"&profanity="+profanity;
		} else {
			self.location=window.location+"?profanity="+profanity;
		}
	},

	show_edit_comment: function() {
		if (!user.id) { return non_user('Post a Comment'); }
		$(".postCommentForm").toggle();
		$("textarea", ".postCommentForm").focus();
	},

	googleSearch: function() {
		var q=$("#video_google_cse_q").val();
		if ($.trim(q).length==0) { return false; }
		q=q.replace(/\s/g, '+');
		self.location='/video/search.php?sa=search&q='+escape(q);
		return false;
	}
}