/***********************************************
	Code runs as soon as this JS file is loaded
	Code adds the class 'jsEnabled' to the HTML tag
	--------------------------------------------
	Add the class 'jsEnabled' to the HTML tag on a page.
	Runs as soon as this JS file is loaded, as the html tag
	should be the first tag available and doesn't require the
	documentent to be DOM ready.
***********************************************/
if (document.documentElement && document.getElementById) {
    var docClass = document.documentElement.className != null ? document.documentElement.className : document.documentElement.getAttribute('class');
    docClass =  docClass !='' ? docClass + ' jsEnabled' : 'jsEnabled';
    document.documentElement.setAttribute('class',docClass);
    document.documentElement.className = docClass; //For IE
}


// on document ready...
$(function() {

	/**
		the current top level dropdown is deduced from the breadcrumb ;-)
		if the crumb's second element is a link - use that, stripping the crumbSuffix
		if not, and it's text, use that, finding it after splitting the crumb's text by the crumbDelimiter
	*/
	if($('div.breadcrumb').text().indexOf(' > ')!==-1){ // safety - ensure the breadcrumb is of the proper format and has at least 2 elements
		if(!(topNavToFind = $('div.breadcrumb a:eq(1)').text().replace(/ >/,''))){ // crumbSuffix = ' >'
			splitCrumb = $('div.breadcrumb').text().split(' > ');// crumbDelimiter = ' > '
			topNavToFind = splitCrumb[splitCrumb.length-1];// get the last element of the array = text of crumb last item
		}
		/**
		for all divs with class of inner, containing the exact(case sensitive) text in the crumb's second item, highlight their first parent of the type of LI
		will fail if no case sensitive match (bespoke pages, etc..)
		will misbehave if the exact value of a top level item is found in another 
			- unlikely, if all items only get the first letter Capitalized, also they're departments - will be very different..
		*/
		$("div.inner:contains('"+topNavToFind+"')").parents('li').eq(0).addClass('selected');
	}


	// AKQA...
	if(/MSIE 6/i.test(navigator.userAgent)) {
		// wraps a tags round buttons so the :hover states show up in effing msie 6
		$('input[type=button]').add('input[type=submit]').wrap( '<a href="#"></a>' );
	}
	if(/Firefox/i.test(navigator.userAgent)) {
		$('.custom_input').addClass('firefox_pad');
	}
	$('#utility li:first-child a').addClass('no_background');
	$('#shopping_bag li:last-child a').addClass('no_background');

});
