(function( $ ){
  $.fn.crumbit = function(options) {
	  var defaults = {
		  url: window.location,
		  first: '<a href="/">Home</a>',
		  list: 'ul',
		  el: 'li'
	  };


	  var opts = $.extend(defaults, options);
	  var location = ""+opts.url+"";

	  var removeAfterHash = location.split("#");
	  var arrayOfOptions = removeAfterHash[0].split("/");
	  var index = 3;
	  var html = '<'+opts.list+'>';

	  html += '<'+opts.el+'>'+opts.first+'</'+opts.el+'>';

	  // from the array indexes 0, 1, 2 are useless.
	  var numberOfElements = arrayOfOptions.length;

	  if(numberOfElements >= 1) {
		  var file = '/';
		  var productNext = false;
		  for(i=index;i<numberOfElements;i++) {
			file += arrayOfOptions[i];
			var name = arrayOfOptions[i];
			name = name.replace(/\-/gi,' ');
			name = name.replace(/\_/gi,' ');
			name = name.replace(/\?.*/gi,'');
			name = name.replace(".htm",'');
			name = toUpper(name);
			if(name.match(".htm")) {

			//} else if(name.match("Helpcentre")) {
                                //name = 'Help Centre';
			} else {
				file += '/';
			}
			if(name.match("Index")) {
			} else {
				if(file.match(".htm/")) {
					file = file.replace(".htm/", ".htm");
				}
				var printFile = file;
				var printName = name;
                                if(name.match("Helpcentre")) {
                                    printName = "Help Centre";
                                    printFile = "/help-centre.htm";
                                }

				if(name.match("Product Details") || name.match("Products")) {
					printName = "Products";
					printFile = "/products.htm";
				}
				if(name.match("Help Me Choose Domestic")) {
					printName = "Help me choose - Residential - Living";
				}
				if(name.match("Help Me Choose Kitchbath")) {
					printName = "Help me choose - Residential - Kitchen and Bathroom";
				}
				if(name.match("News")) {
					printFile = "/news-and-events.htm";
				}
				if(name.match("About Us")) {
					printFile = "/about-us.htm";
				}
				if(name.match("Contact")) {
					printFile = "/contact-us.htm";
				}
				if(name.match("Findus")) {
					printName = 'Find Us';
				}
				var prodTitleRemove = $('h1.productstyle span').html();
				$('h1.productstyle span').remove();
				var prodTitle = $('h1.productstyle').html();
				$('h1.productstyle').append('<span>'+prodTitleRemove+'</span>');

				if(productNext === true && prodTitle != undefined) {
					prodTitle.replace(prodTitleRemove, "");
					printName = prodTitle;
					productNext = false;
				}
				html += '<'+opts.el+'>';
				html += '<a href="'+printFile+'">&raquo; '+printName+'</a>';
				var depHead = $('.department-header-link').attr('id');
				if(name.match("Product Details") && depHead != undefined) {
				 	html += '<'+opts.el+'>';
					html += '<a href="'+$('.department-header-link a').attr('href')+'">&raquo; '+depHead+'</a>'
					html += '</'+opts.el+'>';
					productNext = true;
				}
				html += '</'+opts.el+'>';
			}
		  }
	  }

	  html += '</'+opts.list+'><div class="clear"></div>';
	  this.html(html);



  };
})( jQuery );

