

aboutShown = 0;
aboutOver = 0;

mouseX = 0;
mouseY = 0;

$(document).ready(function() {

    $("#aboutUsNavLink").mouseover(showAbout);
    $("#aboutUsNavLink").mouseout(startHideAbout);

    $("#navabout").mouseover(function() { aboutOver = 1; });
    $("#navabout").mouseout(startHideAbout);

    $(".main_expand").click(accordionMySibling);

    $().mousemove(function(e) {
        mouseX = e.pageX;
        mouseY = e.pageY;
    });

    $("#navclient").click(function() {
        window.location = "/Clients.aspx";
    });

    //setup lightubox links
    $('a.lightbox').lightBox();

});

function showAbout() {
    aboutOver = 1;
    if (aboutShown == 0) {
        $('#navabout').css('opacity', 0.7).animate({left: (mouseX-50)+'px'}).slideDown();
        aboutShown = 1;
    }
}

function hideAbout() {
    if (aboutShown == 1 && aboutOver == 0) {
        $('#navabout').slideUp(500);
        aboutShown = 0;
    }
}

function startHideAbout() {
    aboutOver = 0;
    if (aboutShown == 1) {
        setTimeout(hideAbout, 1000);
    }
}

function accordionMySibling(event) {

    var e = event || window.event;
    
    var control = $(this).next();

    if ($(control).is(":visible")) {

        //$(control).slideUp(100);
        $(control).hide();
        
    } else {

        //$(control).css("opacity", 0.01).slideDown(500).fadeTo(1000, 1.0);
        $(control).show('slow');

    }
}



// COOKIE HANDLING OBJECT(S)

function CookieHandler() {

    this.setCookie = function(name, value, seconds) {

        if (typeof (seconds) != 'undefined') {
            var date = new Date();
            date.setTime(date.getTime() + (seconds * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else {
            var expires = "";
        }

        document.cookie = name + "=" + value + expires + "; path=/";
    }

    this.getCookie = function(name) {

        name = name + "=";
        var carray = document.cookie.split(';');

        for (var i = 0; i < carray.length; i++) {
            var c = carray[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
        }

        return null;
    }

    this.deleteCookie = function(name) {
        this.setCookie(name, "", -1);
    }

}

// Returns the string with all the beginning
// and ending whitespace removed
String.prototype.trim = function() {
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
};

// Returns the left x characters of the string
String.prototype.left = function(count) {
    if (this.length > count) {
        return this.substring(0, count);
    }
    else {
        return this;
    }
}

// Returns the right x characters of the string
String.prototype.right = function(count) {
    if (this.length > count) {
        return this.substring(this.length - count, this.length);
    }
    else {
        return this;
    }
}

// Returns true if the string begins with value
String.prototype.startsWith = function(value) {
    if (this.length < value.length) {
        return false;
    }
    else {
        return this.substring(0, value.length) === value;
    }
}

// Returns true if the string ends with value
String.prototype.endsWith = function(value) {
    if (this.length < value.length) {
        return false;
    }
    else {
        return this.substring(this.length - value.length, this.length) === value;
    }
}

// Returns a shortened version of the string
// suffixed with "..." if characters are truncated
// from the original string
String.prototype.shorten = function(maxLength) {
    if (!this) {
        result = null;
    }
    else if (this.length > maxLength) {
        preferredSize = maxLength - '...'.length;
        if (preferredSize > 0) {
            result = this.left(preferredSize) + '...';
        }
        else {
            result = this.left(maxLength);
        }
    }
    else {
        result = this;
    }
    return result;
}
