$(document).ready(function(){
	/*
	#tab_ask
	#tab_idea
	#tab_problem
	#tab_faq

	#contact_dialog
	#subject_ask
		sel_ask
	#faq_ask
	#subject_problem
		sel_problem
			option name="help"
			option name="bug"
	#product_list
		select products
	*/
	function change_tab(tab_id)
	{
		$("#tab_ask").removeClass("on");
		$("#tab_faq").removeClass("on");
		$("#tab_problem").removeClass("on");
		$("#tab_idea").removeClass("on");

		$(tab_id).addClass("on");

		$("#faq_ask_forum").hide();
		$("#faq_ask_presale").hide();
					
		if (tab_id == "#tab_ask")
		{
			$("#contact_dialog").removeClass().addClass("contact_dialog_blue");
			$("#label_msg").text("Your Question(s):");
			$("#instruct").text("Please be as specific as possible.");
		}
		else if (tab_id == "#tab_idea")
		{
			$("#contact_dialog").removeClass().addClass("contact_dialog_yellow");
			$("#label_msg").text("Tell us more about your idea:");
			$("#instruct").text("Please be as specific as possible.");
		}
		else if (tab_id == "#tab_problem")
		{
			$("#contact_dialog").removeClass().addClass("contact_dialog_red");
			$("#label_msg").text("Describe the problem:");
			$("#instruct").text("Please include a URL, screenshot or anything else that might help us fix your problem.");
		}
		else if (tab_id == "#tab_faq")
		{
			$("#contact_dialog").removeClass().addClass("contact_dialog_green");
		}
	}
	
	function hide_tab_content(exception)
	{
		$("#subject_ask").hide();
		$("#subject_problem").hide();
		$("#product_list").hide();
		$("#contact_faq_list").hide();
		$("#faq_ask_presale").hide();
		
		if (exception)
		{
			$(exception).show();
		}
	}

	hide_tab_content("#subject_ask");
	$('select[name="sel_ask"]').change(function(){

		var list_name = $('select[name="sel_ask"] option:selected').attr("name");
		if (list_name == "presale")
		{
			$("#faq_ask_forum").hide("fast");
			$("#faq_ask_presale").slideDown("normal");

		} else if (list_name == "forum" ) { 

			$("#faq_ask_presale").hide("fast");
			$("#faq_ask_forum").slideDown("normal");

		}
		else
		{
			$("#faq_ask_presale").hide("fast");
			$("#faq_ask_forum").hide("fast");
		}
	});
		
	$("#a_ask").click(function() {
		$("#contact_dialog  form").show();

		change_tab("#tab_ask");
		hide_tab_content("#subject_ask");
	
		$('select[name="sel_ask"] option:selected').attr("selected", "");
		
		$("input[name='tab']").val("ask");
		return false;
	});
	
	$("#a_idea").click(function() {
		$("#contact_dialog form").show();
			
		change_tab("#tab_idea");
		hide_tab_content();
		
		$("input[name='tab']").val("idea");
		return false;
	});
	
	
	$("#a_problem").click(function() {
		$("#contact_dialog form").show();
			
		change_tab("#tab_problem");
		hide_tab_content("#subject_problem");
		
		$('select[name="sel_problem"] option:selected').attr("selected", "");
		$('select[name="sel_problem"]').change(function(){
			var opt_name = $('select[name="sel_problem"] option:selected').attr("name");
			if (opt_name == "bug" || opt_name == "help")
			{
				$("#product_list").show("normal");
				$("#faq_ask_forum").hide("normal");
				
			} else if (opt_name == "forum") {
			
				$("#product_list").hide("normal");
				$("#faq_ask_forum").slideDown("normal");
			}
			else
			{
				$('select[name="products"] option:selected').attr("selected", "");
				$("#product_list").hide("normal");
				$("#faq_ask_forum").hide("normal");
			}
		});

		
		$("input[name='tab']").val("problem");
		return false;
	});
	
	$("#a_faq").click(function() {
		$("#contact_dialog form").hide();
		change_tab("#tab_faq");
		$("#contact_faq_list").show();
		//hide_tab_content();
		return false;
	});	

});
