$(document).ready(function() {
	var speed = 0;
			// showing the sub menu
			$("ul.level1 li").hover(
				function() {
					$(this).children("ul.level1 li ul").slideDown(speed);
				},
				function() {
					$(this).children("ul.level1 li ul").slideUp(speed);
				}
			);
			
			// showing the sub sub menu
			$("ul.level1 li ul li").hover(
				function() {
					$(this).children("ul.level1 li ul li ul").show(speed);
				},
				function() {
					$(this).children("ul.level1 li ul li ul").hide(speed);
				}
			);
			
			// hover color, don't affect the first button
			$("ul.level1 li[class!=firstButton]").hover(
				function() {
					oldBgColor = $(this)[0].style.backgroundColor;
					$(this).css("background-color","#5c9ed4");
				},
				function() {
					$(this).css("background-color",oldBgColor);
				}
			);
});





function forumLoad() {
	
	$("a").click(function(event){
		var href = $(this).attr("href");
		if (href && href.match("cgi.ebay.")) {
			$.post("/frontpageMods/ebay.php",{url:href},function(new_url){
				window.location=new_url;
			});
			event.returnValue = false;
			return false;
		} else {
			return true;
		}
	});
	
	$("a").click(function(event){
		var href = $(this).attr("href");
	try {
			if (href && href.match("http://www.ebay") || href.match("http://ebay")) {
			var newLink ="http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=1&pub=5574840065&toolid=10001&campid=5336355229&customid=&ipn=psmain&icep_vectorid=229466&kwid=902099&mtid=824&kw=lg";
			$(this).attr("href",newLink);
			
		}
		} catch(e) {}
	});
	
	
	if($("#vB_Editor_001_textarea")[0]) {
		$("#vB_Editor_001_textarea")[0].style.width = "650px";
		$("#vB_Editor_001_textarea").keyup(function() {
			$("#charCount").val($("#vB_Editor_001_textarea").val().length);
		});
	}
	
	$("#cb_1").change(function() {
		if($("#cb_1")[0].checked) {
			$.post("/vbulletin/getTechEvents.php", function(data){
			  $("#cb_1").parent().parent().append(data);
			});
		} else {
			$("#techEventsDrop").hide();
		}
	});
	
	
	/*
	// this function controls re writing the links for ebay when you choose
	// to open in a new tab.  Not active on the live forum yet
	$("a").rightMouseDown(function(){
		var href = $(this).attr("href");
		if (href.match("cgi.ebay.")) {
			var regex= /(item=|itemZ).*?([0-9]+)/i;
			var myArray = regex.exec(href);
			var item = myArray[2];
			var newLink ="http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=2&pub=5574840065&toolid=10001&campid=5336355221&customid=&icep_item="+item+"&ipn=psmain&icep_vectorid=229466&kwid=902099&mtid=824&kw=lg";
			$(this).attr("href",newLink);
		}	
	});
	*/

}	

var shareBoxIsOpen = false;

function prepBlog() {
$(document).ready(function() {
		
		
		
		// width fix for real forum
		$("div.page").attr("style","");

		// hide all the read more stuffs
		$(".rest").hide();
		// controls the slide up and slide down for clicking the read more link
		$(".readMore").click(function() {
			$a = $(this);
			$(this).parent().siblings(".rest").slideToggle("slow",function() {
				if ($a.html() == "Read More") {
					$a.html("Read Less");
				} else {
					$a.html("Read More");
				}
			});
				return false;
		});
		
		//liveInt = setInterval("check4LivePosts()",3000);
		
		if (window.location.href.match("videos")) {
		$(".draglist").css("list-style-type","none");
		}
		
		$(".shareLink").hover(
			function() {
				if(currentOpenShareBox) closeShare();
				clearTimeout(closeShareTimer);
				$(this).next("div").show();
				currentOpenShareBox = $(this).next("div");
			}, function() {
				closeShareTimer = setTimeout("closeShare()",500);
			}
		);
		
		$(".shareLink").next("div").hover(
			function() {
				clearTimeout(closeShareTimer);
				$(this).next("div").show();
			}, function() {
				closeShareTimer = setTimeout("closeShare()",500);
				
			}
		);
		
		
		
		
	});
}

function closeShare() {
	currentOpenShareBox.hide();
	currentOpenShareBox = null;
}
var closeShareTimer;
var currentOpenShareBox = null;

// when you are posting a blog and choose a new event, this will use ajax to add it to the list
function newEvent() {
	var shortName = prompt("What is the Abbreviation for this event?");
	if(shortName) var longName = prompt("What is the FULL name for this event?");
		if(longName) {
		$.post("newTechEvent.php", { shortName: shortName, longName: longName },function(data) {
			$("#techEventsDrop").replaceWith(data);
		});
	}
}




// global js var to keep track of the last date of the last ajax loaded post
lastDate = 0;
// this function is run every x seconds and checks for a new post
// if it finds one it puts it in the list
function check4LivePosts() {
	$(document).ready(function() {
		kill6thPost(); // make sure there are only 5
		$.post("/vbulletin/livePost.php", {},
		  function(data){
			if (data.dateline > lastDate) {
				if (data.title == "") {
					data.title = data.pagetext.substr(0,32);
					data.title += "...";
				}
				$("#liveParent").prepend("<li><a href='/vbulletin/showthread.php?p="+data.postid+"#"+data.postid+"'>"+data.title+"</a></li>");
				blink($("#liveParent > li:first-child"))
				lastDate = data.dateline;
			}
			kill6thPost(); // make sure there are only 5
		  },"json");
	});
}

function check4LivePostsa() {
	$(document).ready(function() {
		kill6thPost(); // make sure there are only 5
		$.post("/vbulletin/livePost.php", {},
		  function(data){
			$("#liveParent").prepend(data);
		  });
	});
}

// kills the 6th live post if there is one
function kill6thPost() {
	if($("#liveParent > li").get().length > 5) {
		$("#liveParent > li:last-child").remove();
	}
}

// takes a  jquery object and blinks it.
function blink(jelm) {
	jelm.fadeOut("slow");
	jelm.fadeIn("slow");
}	
	
// slides down the login box
function slideLogin() {
	$(document).ready(function() {
		$("#topLogin").toggle(1000);
	});
}
	

function subNewThread() {
	
	// fill the text area with rich text if you can
	if ($("#vB_Editor_001_iframe")[0] && $("#vB_Editor_001_iframe")[0].contentDocument.body.innerHTML != "<br>") {
		$("#vB_Editor_001_textarea").val($("#vB_Editor_001_iframe")[0].contentDocument.body.innerHTML);
	}	
	
	
	if($("#tag_input").val() != "") {
		if( $("#cb_1")[0].checked ||
			$("#cb_2")[0].checked ||
			$("#cb_3")[0].checked ||
			$("#cb_4")[0].checked ||
			$("#cb_5")[0].checked) {
			if($("[name=title]").val() != "") {
				if($("#vB_Editor_001_textarea").val() != "" && $("#vB_Editor_001_textarea").val() != "<br>") {
					document.vbform.action = "/vbulletin/newthreadblog.php";
					document.vbform.submit();
				} else alert("You need to enter a message");	
			} else alert("You need to have a title");
		} else alert("You need to choose at least 1 category");	
	} else alert("You need to put some tags");

}

