	//Map for homepage
	
		function highlightMap(mapID){
		document.getElementById("countyMap").src = "base-install/images/map/map-" + mapID.id + ".jpg";
		document.getElementById("mapLoc").innerHTML = mapID.id;
	}
	function outMap(){
		document.getElementById("countyMap").src = "base-install/images/map/map.jpg";
		document.getElementById("mapLoc").innerHTML = "";		
	}

$(document).ready(function(){
	var tmpmenuid = 0;	//for submenu hover code
	
	// For aligned images
	$('img[align=right]').addClass('float-right');
	$('img[align=left]').addClass('float-left');	

	// Property module tabs
	$('#tab_nav').show();
	$("#property_tabs").tabs();

	// Adds an icon and title for links that open in a new window
	$('p a[target=_blank]').attr('title', 'Opens in a new window').addClass('newindow');
	
	// Gallery Plugin
	$("a[rel=image_gallery]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition' 	: 'inside',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
	
	$("a.lightbox").fancybox({
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});

	// Quicklinks
	quicklinkgo();
	
/*
	// map rollovers
   $("#countyMap > area").hover(
		  function () {
		     var $this = $(this),
             $map = $("#map"),
             src;
           switch ($this.attr("alt")) {
             case "derbyshire":
		            src = "map-derbyshire.jpg";
		            break;
             case "leicestershire":
                src = "map-leicestershire.jpg";
                break;
             case "lincolnshire":
                src = "map-lincolnshire.jpg";
                break;
             case "northamptonshire":
                src = "map-northamptonshire.jpg";
                break;
             case "nottinghamshire":
                src = "map-nottinghamshire.jpg";
                break;
             case "rutland":
                src = "map-rutland.jpg";
                break;
             default:
                src = "map.jpg";
         }
         $map.attr("src", "base-install/images/map/" + src);
       },
      function () {
         $("#map").attr("src", "base-install/images/map/map.jpg");
      }
   );
*/
  
   //preload map images
   (function () {
         
          var images = [
                 "map-derbyshire.jpg",
                 "saddleworth.gif",
                 "west_oldham.gif",
                 "shaw_royton.gif",
                 "east_oldham.gif",
                 "failsworth_hollinwood.gif"
          ];
         
          for (i in images) {
                 var image = new Image();
                 image.src = "base-install/images/map/map.jpg" + images[i];
          };
         
   })();
 
	
	// Default slideshow - for opts see http://jquery.malsup.com/cycle/options.html
	$(".slider").v1Slider();
	
	//Staff directory tree images
	var treeClosed = "images/arrow_blue_horiz.png";
	var treeOpen = "images/arrow_blue_down.png";
	
	
	///////////////// CMS specific code below /////////////////////
	
	// Search filter
	$(".searchAllModules").click(function (ev) {
		ev.preventDefault();
		var $this = $(this),
			check = true;
		if ($this.text() == "Select all") 
			$this.text("Deselect all");
		else {
			$this.text("Select all");
			check = false;
		}
		$this.nextAll("input[type=checkbox]").each(function () {
			if (check) this.checked = true;
			else this.checked = false;
		});
	}).nextAll("input[type=checkbox]").each( function () {
		if (this.checked) {
			$(".searchAllModules").text("Deselect all");
			return false; // break
		}
	});	
	
	//media file transcripts
	$(".mediaFileTranscript").hide();
	$(".toggleTranscriptView").click(function (ev) {
		ev.preventDefault();
		$(this).parent().next(".mediaFileTranscript").slideToggle(300);
	});
	
	/*for personalisation*/
	//commented out because it was breaking.
	//Personalise = new personalise();
	//Personalise.initfrontend("#perstodofrontph","#persfavfrontph","framework/personalise/personalisehandlerforfront.cfm");
	
	//Staff directory initialisation
	if (typeof StaffDirectory !== "undefined") {
		StaffDirectory = new StaffDirectory(treeOpen, treeClosed);
		StaffDirectory.init();
		
		//switcher for locations drop down
		$('.showLoc').click(function(){
			$('#location_div').toggle();
		});
	}
	
	//IPM initialisation
	if (typeof IPMController !== "undefined") {
		try {
			FieldManager = new fieldManager({
				handler: 'fieldManagerHandler.cfm',
				frontEndMode: true
			});
			IPM = new IPMController({
				handler: 'IPMHandler.cfm',
				parentDivId: '#IPMTemplate',
				frontEndMode: true
			});
			IPM.init();
		} catch (e) {
			alert(e.message);
		}
	}
	
	//Targets the HTML5 Placeholder element in form inputs and provides a fallback for crippled browsers
	//Taken from http://www.cssnewbie.com/cross-browser-support-for-html5-placeholder-text-in-forms/
	if(!$.support.placeholder) { 
		var active = document.activeElement;
		$(':text').focus(function () {
			if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
				$(this).val('').removeClass('hasPlaceholder');
			}
		}).blur(function () {
			if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
				/*commented out because its breaking at the moment.
				$(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');*/
			}
		});
		$(':text').blur();
		$(active).focus();
		$('form').submit(function () {
			$(this).find('.hasPlaceholder').each(function() { $(this).val(''); });
		});
	}
	
	$("#myspace-news").v1Slider({
		pauseBtn: "#myspace-pause",
		fx: "scrollLeft",
		timeout: 16000,
		speed: 2000
	});
	
	//submenu hover code
	$(".topnavhover").hover(
		function(){			
			$(".hoverol").addClass("hideol");			
			var $this = $(this);
			tmpmenuid = $this.find("a:first").attr("id").substring(1);
			if ($('#ol'+tmpmenuid).length) {
				$('#ol'+tmpmenuid).removeClass("hideol");
			}
			else {
				$.get("ajaxcallolpage.cfm",
					{menuid: tmpmenuid},
					function(data){
						$this.append(data);
					}, "html")
			}
		},
		function(){				
			$('#ol'+tmpmenuid).addClass("hideol");
		}
	);
	
	
	$(".datepicker").datepicker(
		{
			dateFormat: 'yy-mm-dd'
		}
	);
});	

function quicklinkgo(){
	var btn = document.getElementById('quicklinks_go');
	if(!btn)
		return false;
	btn.style.display='none';//hide the button

	btn = document.getElementById('quicklinks_select');
	if(btn)btn.onchange=function(){this.parentNode.submit();}
}
