/**** Add application wide javascripts below this point  ******/
jQuery(document).ready(function(){
  if(jQuery("#adopt-accordion").length>0) jQuery("#adopt-accordion").accordion({autoHeight: false, event: 'mouseover'});
  if(jQuery("#quote-bubble-3").length>0){
    var opts = {
      event: 'mouseover',
      show: function(event, ui) {
        jQuery(this).find(".picker-on").css("display","none");
        jQuery(this).find(".picker-off").css("display","inline");
        jQuery(ui.tab).find(".picker-off").css("display","none");
        jQuery(ui.tab).find(".picker-on").css("display","inline");
      }
    };
    if(picked_bird) opts.selected = picked_bird - 1;
    jQuery("#quote-bubble-3").tabs(opts);
  }
  
  jQuery(".inline_image").each(function(){
    if($(this).attr("alt")){
      var width = $(this).attr("width");
      jQuery(this).wrap("<span class='"+jQuery(this).attr("class")+"'></span>").after("<span class='"+jQuery(this).attr("class")+" inline_image_caption'>"+jQuery(this).attr("alt")+"</span>");
      jQuery(this).removeClass("inline_image");
			jQuery(this).css("display","block");
			jQuery(this).parent().css("display","block").css("width",width);
			jQuery(this).siblings(".inline_image_caption").css("padding","5px").css("margin","0").css("width",width-10);
    }
  });
  jQuery("#centerpicker select").change(function(){window.location.href=jQuery(this).val();});

  var map_locs = {
    "/visit-us/castle-espie/how-to-find-us":["54.5241","-5.6905"],
    "/visit-us/caerlaverock/how-to-find-us":["54.978615","-3.496783"],
    "/visit-us/washington/how-to-find-us":["54.902014","-1.486869"],
    "/visit-us/martin-mere/how-to-find-us":["53.622609","-2.865204"],
    "/visit-us/welney/how-to-find-us":["52.525920","0.277855"],
    "/visit-us/llanelli/how-to-find-us":["51.663980","-4.122960"],
    "/visit-us/slimbridge/how-to-find-us":["51.741002","-2.403745"],
    "/visit-us/london/how-to-find-us":["51.477206","-0.235929"],
    "/visit-us/arundel/how-to-find-us":["50.866843","-0.545155"]
  };
  if(jQuery("#locationMap").length && map_locs[location.pathname]){
		map = new GMap2(document.getElementById("locationMap"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl());
		var point = new GLatLng(map_locs[location.pathname][0],map_locs[location.pathname][1]);
		map.setCenter(point,9);
		var marker = new GMarker(new GLatLng(map_locs[location.pathname][0],map_locs[location.pathname][1]));
    map.addOverlay(marker);
  }
  
  if(jQuery('#centreAppMap').length){
    centreMap();
  }
  
  var gallery_list = jQuery('#gList a[rel=lightbox]');
  if(gallery_list.length) gallery_list.lightBox();


	if($("#centres_image_map").length){
		$("#centres_image_map").tabs();
	}
	//$("#sField").hint();
	$(".input_field").hint();
	$("#newsletter_email").focus(function(){
		$("#newsletter_signup .hidden").slideDown("slow");
	});
	
});

function centreMap(){
  jQuery('div.centreSite').hide();
  jQuery('#c0').show();
  jQuery('#centreAppMap area').hover(
    function(){
      var raw_href_val = jQuery(this).attr('href');
      var href_val = raw_href_val.substring(raw_href_val.indexOf('#'));
      jQuery('div.centreSite').each(function(){
        if(this.id != href_val.substr(1)) jQuery(this).hide();
        else if(this.id == href_val.substr(1) && !jQuery(this).is(':visible')) jQuery(this).show();
      });      
    }, 
    function(){}
  );
  
}