


$(window).load(function(){
	
/**SOLUTIONS FINDER APP - START**/
	var healthModal; //used to store currently opened modal window

	
	/*Tabs*/
	$("#solutions-nav a").click(function () {  
		$('.hotspot-info .modal-close').click(); //Close all hotspots
		
		$("#solutions-nav a.selected").removeClass("selected");
		
		$(this).addClass("selected");
		
		$(".tab-content").removeClass('selected').hide();
		
		
		var content_show = $(this).attr("rel");
		
  		$(".tab-content."+content_show).addClass('selected').show();
		
		//web trends multitrack event
		dcsMultiTrack('DCS.dcsuri', 'solutions/tabs', 'WT.ti', 'Solutions%20Finder%20Tabs',
			'DCSext.Choice', content_show);
		
		return true;								
  
	});
	
	
	
	/*Hotspots*/
	$(".hotspot a").mouseover(function(){
		$(this).parents('.interactive').find(".hotspot-over-content").text($(this).text());
		$(this).parents('.interactive').find(".hotspot-over").css({
			'width': 0,
			'top':$(this).parent().position().top-5+"px",
			'left':$(this).parent().position().left+30+"px"
		})
		.stop(true,true)
		.fadeIn(200);
		//alert($(this).attr("rel"));
		highlightProducts($(this).attr("rel"),$(this).parents('.tab-content').find('.product-list'));
	})
	.mouseout(function(){
		$(this).parents('.interactive').find(".hotspot-over").stop(true,true).fadeOut(200);
		
		if(!$(this).parents('.interactive').is('.modal')){
			unhighlightProducts($(this).parents('.tab-content').find('.product-list'));
		}
	})
	.click(function(){
		var pos = $(this).parent().index();
		$(this).parents('.interactive').addClass('modal') //add modal class to hotspot container	
		.find('.hotspot-info').stop(true,true).fadeOut(100)  //slide all panels up
		.eq(pos).slideDown(200).find; //slide down relevant panel
		highlightProducts($(this).attr("rel"),$(this).parents('.tab-content').find('.product-list'));
		
	});
	
	$('.hotspot-info .modal-close').click(function(){
		$(this).parent().stop(true,true).slideUp(200); //slide up panels
		$(this).parents('.interactive').removeClass('modal'); //remove modal class from hotspot container
		unhighlightProducts($(this).parents('.tab-content').find('.product-list'));
	});
	
	$('.interactive-graphic').click(function(){
		$(this).parent().removeClass('modal') //remove modal class from container
		.find('.hotspot-info').stop(true,true).slideUp(200); //slide panels up
		unhighlightProducts($(this).parents('.tab-content').find('.product-list'));
		if(healthModal){healthModal.children('.modal-close').click();}
		
	});
	
	//Quick nav
	$('.quick-nav-link').click(function(){
		$(this).parent().find('.quick-nav-links').stop(true,true).slideDown(200);
	});
	$('.quick-nav-header').click(function(){
		$(this).parents('.quick-nav-links').slideUp(200);
	});
	
	//Quick nav links
	$('.quick-nav-list a').click(function(){
		var tab = $(this).parents('.quick-nav-list').attr('rel'); //find related tab
		var hotspot = $(this).parent().index(); //find hotspot
		$(this).parents('.quick-nav').find('.quick-nav-links').stop(200,200).slideUp(200,function(){ //slide menu up
			$('#solutions-nav .'+tab+' a').click(); //simulate tab click
			$('.'+tab+' .hotspot-list li').eq(hotspot).find('a').click(); //simulate hotspot click
		});
		
	})
	
	//Germ list hovers
	$('.germ-list a').mouseover(function(e){
		$(this).parents('.germs').find('.germ-info-list li.'+$(this).attr('rel')).stop(true,true).fadeIn(200);
	}).mouseout(function(){
		$(this).parents('.germs').find('.germ-info-list li.'+$(this).attr('rel')).stop(true,true).fadeOut(200);
	});
	

	/*Health concern*/
	//Accordion
	
	//preload accordion backgrounds
	function preload(arrayOfImages) {
	    $(arrayOfImages).each(function(){
	        $('<img/>')[0].src = this;
	        // Alternatively you could use:
	        // (new Image()).src = this;
	    });
	} 
	preload([
	    '/images/solutions/flu.jpg',
	    '/images/solutions/skin-wound.jpg',
	    '/images/solutions/stomach-bugs.jpg',
	    '/images/solutions/allergies.jpg',
	    '/images/solutions/respiratory-problems.jpg',
	    '/images/solutions/children-baby.jpg',
	]);
	$('.health-concern-trigger').click(function(){
		
		if(!$(this).hasClass('selected')){ //if NOT selected
			
			if(healthModal){healthModal.children('.modal-close').click();}
			$('.health-concern .interactive').find('.health-bg').fadeOut(function(){$(this).remove();}) //fade out and remove any existing background overlay
			$('.health-concern .interactive').append('<img class="health-bg" src="/images/solutions/'+$(this).attr('rel')+'.jpg" />'); //display background overlay
			$('.health-concern .interactive').children('.health-bg').fadeIn(); //fade in background overlay
			$('.health-concern-subnav').stop(true,true).slideUp(); //slide all subnav options up
			$(this).siblings('.health-concern-subnav').stop(true,true).slideDown(); //slide relevtant options down
			$('.health-concern-trigger').removeClass('selected'); //remove selected class on all
			$(this).addClass('selected'); //add selected class to relevant one
			
		}else{ //if selected
			
			$('.health-concern .interactive').find('.health-bg').fadeOut(function(){$(this).remove();}) //fade out and remove background overlay
			$(this).siblings('.health-concern-subnav').stop(true,true).slideUp(); //slide up
			$('.health-concern-trigger').removeClass('selected'); //remove selected class
			
		}
	});
	
	//Health Concern Modal, Germ, Tip, Products
	$('.health-concern-subnav a')
	.mouseover(function(){
		if(!($(this).parents('.tab-content').find('.product-list a').hasClass('highlight'))){
			highlightProducts($(this).attr("rel"),$(this).parents('.tab-content').find('.product-list'));
		}
	})
	.mouseout(function(){
		if(!$(this).hasClass('selected')&&!$(this).parents('.interactive').hasClass('modal')){
			  unhighlightProducts($(this).parents('.tab-content').find('.product-list'));
		}
	})
	.click(function(){	
		var pos = $(this).parent().index('.health-concern-nav li li'); //Get list item position which we can use to determine relations with other lists
		
		
		//Modal window
		$('.health-concern-content li').stop(true,true).fadeOut(); //fade out all existing modals
		healthModal = $('.health-concern-content li').eq(pos);
		healthModal.stop(true,true).fadeIn(); //fade in relevant one
		$(this).parents('.interactive').addClass('modal');
		
		//Tip
		$('.tips-list li').not('.tips-list li li').hide();	 //hide all existing tips
		$('.health-concern-tips .default').hide();
		$('.health-concern-tips li').not('.tips-list li li').eq(pos).stop(true,true).show(); //show relevant one using position
		//Germ
		$(this).parents('.tab-content').find('.germ-list li, .germs .default').hide() //hide all germ items;
		$(this).parents('.tab-content').find('.germ-list li').eq(pos).show(); //show related germ list item
		
		//Products
		unhighlightProducts($(this).parents('.tab-content').find('.product-list'));
		highlightProducts($(this).attr("rel"),$(this).parents('.tab-content').find('.product-list'));
		$('.health-concern-subnav a').removeClass('selected'); //remove selected states on others
		$(this).addClass('selected'); //add selected state on specific bug
		
		
	});
	
	//Modal close button
	$('.health-concern-content .modal-close').click(function(){
		$(this).parent().stop(true,true).fadeOut();
		$('.tips-list li').not('.tips-list li li').hide(); //hide all existing tips
		$('.health-concern-tips .default, .germs .default').show() //show default message
		$(this).parents('.tab-content').find('.germ-list li').hide() //hide all germ items;
		unhighlightProducts($(this).parents('.tab-content').find('.product-list'));
		
		$(this).parents('.tab-content').find('.health-concern-subnav a').removeClass('selected');
		$('.health-concern-subnav a').removeClass('selected'); //remove selected state
		
		$(this).parents('.interactive').removeClass('modal');
	});
	
	$('.health-bg').live('click', function(){
		$('.health-concern-content .modal-close').click();
	})
	
	
	
	//This function takes a space separated list of product shortnames and a reference to the product list
	//and highlights the appropriate products
	function highlightProducts(products, productList){
		var productArray = products.split(" ");
		for(i in productArray){
			productList.find('li a.'+productArray[i]).stop(true,true).addClass('highlight');
		}
	}
	
	//This function unhighlights all products that are selcted
	function unhighlightProducts(productList){
		productList.find('li a').stop(true,true).removeClass('highlight');
	}
/**SOLUTIONS FINDER APP - END**/
	
	/*Tabs on Hygiene Page*/
	$("#hygiene-tabs a").click(function () {  
		
		
		
		$(".tab-content").slideUp();
		
		var content_show = $(this).attr("rel");
		
  		$("."+content_show).delay(400).slideDown();
		
		return true;								
  
	});
	
	/** USAGE POP UP BOXES **/
	$("a.usage").click(function () {
		var usageBox = $(this).parents('.product, .product-right').find(".usage-box");
		
		$('#fade').css({
						width:		$(document).width(),
						height:		$(document).height()
					});
		$("#fade").show();
		var content = $(this).attr("rel");
		$("#" + content).show();
		var top = (($(window).height() - usageBox.outerHeight(false))/2 + $(window).scrollTop());
		var left = ((($('.content').width()) - (usageBox.width())) /2);
		
		
	
		
		usageBox.css({
			'top': top+"px",
			'left': left+"px"
		}).show();
		return false;
	});
	$("#fade").click(function () {
		$("#fade").hide();
		$(".usage-box").hide();
		return false;
	});
	$("a.close").click(function () {
		$("#fade").hide();
		$(".usage-box").hide();
		return false;
	});
	
	
	/** Abstracted version of the above modal functionality **/
	$("a.modal-link").click(function () {
		var modal = $("#" + $(this).attr("rel"));
		
		$('#fade').css({
			width:		$(document).width(),
			height:		$(document).height()
		});
		$("#fade").show();
		
		modal.show();
		
		var top = (($(window).height() - modal.outerHeight(false))/2 + $(window).scrollTop());
		var left = ((($(window).width()) - (modal.width())) /2);
		
		console.log("top=" + top + ", left=" + left)
		
		modal.css({
			'top': top+"px",
			'left': left+"px"
		}).show();
		return false;
	});
	$("#fade").click(function () {
		$("#fade").hide();
		$(".modal").hide();
		return false;
	});
	$("a.close").click(function () {
		$("#fade").hide();
		$(".modal").hide();
		return false;
	});
	




});




/*Read more content*/
$('.read-more-content').css({display: 'none'});
$('.read-more-container').append(' <a class="read-more" href="javascript:void(0)">Read more</a>')
					     .find('.read-more').click(function(){
					   	    $(this).parent().parent().find('.read-more-content').slideToggle();	
				   	     });


