var $j = jQuery.noConflict();

$j(document).ready(function() {

	//Default Action
	$j(".tab_content").hide(); //Hide all content
	$j("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$j(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$j("ul.tabs li").click(function() {
		$j("ul.tabs li").removeClass("active"); //Remove any "active" class
		$j(this).addClass("active"); //Add "active" class to selected tab
		$j(".tab_content").hide(); //Hide all tab content
		var activeTab = $j(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$j(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});

$j(document).ready(function() {

	//Default Action
	$j(".product_tab_content").hide(); //Hide all content
	$j("ul.product_tabs li:first").addClass("active").show(); //Activate first tab
	$j(".product_tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$j("ul.product_tabs li").click(function() {
		$j("ul.product_tabs li").removeClass("active"); //Remove any "active" class
		$j(this).addClass("active"); //Add "active" class to selected tab
		$j(".product_tab_content").hide(); //Hide all tab content
		var activeTab = $j(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$j(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});

$j(document).ready(function() {

	//Default Action
	$j(".hp_tab_content").hide(); //Hide all content
	$j("ul.hp_tabs li:first").addClass("active").show(); //Activate first tab
	$j(".hp_tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$j("ul.hp_tabs li").click(function() {
		$j("ul.hp_tabs li").removeClass("active"); //Remove any "active" class
		$j(this).addClass("active"); //Add "active" class to selected tab
		$j(".hp_tab_content").hide(); //Hide all tab content
		var activeTab = $j(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$j(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

});


// Highlights 2nd/3rd level Nav
// Also display appropriate 3rd level nav item
// Works by comparing href of nav item against the page url
$j(document).ready(function() {


//Highlight selected items based on URL
	$j('.sub-nav-content').hide(); //hide all subnavs
	//Get the url string and split it into category components
	url = jQuery(location).attr('href');
	url = trimUrl(url);
	arr_url = url.split('/'); //split url into categories array // e.g [mydomain.com] [rooms] [kitchen] [whats-new]
	
	//Highlight 1st level nav item
	/*$j('#main-nav').children.each(function(i) {
		var href = $j(this).find('a').attr('href'); //get href of item
		href = trimUrl(href);
		if(arr_url.length==0) {
			//we must be on the homepage
			//$(j
		}
		
	});*/
	

	//Check Each of the links in Nav Level2 - if it's href is contained in the current url, mark it as selected
	$j('.sec-top-lvl').children().each(function(i){
		var href = $j(this).find('a').attr('href'); //get href of item
		href = trimUrl(href);

		if(arr_url.length > 2) { 
			if (href.indexOf(arr_url[2]) >=0) {
/*remove*/		//$j(this).css('background-color','red');
				$j(this).find('a').addClass('active'); //add class active to 2nd level nav item
				nav_index = $j(this).find('a').attr('rel');
				$j('#nav3_'+nav_index).addClass('active'); //mark 3rd level nav as active
				$j('#nav3_'+nav_index).show(); //show the appropriate 3rd level nav
				
				//Highlight 3rd Level Nav
				$j('#nav3_'+nav_index).find('ul').children().each(function(i) {
					href3 = $j(this).find('a').attr('href'); //get href of item
					href3 = trimUrl(href3);

					//output+=href3+'<br/>';
					if(arr_url.length > 3) {
						if (href3.indexOf(arr_url[3]) >=0) {
							$j(this).find('a').addClass('active');
/*remove*/					//$j(this).find('a').css('background-color','red');
						}
					}
				});

			}
		}
		//$j('.page-title').html(output);
	});
	
	function trimUrl(urlString) {
		urlString = urlString.replace('http://www.','');
		urlString = urlString.replace('http://','');
		urlString = urlString.replace('.html','');
		return urlString;
	}
	
	
	/*Rollover show appropriate Nav*/
	//Removed for now - hover doesnt allow clicking subnav
	/*$j('.sec-top-lvl').children().each(function(i){
		$j(this).hover(
			function() {
				nav_index = $j(this).find('a').attr('rel');
				$j('.sub-nav-content.active').hide(); //hide active one
				$j('#nav3_'+nav_index).fadeIn(); //show one being hovered over
			},
			function() {
				nav_index = $j(this).find('a').attr('rel');
				$j('#nav3_'+nav_index).hide(); //hide one being hovered over
				$j('.sub-nav-content.active').fadeIn(); //show active one
			}
		);
	});*/
	
});

/*
Auto run the adj_nav_toolbar_make_request function to pull in the page numbers on page load. 
Only do this for pages which have the dd_limiter dropdown and the right hand layered navigation on display.
Also check adj_nav_toolbar_make_request function exists. this prevents it executing on Whats new pages.
*/
$j(document).ready(function() {
	if($j('#dd_limiter')){
		if(typeof adj_nav_toolbar_make_request == 'function') { 
			var limitererval = document.getElementById('dd_limiter').value;
			adj_nav_toolbar_make_request(limitererval);
		}		
	}
});


