﻿function xtractExt(fullPath) {
    firstDot = fullPath.firstIndexOf("/")
    return fileName = fullPath.substring(firstDot + 1, fullPath.length);
}
function xtractPath(fullPath) {
    directory = fullPath.substring(0, lastSlash)
    return fileName = fullPath.substring(lastSlash + 1, fullPath.length);
}
function xtractFile(fullPath) {
    lastSlash = fullPath.lastIndexOf("/")
    return fileName = fullPath.substring(lastSlash + 1, fullPath.length);
}
function appendTrailingSlash(str) {
    if (str[str.length - 1] != '/')
        str += '/';
    return str;
}
function isSubPath(src, dst) {
    if (dst.toLowerCase().indexOf(src.toLowerCase()) == 0)
        return true;
    return false;
}
function swapChar(s, c, x) {
    /*
    ** Remove NewLine, CarriageReturn and Tab characters from a String
    **   s  string to be processed
    ** returns new string
    */
    r = "";
    for (i = 0; i < s.length; i++) {
        if (s.charAt(i) == c) {
            r += x;
        }
        else {
            r += s.charAt(i);
        }
    }
    return r;
}
function removeChar(s, c) {
    /*
    ** Remove NewLine, CarriageReturn and Tab characters from a String
    **   s  string to be processed
    ** returns new string
    */
    r = "";
    for (i = 0; i < s.length; i++) {
        if (s.charAt(i) != c) {
            r += s.charAt(i);
        }
    }
    return r;
}
PEPS = {};

PEPS.rollover =
        {
            init: function(cs) {
                this.preload();
                if (cs == undefined)
                    cs = ".ro";
                $(cs).each(function(i) {
                    if ($(this).data("hovered") == undefined) {
                        $(this).hover(
                            function() { $(this).attr('src', PEPS.rollover.newimage($(this).attr('src'))); },
                            function() { $(this).attr('src', PEPS.rollover.oldimage($(this).attr('src'))); }
                        );
                    }
                    else {
                        $(this).data("hovered", "hovered");
                    }

                });

            },

            preload: function() {
                $(window).bind('load', function() {
                    $('.ro').each(function(key, elm) { $('<img>').attr('src', PEPS.rollover.newimage($(this).attr('src'))); });
                });
            },

            newimage: function(src) {
                return src.substring(0, src.search(/(\.[a-z]+)$/)) + '_o' + src.match(/(\.[a-z]+)$/)[0];
            },

            oldimage: function(src) {
                return src.replace(/_o\./, '.');
            }
        };
        
