//js file as at 12:16 06/11/09  ~(..,)~
$(function() {
	$('.nav_head').toggle(function() {
		$('#navBar').animate({height: 166}, 'slow');
						}, function(e) {
		$('#navBar').animate({height:18}, 'slow');
		e.stopPropagation();
	});
	$('.subNav a').click(function(){return true;});
	$('.screening_container').children('p').hide();
   	$('.screening_container h3').click(function(){
		$(this).parent().children('p').slideToggle(200);
		$(this).parent().children('.more_icon').toggleClass('more_hover');
	});
	$('#vit_prem_red').hide();
	$('#cont1').hide();
	$('.switcher').next().hide();
   	$('.switcher').click(function(){
		var next = $(this).next();
		var prev =$(this).prev();
		$(next).slideToggle();
		$(prev).toggleClass('more_hover');
	});
	$('.slider_close').click(function(){
		$(this).parent().slideUp();
	});
	
	//Carousel code
	var one = '0px'; // set-up the scroll distances for each slide
	var two = '-=580px'; // we can use this as the increment
	var three = '-1160px';
	var four = '-1740px';
	$(function(){
		var slide = 0;
		var carouselTimeout; 
		var interrupt = false; //this is the trigger to stop auto rotation, or it will once I get it working...
		var carouselRotate = function(){
				if (slide < 3 && interrupt==false){
					$('#carousel_container').animate({left: two}, 1000);
					carouselTimeout = setTimeout(carouselRotate, 6000);
					slide ++;
					} else {
					$('#carousel_container').animate({left:one}, 1000);
					slide = 0;
					carouselTimeout = setTimeout(carouselRotate, 6000);
					};
					
			};
		carouselTimeout = setTimeout(carouselRotate, 6000);
		$('#scroll_left').click(function(){
			interrupt = true;
			slide--;
			if (slide > 0){
				$('#carousel_container').animate({left: two}, 1000);
			} else {
				$('#carousel_container').animate({left:four}, 1000);
				slide = 4;
			};
		});
		$('#scroll_right').click(function(){
			interrupt = false;
			slide++;
			if (slide < 4){
				$('#carousel_container').animate({left: "-=580px"}, 1000);
			} else {
				$('#carousel_container').animate({left:one}, 1000);
				slide=1;
			};
		});
	});
   	//Vitality rollovers
     var offsetX = -360;
     var offsetY= -200;
	 $('.vitality_steps > p').hide();
	  $('.trigger').hover(function(event){
		   var href=$(this).attr('href');
		   var thisPara=$(this).find('p');
		   $(thisPara).show();
		   $(thisPara)
		   .css('top', event.pageY + offsetY)
		   .css('left', event.pageX + offsetX)
	  }, function(){
		   //mouse off
		   $(this).find('p').hide();
	  });

	  
	  //News page
	  $(function(){
			var newsid = ('newsid');
			$('.article_body').hide();
			$('.article_body').each(function(index){
				$(this).attr("id", ['newsid' + index]);
				});
			$('.more').click(function(){
				newsid =$(this);
				var thisid = $(this).parent().next().attr('id');
				$(this).parent().next().slideDown();
				$(this).hide();
				return false;
				});
			$('.collapse').click(function(){
				$(this).parent().slideUp();
				$(newsid).show();
			});
			
			});
	  
	  //FAQ Page
	 /* $(function(){
			$('.faq_answer').hide()
			$('.faq_question').click(function(){
					$(this).next().slideToggle();
					$(this).prev().toggleClass('more_hover');
					return false;
				});
			});*/
	   $(function(){
			$('.faq_answer').hide()
			$('.faq_question').toggle(function(){
					$(this).next().show();
					$(this).prev().addClass('more_hover');
					}, function(){
						$(this).next().hide();
						$(this).prev().removeClass('more_hover');
					return false;
				});
			});
	  //tabbed nav
		$(function(){
			$('#second_content').hide();
			$('#third_content').hide();
			$('#fourth_content').hide();
			$('#fifth_content').hide();
			$('#sixth_content').hide();
			$('#seventh_content').hide();

			$('a.tab').click(function(){
				$('a.tab').css({'color': '#ab218e', 'font-weight': 'normal'});					  
				$('.current').removeClass('current');
				$(this).parent().addClass('current');
				$(this).css({'color': '#ab218e', 'font-weight': 'bold'});
				$('.tab_content').slideUp();
				var content_show = $(this).attr('title');  
				$('#' + content_show).slideDown();
				console.log(content_show);
				return false;
			});
		});
});		
		//popup
$(document).ready(function(){
  
  $('.hidden').hide();
  $(".modal_trigger").click(function(e){
	  e.preventDefault();
	  var clicked = $(this).attr('title');
	  var popupcontent = $('#' + clicked);
	  var maskHeight = $(document).height();
	  var maskWidth = $(window).width();	
	  $('#dim').css({'width':maskWidth,'height':maskHeight});
	  var winH = $(window).height();
	  var winW = $(window).width();
	  $('#dim').fadeIn(1000);
	  $('#dim').fadeTo('slow', 0.8);
	  $(popupcontent).css('top', winH/2-$(popupcontent).height()/2);
	  $(popupcontent).css('top', winW/2-$(popupcontent).width()/2);
	  $(popupcontent).fadeIn(1000);
	  $(popupcontent).append('<br /><a href="" id="closelink" style="color:#f8981d;text-decoration:underline">Close window X</a><br /><br />	 ');

	  });
				
  $("#dim").live("click", function(){
	  $(this).remove()
	});
  $(".modal_close").live("click", function(e){
	  e.preventDefault();
	  $(this).parent().hide()
	  $('#dim').hide();
	});
});

//Literature & Tools Mod 14 April 2010 - Andy
$(function(){
	$('#tool_preview').hide();
		$('#second_main > li').hide();
		$('#first_main .menu_item').click(function(){
		$('#second_main > li').hide();
		$('#first_main .menu_item').removeClass('selected');
		var clicked = $(this).attr('id');
		$(this).addClass('selected');
		$('#second_main > li').each(function(index){
			var thisRow = $(this).attr('class');
			$(this).attr("id", index);
		if (thisRow == clicked){
			$(this).show();
		}
	});
	
	});
	$('#second_main > li').click(function(e){
		e.preventde
		$('.preview').hide().attr('src', '');
		$('#tool_preview').show();
		$('.toolTitle').remove();
		$('.tool_descr').remove();
		//$('#second_main > li').removeClass('selected');
		//$(this).addClass('selected');
		var thisLink = $(this).children().attr('href');
		var doc = thisLink.split('.');
		var thisImg = thisLink.slice(32, -4) + '.gif'; //altered slice from 13 to 10 for SA
		var toolTitle = $(this).children('a').text();
		var toolText = $(this).children('.tool_description').html();
		$('<p class="tool_descr">' + toolText +'</p>').insertAfter('.preview');
		$('<h3 class="toolTitle greenone">' + toolTitle + '</h3>').insertBefore('.preview');
		$('.preview').show().attr('src', '/images/general/thumbnails/'+ thisImg);
  //modified 4/11/09 for SA's structure. Removed ../ before images
		if ($(this).attr('id') === 'gym') {
			
			$('a#download').html('<a href="http://www.pruhealth.co.uk/uk/co/prudential/vitality/gym_finder_content.html" target="" class ="white" onclick="return openWindow(this,900,600);">Gym locator</a>');

		} else {	
			$('a#download').text("Go");
			$('a#download').attr('href', thisLink);
		};
		return false;
	
	});
});