jQuery(function(){

	//Sets the "Current" class on the current menu item.
	//Get page file name
	var pagefile = document.location.href;
	var pagefilelength = pagefile.length;
	var filenamestart = pagefile.lastIndexOf("/");
	pagefile = pagefile.substring(filenamestart, pagefilelength);

	
	
	//Find Primary Nav items that are current.
	var menuitemhref
	jQuery('#PrimaryNavigation ul li').children('a').each(function(){
		menuitemhref = jQuery(this).attr('href');
		if (menuitemhref.indexOf(pagefile) > -1){
			(jQuery(this).addClass('selected'));
		}
	});
	
	//Adds selected class to the parent li on child ul hover.
	jQuery('#PrimaryNavigation ul li').children('ul').hover(
		function () {
		jQuery(this).parent().addClass('selected');
		}, 
		function () {
		jQuery(this).parent().removeClass('selected');
		}
	);
	
	//Adds the selected class to the homelink if no filename is present.
	if (pagefile == "/"){
		jQuery('#PrimaryNavigation .selected').removeClass('selected');
		jQuery('#nav_14623 li:first').addClass('selected');
	}
	
	
	// Hides the Case Number in the contact form submission content.
	jQuery('#casenumber').parent('tr').hide();
	
	
	//Provides the  functionality.
	if(jQuery('.newColourChart').length > 0){
		
		//Turn all ToolTips off.
		jQuery('#off').hover(function(){
			jQuery('.newColourChart #ttpurple').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgreen').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttwhite').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttpink').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgrey').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttbrown').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttturquoise').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttblack').fadeOut(400).stop(true, true);
		}, function(){
		});
		
		//Purple
		jQuery('#RH25').hover(function(){
			jQuery('.newColourChart #ttgreen').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttwhite').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttpink').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgrey').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttbrown').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttturquoise').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttblack').fadeOut(400).stop(true, true);
			if(jQuery('.newColourChart #ttpurple').css('display') == 'none'){
				jQuery('.newColourChart #ttpurple').fadeIn(400);
			}
		});
		
		//Dark Green
		jQuery('#RH12').hover(function(){
			jQuery('.newColourChart #ttpurple').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttwhite').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttpink').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgrey').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttbrown').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttturquoise').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttblack').fadeOut(400).stop(true, true);
			if(jQuery('.newColourChart #ttgreen').css('display') == 'none'){
				jQuery('.newColourChart #ttgreen').fadeIn(400);
			}
		});
		
		//White
		jQuery('#RH80').hover(function(){
			jQuery('.newColourChart #ttpurple').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgreen').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttpink').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgrey').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttbrown').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttturquoise').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttblack').fadeOut(400).stop(true, true);
			if(jQuery('.newColourChart #ttwhite').css('display') == 'none'){
				jQuery('.newColourChart #ttwhite').fadeIn(400);
			}
		});
		
		//Pink
		jQuery('#RH90').hover(function(){
			jQuery('.newColourChart #ttpurple').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgreen').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttwhite').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgrey').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttbrown').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttturquoise').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttblack').fadeOut(400).stop(true, true);
			if(jQuery('.newColourChart #ttpink').css('display') == 'none'){
				jQuery('.newColourChart #ttpink').fadeIn(400);
			}
		});
		
		//Grey
		jQuery('#RH65').hover(function(){
			jQuery('.newColourChart #ttpurple').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgreen').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttpink').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttwhite').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttbrown').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttturquoise').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttblack').fadeOut(400).stop(true, true);
			if(jQuery('.newColourChart #ttgrey').css('display') == 'none'){
				jQuery('.newColourChart #ttgrey').fadeIn(400);
			}
		});
		
		//Brown
		jQuery('#RH33').hover(function(){
			jQuery('.newColourChart #ttpurple').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgreen').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttpink').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttwhite').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgrey').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttturquoise').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttblack').fadeOut(400).stop(true, true);
			if(jQuery('.newColourChart #ttbrown').css('display') == 'none'){
				jQuery('.newColourChart #ttbrown').fadeIn(400);
			}
		});
		
		//Turquoise
		jQuery('#RH26').hover(function(){
			jQuery('.newColourChart #ttpurple').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgreen').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttpink').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttwhite').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgrey').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttbrown').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttblack').fadeOut(400).stop(true, true);
			if(jQuery('.newColourChart #ttturquoise').css('display') == 'none'){
				jQuery('.newColourChart #ttturquoise').fadeIn(400);
			}
		});
		
		//Black
		jQuery('#RH70').hover(function(){
			jQuery('.newColourChart #ttpurple').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgreen').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttpink').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttwhite').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttgrey').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttbrown').fadeOut(400).stop(true, true);
			jQuery('.newColourChart #ttturquoise').fadeOut(400).stop(true, true);
			if(jQuery('.newColourChart #ttblack').css('display') == 'none'){
				jQuery('.newColourChart #ttblack').fadeIn(400);
			}
		});
	}

	//Provides the Sparckle Colour Wheel and TPV New Colour Wheel functionality.
	if(jQuery('.colourChart').length > 0){
		
		//Turn all ToolTips off.
		jQuery('#ttOff').hover(function(){
			jQuery('.colourChart #red').fadeOut(400).stop(true, true);
			jQuery('.colourChart #blue').fadeOut(400).stop(true, true);
			jQuery('.colourChart #yellow').fadeOut(400).stop(true, true);
			jQuery('.colourChart #green').fadeOut(400).stop(true, true);
		}, function(){
			
		});
		
		//Blue
		jQuery('#ttBlue').hover(function(){
			jQuery('.colourChart #red').fadeOut(400).stop(true, true);
			jQuery('.colourChart #green').fadeOut(400).stop(true, true);
			jQuery('.colourChart #yellow').fadeOut(400).stop(true, true);
			if(jQuery('.colourChart #blue').css('display') == 'none'){
				jQuery('.colourChart #blue').fadeIn(400);
			}
		});
		//Green
		jQuery('#ttGreen').hover(function(){
			jQuery('.colourChart #red').fadeOut(400).stop(true, true);
			jQuery('.colourChart #blue').fadeOut(400).stop(true, true);
			jQuery('.colourChart #yellow').fadeOut(400).stop(true, true);
			if(jQuery('.colourChart #green').css('display') == 'none'){
				jQuery('.colourChart #green').fadeIn(400);
			}
		});
		//Red
		jQuery('#ttRed').hover(function(){								   
			jQuery('.colourChart #green').fadeOut(400).stop(true, true);
			jQuery('.colourChart #blue').fadeOut(400).stop(true, true);
			jQuery('.colourChart #yellow').fadeOut(400).stop(true, true);
			if(jQuery('.colourChart #red').css('display') == 'none'){
				jQuery('.colourChart #red').fadeIn(400);
			}
		});
		//Yellow
		jQuery('#ttYellow').hover(function(){
			jQuery('.colourChart #green').fadeOut(400).stop(true, true);
			jQuery('.colourChart #blue').fadeOut(400).stop(true, true);
			jQuery('.colourChart #red').fadeOut(400).stop(true, true);
			if(jQuery('.colourChart #yellow').css('display') == 'none'){
				jQuery('.colourChart #yellow').fadeIn(400);
			}
		});
	}
	
	/* Photo Gallery */
	if(jQuery('.photogalleryTable').length > 0){
		jQuery('.photogalleryTable td img').each(function(){
			jQuery(this).parent('a').append('<span class="caption">' + jQuery(this).attr('alt') + '</span>');
		});
	}
	
});
