/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

String.prototype.ucFirst = function () {
    // Split the string into words if string contains multiple words.
    var x = this.split(/\s+/g);
    for (var i = 0; i < x.length; i++) {
        // Splits the word into two parts. One part being the first letter,
        // second being the rest of the word.
        var parts = x[i].match(/(\w)(\w*)/);
        // Put it back together but uppercase the first letter and
        // lowercase the rest of the word.
        x[i] = parts[1].toUpperCase() + parts[2].toLowerCase();
    }
    // Rejoin the string and return.
    return x.join(' ');
};

String.prototype.replaceAll = function(de, para){
    var str = this;
    while (str.indexOf(de) != -1){
        str = str.replace(de, para);
    }
    return (str);
};

String.prototype.contains = function(contem){
    return this.indexOf(contem)!= -1;
};

String.prototype.contido = function(contido){
    return contido.indexOf(this)!= -1;
};

jQuery(function($){
    var $rootUrl = $('input#rootUrl');
    var $breadCrumbs = $('ul.breadcrumbs');

    var urlRelativa = location.href.substring($rootUrl.val().length,location.href.length).replaceAll('-',' ').replaceAll('_',' ');

    $breadCrumbs.append(
        $('<li />').append(
            $('<span />').addClass('ico')
            ).append(
            $('<a />').attr('href',$rootUrl.val()).text('Home')
            )
        )/*.append(
        $('<li />').append(
            $('<span />').addClass('ico')
            ).append(
            $('<a />').attr('href',$rootUrl.val()+urlRelativa.split('/')[0]).click(function(){
                return false;
            }).text(urlRelativa.split('/')[0].ucFirst())
            )
        )*/;

    if(urlRelativa.split('/').length>2){
        $breadCrumbs.append(
            $('<li />').append(
                $('<span />').addClass('ico')
                ).append(
                $('<a />').attr('href','#').click(function(){
                    return false;
                }).text(urlRelativa.split('/')[urlRelativa.split('/').length-2].ucFirst())
                )
            );
    }
});
