$(document).ready(function () {
    $(".questionAnswerToggle").click(function () {
        $(this).closest(".questionItem").find(".questionAnswerContainer").slideToggle();
        $(this).closest(".questionItem").toggleClass("questionItemSelected");
        $(this).closest(".questionItem").find(".HideAnswer").toggle();
        $(this).closest(".questionItem").find(".ShowAnswer").toggle();
    });

    var currQ = $("#CurrentQuestion > input").val();

    if (currQ != "" && currQ != 'undefined') {
        currQ = "#" + currQ;
        $(currQ).find(".questionAnswerContainer").slideToggle();
        $(currQ).toggleClass("questionItemSelected");
        $(currQ).find(".HideAnswer").toggle();
        $(currQ).find(".ShowAnswer").toggle();
        $(currQ).find(".Ask").toggle();
        $(currQ).find(".TQ").toggle();
    }
});


function slideShow(speed) {


	//append a LI item to the UL list for displaying caption
	$('ul.HomeBanner').append('<li id="HomeBannerCaption" class="caption"><div class="HomeBannerCaptionContainer"><h3></h3><p></p></div></li>');

	//Set the opacity of all images to 0
	$('ul.HomeBanner li').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('ul.HomeBanner li:first').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	$('#HomeBannerCaption h3').html($('ul.HomeBanner a:first').find('img').attr('title'));
	$('#HomeBannerCaption p').html($('ul.HomeBanner a:first').find('img').attr('alt'));
		
	//Display the caption
	$('#HomeBannerCaption').css({opacity: 0.85, bottom:0});
	
	//Call the gallery function to run the slideshow	
	var timer = setInterval('gallery()',speed);
	
	//pause the slideshow on mouse over
	$('ul.HomeBanner').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('gallery()',speed);			
		}
	);
	
}

function gallery() {


	//if no IMGs have the show class, grab the first image
	var current = ($('ul.HomeBanner li.show')?  $('ul.HomeBanner li.show') : $('#ul.HomeBanner li:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().attr('id') == 'HomeBannerCaption')? $('ul.HomeBanner li:first') :current.next()) : $('ul.HomeBanner li:first'));
		
	//Get next image caption
	var title = next.find('img').attr('title');	
	var desc = next.find('img').attr('alt');	
		
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
	
	//Hide the caption first, and then set and display the caption
	/*$('#HomeBannerCaption').animate({bottom:-70}, 300, function () {
			//Display the content
			$('#HomeBannerCaption h3').html(title);
			$('#HomeBannerCaption p').html(desc);				
			//$('#HomeBannerCaption').animate({bottom:0}, 500);	
	});	*/	

	//Hide the current image
	current.animate({opacity: 0.0}, 1000).removeClass('show');

}

/**
 *  jQuery Tooltip Plugin
 *  @requires jQuery v1.2.6 or greater
 *  http://hernan.amiune.com/labs
 *
 *  Copyright (c)  Hernan Amiune (hernan.amiune.com)
 *  Licensed under MIT license:
 *  http://www.opensource.org/licenses/mit-license.php
 * 
 *  Version: 1.0
 */
 
(function($){ $.fn.tooltip = function(options){
	
    var defaults = {
        cssClass: "",     //CSS class or classes to style the tooltip
		delay : 0,        //The number of milliseconds before displaying the tooltip
        duration : 250,   //The number of milliseconds after moving the mouse cusor before removing the tooltip.
        xOffset : -20,     //X offset will allow the tooltip to appear offset by x pixels.
        yOffset : -20,     //Y offset will allow the tooltip to appear offset by y pixels.
		opacity : 0,      //0 is completely opaque and 100 completely transparent
		fadeDuration: 400, //[toxi20090112] added fade duration in millis (default = "normal")
		fixed: false
	};
  
    var options = $.extend(defaults, options);
	
	
	return this.each(function(index) {
	
		
		var $this = $(this);
		
		//use just one div for all tooltips
		// [toxi20090112] allow the tooltip div to be already present (would break currently)
		$tooltip=$("#divTooltip");
		if($tooltip.length == 0){
			$tooltip = $('<div id="divTooltip"></div>');			
			$('body').append($tooltip);
			$tooltip.hide();
		}
			
		
		//displays the tooltip
		$this.mouseover( function(e){
			//compatibility issue
			e = e ? e : window.event;
			
			//don't hide the tooltip if the mouse is over the element again
			clearTimeout($tooltip.data("hideTimeoutId"));
			
			//set the tooltip class
			$tooltip.removeClass($tooltip.attr("class"));
			$tooltip.css("width","");
			$tooltip.css("height","");
			$tooltip.addClass(options.cssClass);
			$tooltip.css("opacity",1-options.opacity/100);
			$tooltip.css("position","absolute");			
			
			//save the title text and remove it from title to avoid showing the default tooltip
			$tooltip.data("title",$this.attr("title"));
			$this.attr("title","");
			$tooltip.data("alt",$this.attr("alt"));
			$this.attr("alt","");
						
			//set the tooltip content
			$tooltip.html($tooltip.data("title"));
			// [toxi20090112] only use ajax if there actually is an href attrib present
			var href=$this.attr("href");
			var dummy = new Date();
			// [Peter] href!="" added
			if(href!=undefined && href!="" && href != "#")
			    $tooltip.html($.ajax({url:$this.attr("href")+"?_="+dummy.getTime(),async:false}).responseText);
			
			if(options.fixed === false){
				//set the tooltip position
				winw = $(window).width();
				w = $tooltip.width();
				xOffset = options.xOffset;
				
				//right priority
				if(w+xOffset+50 < winw-e.clientX)
				  $tooltip.css("left", $(document).scrollLeft() + e.clientX+xOffset);
				else if(w+xOffset+50 < e.clientX)
				  $tooltip.css("left", $(document).scrollLeft() + e.clientX-(w+xOffset));
				else{
				  //there is more space at left, fit the tooltip there
				  if(e.clientX > winw/2){
					$tooltip.width(e.clientX-50);
					$tooltip.css("left", $(document).scrollLeft() + 25);
				  }
				  //there is more space at right, fit the tooltip there
				  else{
					$tooltip.width((winw-e.clientX)-50);
					$tooltip.css("left", $(document).scrollLeft() + e.clientX+xOffset);
				  }
				}
				
				winh = $(window).height();
				h = $tooltip.height();
				yOffset = options.yOffset;
				//top position priority
				if(h+yOffset + 50 < e.clientY)
				  $tooltip.css("top", $(document).scrollTop() + e.clientY-(h+yOffset));
				else if(h+yOffset + 50 < winh-e.clientY)
				  $tooltip.css("top", $(document).scrollTop() + e.clientY+yOffset);
				else 
				  $tooltip.css("top", $(document).scrollTop() + 10);
			}
			
			//start the timer to show the tooltip
			//[toxi20090112] modified to make use of fadeDuration option
			$tooltip.data("showTimeoutId", setTimeout("$tooltip.fadeIn("+options.fadeDuration+")",options.delay));
		});
		
		
		$("#divTooltip").click(function(e){
			//restore the title
			$this.attr("title",$tooltip.data("title"));
			$this.attr("alt",$tooltip.data("alt"));
			//don't show the tooltip if the mouse left the element before the delay time
			clearTimeout($tooltip.data("showTimeoutId"));
			//start the timer to hide the tooltip
			//[toxi20090112] modified to make use of fadeDuration option
			$tooltip.data("hideTimeoutId", setTimeout("$tooltip.fadeOut("+options.fadeDuration+")",options.duration));
		});
		
		/*$this.mouseout(function(e){
			//restore the title
			$this.attr("title",$tooltip.data("title"));
			$this.attr("alt",$tooltip.data("alt"));
			//don't show the tooltip if the mouse left the element before the delay time
			clearTimeout($tooltip.data("showTimeoutId"));
			//start the timer to hide the tooltip
			//[toxi20090112] modified to make use of fadeDuration option
			$tooltip.data("hideTimeoutId", setTimeout("$tooltip.fadeOut("+options.fadeDuration+")",options.duration));
		});*/
		
		$this.click(function(e){
		    e.preventDefault();
		});

	});

}})(jQuery);



function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
    field.value = field.value.substring(0, maxlimit);
else 
countfield.value = maxlimit - field.value.length;
}

function textLimit(field, maxlimit) {
    if (field.value.length > maxlimit)
        field.value = field.value.substring(0, maxlimit);
}

$(document).ready(function () {
	$('#HomeSlider').bxSlider({
		wrapper_class: 'HomeSliderWrap',
		margin: 70,
		auto: true,
		auto_controls: false,
		speed: 500,
		pager: true,
		controls: false,
		pause: 8000
	});	
	
	
    $("#qAskNo").click(function () {
        $(".qAsk").slideToggle();
    });});
    
	//Image Header Slider Code
	$(document).ready(function() {		
	
	//Execute the slideShow, set 4 seconds for each images
	slideShow(8000);
	
	
	$("#PrimaryNav ul ul").css({display: "none"});
	$("#PrimaryNav li").hover(function(){
		$(this).find("ul:first").css({visibility: "visible",display: "none"}).show(50);
		},function(){
		$(this).find("ul:first").css({visibility: "hidden"});
	});
	
	$(".NorthEastEvents").simpletip({fixed: true,showEffect: 'fade', hideEffect: 'fade',baseClass: 'MapRolloverNorthEast'}).simpletip().load('/Events2_NE.html'); 
	$(".NorthWestEvents").simpletip({fixed: true,showEffect: 'fade', hideEffect: 'fade',baseClass: 'MapRolloverNorthWest'}).simpletip().load('/Events2_NW.html'); 
	$(".CentralEvents").simpletip({fixed: true,showEffect: 'fade', hideEffect: 'fade',baseClass: 'MapRolloverCentral'}).simpletip().load('/Events2_WM.html'); 
	$(".WalesEvents").simpletip({fixed: true,showEffect: 'fade', hideEffect: 'fade',baseClass: 'MapRolloverWales'}).simpletip().load('/Events2_WA.html'); 
	$(".NorfolkEventsOne").simpletip({fixed: true,showEffect: 'fade', hideEffect: 'fade',baseClass: 'MapRolloverNorfolk'}).simpletip().load('/Events2_EM.html'); 
	$(".NorfolkEventsTwo").simpletip({fixed: true,showEffect: 'fade', hideEffect: 'fade',baseClass: 'MapRolloverNorfolk'}).simpletip().load('/Events2_EM.html'); 
	$(".LondonEvents").simpletip({fixed: true,showEffect: 'fade', hideEffect: 'fade',baseClass: 'MapRolloverSouthEast'}).simpletip().load('/Events2_GL.html'); 
	$(".SouthEastEventsOne").simpletip({fixed: true,showEffect: 'fade', hideEffect: 'fade',baseClass: 'MapRolloverLondon'}).simpletip().load('/Events2_SE.html'); 
	$(".SouthEastEventsTwo").simpletip({fixed: true,showEffect: 'fade', hideEffect: 'fade',baseClass: 'MapRolloverLondon'}).simpletip().load('/Events2_SE.html'); 
	$(".SouthEastEventsThree").simpletip({fixed: true,showEffect: 'fade', hideEffect: 'fade',baseClass: 'MapRolloverLondon'}).simpletip().load('Events2_SE.html'); 
	$(".SouthWestEvents").simpletip({fixed: true,showEffect: 'fade', hideEffect: 'fade',baseClass: 'MapRolloverSouthWest'}).simpletip().load('/Events2_SW.html'); 
	$(".ScotlandEvents").simpletip({fixed: true,showEffect: 'fade', hideEffect: 'fade',baseClass: 'MapRolloverScotland'}).simpletip().load('/Events2_SC.html'); 
		

});
/*

$(document).ready(function() {
	
	$("#ScotlandEvents").tooltip({cssClass:"MapRolloverScotland"});
	$("#NorthEastEvents").tooltip({cssClass:"MapRolloverNorthEast"});
	$("#NorthWestEvents").tooltip({cssClass:"MapRolloverNorthWest"});
	$("#CentralEvents").tooltip({cssClass:"MapRolloverCentral"});
	$("#WalesEvents").tooltip({cssClass:"MapRolloverWales"});
	$("#NorfolkEvents").tooltip({cssClass:"MapRolloverNorfolk"});
	$("#LondonEvents").tooltip({cssClass:"MapRolloverLondon"});
	$("#SouthEastEvents").tooltip({cssClass:"MapRolloverSouthEast"});
	$("#SouthWestEvents").tooltip({cssClass:"MapRolloverSouthWest"});

    SyntaxHighlighter.all();
	
});*/

