﻿

/// <reference path="jquery-1.3.2-vsdoc2.js" />

//////////////////////////////////////////////////////////////////////////////////
//Logic for getting and setting cookie data for the project                     // 
//links.                                                                        //
//////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////
//Author:   Stephen Zsolnai                                                     //
//Date:     03/02/2010                                                          //
//////////////////////////////////////////////////////////////////////////////////

var currentProjectID; //Set on page load from the master page
var LinkCookie = 'test_cookie';
var anotherLinkCookie = 'additional';
var options = { path: '/', expires: 10 };


$(document).ready(function() {

    //Highlight the link for the current project and then process the rest.
    $("#projLink" + currentProjectID).addClass("active");
    getLinksFromCookie()
});



function getLinksFromCookie() {

    if (!($.cookie(LinkCookie))) {

        //Cookie does not exist so create it.
        $.cookie(LinkCookie, currentProjectID, options);
    } else {

        //Cookie exists now break it down into array.
        var cookieArray = $.cookie(LinkCookie).split(',');

        //Use all values in array to highlight the visited links.
        for (var i = 0; i < cookieArray.length; i++) {
            $("#projLink" + cookieArray[i]).addClass("visited");
        }
        //add this pages id to cookie if it doesn't exist there already.
        //inArray returns '0 - length' if value is matched. '-1' if not.
        if ($.inArray(currentProjectID + "", cookieArray) == '-1') {
            
            //No match has been found in the cookie for the current project id so append it.
            var oldCookie = $.cookie(LinkCookie)
            $.cookie(LinkCookie, oldCookie + ',' + currentProjectID, options);
        }
    }

    //use this to delete cookie
    //$.cookie(LinkCookie, null, options);

}
