/* ------------------------------------------------------------------------------------
Website: Encams Keep Britain Tidy
File: Homepage javascript (jquery)
Author: Reading Room
Created: Feb 2009
------------------------------------------------------------------------------------ */
$(document).ready(function() {
	$("body").addClass("js");
	$("#leftCol li:last").addClass("last")
	
/* ------------------------------------------------------------------------------------
-- News ticker
------------------------------------------------------------------------------------ */
	fnSlideshow = function(){
		//options
		slideShowFadeSpeed="slow";
		slideShowPause=7000;

		//ensure the slides are hidden
		$("#newsScroller li").hide();
		
		$("#newsScrollerControls").empty().append('<a href="#" id="newsScrollerStopStart" class="stop"><img src="/images/button-ticker-pause.gif" alt="Pause news ticker" title="Pause news ticker"></a>');


		//stop/start ticker
		$("#newsScroller #newsScrollerStopStart").click( function(){
			$this = $(this);
			if ($this.hasClass("stop")){
				fnStopSlideShow();
				$this.removeClass("stop").addClass("start").find("img").attr("src","/images/button-ticker-play.gif").attr("alt","Start news ticker").attr("title","Start news ticker");
			} else {
				fnStartSlideShow();
				$this.removeClass("start").addClass("stop").find("img").attr("src","/images/button-ticker-pause.gif").attr("alt","Pause news ticker").attr("title","Pause news ticker");
			}
			return false
		});
		
		//show the first slide, add on state
		$("#newsScroller li:eq(0)").addClass("on").fadeIn(slideShowFadeSpeed);
		//start it
		fnStartSlideShow();
	};
	fnStartSlideShow = function(){
		//set time interval
		runSlideshow = setInterval( "fnSlideSwitch()", slideShowPause );
	}
	fnStopSlideShow = function(){
		clearInterval(runSlideshow);
	};
	fnSlideSwitch = function(){
		$("#newsScroller .on").fadeOut(slideShowFadeSpeed, function(){
			$("#newsScroller .on").removeClass("on").next().addClass("on").fadeIn(slideShowFadeSpeed);
			//check if that was the last item
			if ($("#newsScroller .on").length==0){
				clearInterval(runSlideshow);
				//show the first slide, add on state
				$("#newsScroller li:eq(0)").addClass("on").fadeIn(slideShowFadeSpeed);
				fnStartSlideShow();
			};
		});
	};
	//run the function
	fnSlideshow();

	
/* ------------------------------------------------------------------------------------
-- Flash map
------------------------------------------------------------------------------------ */
    $('#regionFlash').flash(
        { 
          src: '/images/flash/regionsMap.swf',
          width: 180,
          height: 236,
		  wmode:"transparent",
          flashvars: { MYURL: '/Get_Involved/Your_region/North_West' }
        },
        { version: 8 }
    );


/*	$('#regionFlash').flash({   
		swf: '/images/flash/regionsMap.swf',
		width:180,
		height:236,
		wmode:"transparent",
		flashvars: { name1: 'jQuery', name2: 'SWFObject', name3: 'Plugin' }
	});
*/
/* ------------------------------------------------------------------------------------
-- Our Expertise box
------------------------------------------------------------------------------------ */
	$("#expertise h3:gt(0), #expertise p:gt(0)").hide();
	$("#expertise h3:first, #expertise p:first").addClass("active");
	$("#expertise li").click(function() {
		if(!$(this).hasClass("active")) {
            // remove active selection
            $("#expertise li").removeClass("active");
            // show and hide
			$("#expertise h3, #expertise p").removeClass("active").hide();
            $("#expertise h3." + $(this).attr("class") + ", #expertise p." + $(this).attr("class")).addClass("active").show();
            // highlight active selection
            $(this).addClass("active");
        };
        return false;
    });

/* ------------------------------------------------------------------------------------
-- Features accordian
------------------------------------------------------------------------------------ */
	$("#features div.item:gt(0)").hide();
	$("#features h2").click(function() {
		$this = $(this);
		if(!$this.hasClass("active")) {
            // show and hide
			$("#features div.active").hide();
			$this.next().show();
            // remove active selection and middle item marker
            $("#features h2, #features div.item").removeClass("active").removeClass("middle");
            // highlight active selection
            $this.addClass("active").next().addClass("active");
			//remove dotted border
			$this.find("a").blur();
	        //if bottom item is selected, set marker on middle item
			if($this.attr("id")=="feature3"){
				$("#feature2").addClass("middle");
			}
			
			return false;
        };
    });

/* ------------------------------------------------------------------------------------
-- Fiddle with height of lozenges
------------------------------------------------------------------------------------ */
	$("#leftCol li span span").each( function(){
		$this = $(this);
		if ($this.height()>20){
			//taller than single line
			$this.addClass("doubleLine");
			
		}
	})


});