
/***********************************************
* Load links dynamically
* Load the case study categories
* TODO Load the items within a category
***********************************************/
function loadLinks(categoryId, itemId) {
    //loadCategoryLinks(categoryId);
    // TODO hack while we are hiding categories
    loadCategoryLinks("category" + itemId.toString().substring(4));
    
    //markCurrentCategory(categoryId);
    // TODO hack while we are hiding categories
    markCurrentCategory("category" + itemId.toString().substring(4));
    
    loadItemLinks(categoryId, itemId);
    markCurrentItem(itemId);
    loadquickNavigationLinks();
    setPreviousAndNext(itemId);
}

/***********************************************
* Load the list of categories (on the right column)
***********************************************/
function loadCategoryLinks(categoryId) {
    //document.getElementById("categoryLinks").innerHTML 
      var content = "<ul class=\"casestudy\">" +
	  "<li id=\"category1\"><a href=\"http://www.symiantechnology.com/casestudies/cardiowiz.asp\">Cardio-Monitoring System</a></li>" +
	  "<li id=\"category2\"><a href=\"http://www.symiantechnology.com/casestudies/ems.asp\">EMS - Patient Signal Review and Workflow Management System</a></li>" +
	  "<li id=\"category3\"><a href=\"http://www.symiantechnology.com/casestudies/wlbroker.asp\">WL Broker</a></li>" +
	  "<li id=\"category4\"><a href=\"http://www.symiantechnology.com/casestudies/clinicalreports.asp\">Clinical Reporting Application</a></li>" +
	  "<li id=\"category5\"><a href=\"http://www.symiantechnology.com/casestudies/pdamon.asp\">PDAMon Client</a></li>" +
	  "<li id=\"category6\"><a href=\"http://www.symiantechnology.com/casestudies/dhr.asp\">DHR – Diabetes Personal Health Record for Diabetic Patients</a></li>" +
	  "<li id=\"category7\"><a href=\"http://www.symiantechnology.com/casestudies/cdp.asp\">CDP – core development for PACS company</a></li>" +
	  "<li id=\"category8\"><a href=\"http://www.symiantechnology.com/casestudies/pccg.asp\">PCCG – Development of Web PACS</a></li>" +
	  "<li id=\"category9\"><a href=\"http://www.symiantechnology.com/casestudies/hiportal.asp\">Health insurances smart portal </a></li>" +
      "</ul>";
      // set the current category
      content = content.toString().replace("id=\"" + categoryId + "\"><a ", "id=\"" + categoryId + "\"><a  class=\"current\"");
      document.getElementById("categoryLinks").innerHTML = content;
}

/***********************************************
* Remove the link for the current category
***********************************************/
function markCurrentCategory(categoryId) {
    document.getElementById(categoryId).firstChild.removeAttribute("href");
}

/***********************************************
* Load the items in a category
***********************************************/
function loadItemLinks(categoryId, itemId) {
    var content = "<a id=\"previous\" class=\"previous\">&nbsp;</a>";
    switch (categoryId) {
        case "category1":
            content += "<a id=\"item1\" class=\"number\" href=\"http://www.symiantechnology.com/casestudies/cardiowiz.asp\">1</a>" +
                "<a id=\"item2\" class=\"number\" href=\"http://www.symiantechnology.com/casestudies/ems.asp\">2</a>" +
                "<a id=\"item3\" class=\"number\" href=\"http://www.symiantechnology.com/casestudies/wlbroker.asp\">3</a>" +
                "<a id=\"item4\" class=\"number\" href=\"http://www.symiantechnology.com/casestudies/clinicalreports.asp\">4</a>" +
                "<a id=\"item5\" class=\"number\" href=\"http://www.symiantechnology.com/casestudies/pdamon.asp\">5</a>" +
                "<a id=\"item6\" class=\"number\" href=\"http://www.symiantechnology.com/casestudies/dhr.asp\">6</a>" +
                "<a id=\"item7\" class=\"number\" href=\"http://www.symiantechnology.com/casestudies/cdp.asp\">7</a>" +
                "<a id=\"item8\" class=\"number\" href=\"http://www.symiantechnology.com/casestudies/pccg.asp\">8</a>" +
                "<a id=\"item9\" class=\"number\" href=\"http://www.symiantechnology.com/casestudies/hiportal.asp\">9</a>";
            break;
        case "category2":
            content += "<a id=\"item1\" class=\"number\" href=\"http://www.symiantechnology.com/casestudies/categorytest1.asp\">1</a>";
            break;
    }
    //set the current item
    content += "<a id=\"next\" class=\"next\">&nbsp;</a>";

    if (parseInt(itemId.toString().substring(4)) < 10) 
        content = content.toString().replace("id=\"" + itemId + "\" class=\"number\"", "id=\"" + itemId + "\" class=\"current\"");
    else
        content = content.toString().replace("id=\"" + itemId + "\" class=\"numberdouble\"", "id=\"" + itemId + "\" class=\"currentdouble\"");
    document.getElementById("categoryItemLinks").innerHTML = content;
}

/***********************************************
* Remove the link for the current item
***********************************************/
function markCurrentItem(itemId) {
    document.getElementById(itemId).removeAttribute("href");
}

function loadquickNavigationLinks() {
    document.getElementById("quickNavigation").innerHTML = "<a id=\"quickprevious\" class=\"previous\">&nbsp;</a>" +
        "<a id=\"quicknext\" class=\"next\">&nbsp;</a>";
}

/***********************************************
* Set the links for next and previous items
***********************************************/
function setPreviousAndNext(itemId) {
    var currentItemNumber = parseInt(itemId.toString().substring(4));
    if (itemId != "item1") {
        var previousId = "item" + (currentItemNumber - 1);
        document.getElementById("previous").setAttribute("href", document.getElementById(previousId).getAttribute("href"));
        document.getElementById("quickprevious").setAttribute("href", document.getElementById(previousId).getAttribute("href"));
    }
    else {
        document.getElementById("previous").style.backgroundImage = "url(http://www.symiantechnology.com/images/previous_disabled.png)";
        document.getElementById("quickprevious").style.backgroundImage = "url(http://www.symiantechnology.com/images/previous_disabled.png)";
    }
    var maxItemNumber = document.getElementById("categoryItemLinks").childNodes.length - 2;
    
    if (itemId != "item" + maxItemNumber) {
        var nextId = "item" + (currentItemNumber + 1);
        document.getElementById("next").setAttribute("href", document.getElementById(nextId).getAttribute("href"));
        document.getElementById("quicknext").setAttribute("href", document.getElementById(nextId).getAttribute("href"));
    }
    else {
        document.getElementById("next").style.backgroundImage = "url(http://www.symiantechnology.com/images/next_disabled.png)";
        document.getElementById("quicknext").style.backgroundImage = "url(http://www.symiantechnology.com/images/next_disabled.png)";
    }
}