$(document).ready( function() {
	//$.ajaxTimeout(8000);
	$("div#faqcontent").ajaxSend( function (){
		$(this).children().remove(".msg");
		$(this).addClass("ajaxloads");
		});

	$("div#faqcontent").ajaxError( function(request, settings){
		$(this).removeClass("ajaxloads");
		$(this).prepend("<div class=\"msg\">ERROR</div>");
	});

	$.getJSON("ajax_cat.php", { cat: 9 } , function (json) {
		for ( i = 0 ; i < json.length ; i++ ) {
			if( json[i].title == $("input#dl_product").val() || $("input#dl_product").val() == "技術支援" || $("input#dl_product").val() == "產品問答" ) {
				if ( $("input#dl_product").val() != "技術支援" && $("input#dl_product").val() != "產品問答" )
					$(".CatSel").val(json[i].id);
			  	dk = json[i].child;
				for ( j = 0 ; j < dk.length; j++) {
					if( dk[j].content == "" ) 
						dk[j].content = "NONE";
					$("div#faqcontent dl").append("<dt>"+dk[j].title+"</dt><dd>"+dk[j].content+"</dd>");
					}
				}
			}
		$('div#faqcontent dl').find('dd').hide().end().find('dt').click( function() {
			$(this).next().slideToggle("slow", function() { 
				if( parseInt($('div.rsidebar').height()) > parseInt($('div.lsidebar').height()) ) 
					$('div.lsidebar').css("height",parseInt($('div.rsidebar').height())+30);
				if( parseInt($('div.lsidebar').height()) - parseInt($('div.rsidebar').height()) > 200 )  
					$('div.lsidebar').css("height",parseInt($('div.rsidebar').height())+100);
				});
			});
		$("div#faqcontent").removeClass("ajaxloads");
		if( parseInt($('div.rsidebar').height()) > parseInt($('div.lsidebar').height()) ) 
			$('div.lsidebar').css("height",parseInt($('div.rsidebar').height())+30);
		if( parseInt($('div.lsidebar').height()) - parseInt($('div.rsidebar').height()) > 200 )  
			$('div.lsidebar').css("height",parseInt($('div.rsidebar').height())+100);
		$("div#faqcontent").fadeIn("normal");
		});
	$("form#Catform").submit( function(){ 
		$.getJSON("ajax_cat.php", { cat: 9 } , function (json) {
			$("div#faqcontent dl").empty();
			for ( i = 0 ; i < json.length ; i++ ) {
				if( json[i].id == $(".CatSel").val() || $(".CatSel").val() == "9" ) {
				  	dk = json[i].child;
					for ( j = 0 ; j < dk.length; j++) {
						if( dk[j].content == "" ) 
							dk[j].content = "NONE";
						$("div#faqcontent dl").append("<dt>"+dk[j].title+"</dt><dd>"+dk[j].content+"</dd>");
						}
					}
				}
				$('div#faqcontent dl').find('dd').hide().end().find('dt').click( function() {
					$(this).next().slideToggle("slow", function() { 
						if( parseInt($('div.rsidebar').height()) > parseInt($('div.lsidebar').height()) ) 
							$('div.lsidebar').css("height",parseInt($('div.rsidebar').height())+30);
						if( parseInt($('div.lsidebar').height()) - parseInt($('div.rsidebar').height()) > 200 )  
							$('div.lsidebar').css("height",parseInt($('div.rsidebar').height())+100);
						});
					});
			$("div#faqcontent").removeClass("ajaxloads");
			if( parseInt($('div.rsidebar').height()) > parseInt($('div.lsidebar').height()) ) 
				$('div.lsidebar').css("height",parseInt($('div.rsidebar').height())+30);
			if( parseInt($('div.lsidebar').height()) - parseInt($('div.rsidebar').height()) > 200 )  
				$('div.lsidebar').css("height",parseInt($('div.rsidebar').height())+100);
			$("div#faqcontent").fadeIn("normal");
			});
		return false;
	});
});


