$(document).ready(function(){
	//Current Nav Tab START
	var urlFull = window.location.pathname;
	var urlFullArray = urlFull.split("/");
	
	switch(urlFullArray[1]){
		case(""):
			$(".navTabContainer a[href='/']").addClass("current")
			break;
		case("about"):
			switch(urlFullArray[2]){
				case("membership"):
					$(".navTabContainer a[href='/about/membership']").addClass("current")
					break;
				default:
					$(".navTabContainer a[href='/about']").addClass("current")
					break;
			}
			break;
		case("news"):
			$(".navTabContainer a[href='/news']").addClass("current")
			break;
		case("vendor"):
			$(".navTabContainer a[href='/vendor']").addClass("current")
			break;
	}
	//Current Nav Tab END
	
	//Prevent Enter from Submitting Form START
	textboxes = $("input:text, input:password");
	
	if ($.browser.mozilla) {
		$(textboxes).keypress(checkForEnter);
	}
	else {
		$(textboxes).keydown(checkForEnter);
	}
	
	function checkForEnter(event) {
		if(event.keyCode == 13){
			event.preventDefault();
			return false;
		}
	}
	//Prevent Enter from Submitting Form END
	
	$(".form").validate({
	   ignore: ".txtLoginEmail, .txtLoginPassword"
	})
	
	$("div.modal")
		.css("background-color", "#FFFFFF")
		.dialog({
			autoOpen : false,
			modal : true,
			width : 640,
			height : 508,
			minWidth : 640,
			minHeight : 508,
			resizable : false,
			title : ""
		})
		.css("overflow", "hidden")
	
	$(".ui-widget-overlay").live("click", function(){
		$("div.modal").dialog("close");
	});
	
	$("a.modal, a[href^='/api/doc/html/?'], a[href^='/api/company/html/?']")
		.click(function(){
			$("div.modal")
				.html("<iframe frameborder=\"0\" width=\"100%\" height=\"100%\" src=\"" + $(this).attr("href") + "\"></iframe>")
				.dialog("open");
			return false;
		})
	
	$(".btnSearch")
		.click(function(){
			if($(".txtSearch").val() == ""){
				alert("Please provide the keywords to search for.");
				return false;
			}
		})
	
	$(".btnLogin")
		.click(function(){
			if($(".txtLoginEmail").valid() == 0 || $(".txtLoginPassword").valid() == 0){
				alert("Invalid email/password.");
				return false;
			};
		})
	
	$(".btnPoll")
		.click(function(){
			if($(".rdoPollOption").valid() == 0){
				return false;
			};
		})
	
	$(".tblPollData")
		.each(function(){
			var total = 0;
			$(this)
				.find(".pnlPollDataCount")
					.each(function(){
						total += parseInt($(this).text());
					});
			$(this)
				.find(".pnlPollDataCount")
					.each(function(){
						$(this).attr("total", total);
					});
		})
	$(".pnlPollDataCount")
		.each(function(){
			var percent = 0;
			$(this)
				.animate({
					"width" : (parseInt($(this).text()) / parseInt($(this).attr("total")) * 191) + 1
				}, 3000)
				.text(Math.round((parseInt($(this).text()) / parseInt($(this).attr("total")) * 100)) + "%");
		});
	
	$(".siteTopText")
		.eq(0)
		.attr("current", 0)
		.fadeIn("slow")
	
	setInterval(
		function(){
			if($(".siteTopText").attr("current") - 0 + 1 >= $(".siteTopText").length){
				$(".siteTopText")
					.fadeOut("fast")
					.attr("current", 0)
				$(".siteTopText")
					.eq(0)
					.delay("slow")
					.fadeIn("slow")
			}
			else{
				$(".siteTopText")
					.fadeOut("fast");
				$(".siteTopText")
					.eq($(".siteTopText").attr("current") - 0 + 1)
					.delay("slow")
					.fadeIn("slow")
				$(".siteTopText")
					.attr("current", $(".siteTopText").attr("current") - 0 + 1)
			}
		}
		, 10000
	)
})

document.write("<div class=\"modal\"></div>")
