$(document).ready(function(){
	$(".tab_container").tabs();
	$('.tab_container').bind('tabsselect', function(event, ui) {
		ans = xtractFile(location.pathname)
		var fullpath = "";
		if (document.getElementById("hello") != null) {
		  fullpath = ans.path + '/' + $("#hello").attr("value") + '/' + ui.panel.id;
		} else {
		  fullpath = ans.path + '/' + ui.panel.id;
		}
		urchinTracker(fullpath);
	});
	
	function xtractFile(data){
		var m = data.match(/(.*)[\/\\]([^\/\\]+\.\w+)?$/);
	  return {path: m[1], file: m[2]}
	}

	if ($("#hello").attr("value") != "") {
      showTabs($("#hello").attr("value"));    
    }; 

    $("#hello").change(function(){
        showTabs($("#hello").attr("value"));
    });

    function showTabs(value) {
      $("#tabs h2").remove();
      switch (value) {
        case "":
          $("#tabs").hide();
          break;

        case "personal":
          $("#tabs").show().prepend("<h2>CareLink&trade; Personal</h2>");
          $("#manual").load("/includes/help/software/manual.html");
          $("#tutorial").load("/includes/help/software/tutorial.html" );
          $(".tutorial").show();
          $("#faq").load("/includes/help/software/faq.html" );
          $(".faq").show();
        break;
        
        case "professional":
          $("#tabs").show().prepend("<h2>CareLink&trade; Pro</h2>");
          $(".tabs li:eq(1)").addClass("first");
      		$(".tab_container").tabs("select","#manual");
          $("#manual").load("/includes/help/software/manual_pro.html");
          $(".tutorial").hide();
          $("#faq").load("/includes/help/software/faq_pro.html" );
          $(".faq").show();
        break;
        
        case "other":
          $("#tabs").show().prepend("<h2>Other Software</h2>");
          $("#manual").load("/includes/help/software/manual_other.html");
      		$(".tab_container").tabs("select","#manual");
          $(".tutorial").hide();
          $(".faq").hide();
        break;
       
        case "508": 
          $("#tabs").show().prepend("<h2>MiniMed 508 Insulin Pump</h2>");
      		$(".tabs li:eq(1)").addClass("first");
      		$(".tab_container").tabs("select","#manual");
          //$(".first").hide();
          $(".tutorial").hide();
      	  $("#manual").load("/includes/help/otherpumps/508.html");
      	  $(".troubleshooting").show();
      	  $("#troubleshooting").load("/includes/help/otherpumps/508_troubleshooting.html");
      		break;

        case "511":  
    		  $(".tabs li:eq(1)").removeClass("first");
    		  $("#manual").load("/includes/help/otherpumps/511.html");
    		  $("#tutorial").load("/includes/help/insulinpumps/tutorials/all.html" );
          $(".tutorial").show();
      		$(".troubleshooting").hide();
      		$(".tab_container").tabs("select","#tutorial");
          $("#tabs").show().prepend("<h2>MiniMed Paradigm<sup>&reg;</sup> 511 Insulin Pump</h2>");
      		break;

        case "512":
          $(".tutorial").show();
      		$(".tabs li:eq(1)").removeClass("first");
          $("#tabs").show().prepend("<h2>MiniMed Paradigm<sup>&reg;</sup> 512 or 712 Insulin Pump</h2>");
      		$("#tutorial").load("/includes/help/insulinpumps/tutorials/all.html" );
      		$("#manual").load("/includes/help/otherpumps/512.html");
      		$(".troubleshooting").show();
      	  $("#troubleshooting").load("/includes/help/otherpumps/x12_troubleshooting.html");
          break;

        case "515":
    		  $(".tabs li:eq(1)").removeClass("first");
          $(".tutorial").show();
          $("#tabs").show().prepend("<h2>MiniMed Paradigm<sup>&reg;</sup> 515 or 715 Insulin Pump</h2>");
          $("#tutorial").load("/includes/help/insulinpumps/tutorials/all.html" );
          $("#manual").load("/includes/help/otherpumps/515.html");
          $(".troubleshooting").show();
      	  $("#troubleshooting").load("/includes/help/otherpumps/x15_troubleshooting.html");
      		break;			   
      }//end switch on "value"
    }//end function "ShowTabs"
  })