

$(document).ready(function(){
  
   /*
   $("body").click(function(event) {
       if ($(event.target).is("a[href*=http://]")) {
        $(event.target).attr('target','_blank');
       }
     });
   
   */
  
    $.lazy('/assets/javascript/jquery.validate.js','validate');
  
    if($('#giants_mapbig').length > 0) initializeMap();
    if($('#giants_map').length > 0) intializeSmallMap();
    $('#contact_form').validate();
   
   
  	function showPopup(id){
  	  $('#giants_mapbig div.popup').hide();
  	  var boxid = '#' + id + '-box';
  		$(boxid).show();
  		/*
  		$('#giants_mapbig div.popup').fadeOut(9000,function() {
  		  var boxid = '#' + id + '-box';
  		  console.log("boxid = "+boxid);
    		$(boxid).fadeIn();
  		}); */
  	}

   	function initializeMap(){      	  
   	  if($('h1.cymraeg').length > 0){	$('#giants_mapbig').css({backgroundImage: 'url(/assets/images/map_big_w.gif)'}); }
   	  else { $('#giants_mapbig').css({backgroundImage: 'url(/assets/images/map_big.gif)'});}
       	  loadBullets();
       	  loadList();
   	}
   
  		function loadBullets(){  				
  			//place bullets
  		$('#giants_mapbig').children('a.bullet').each(function(){
  				var coords = $(this).attr('rel').split('-');
  				$(this).css({left: coords[0] + 'px', top: coords[1] + 'px'})
  					   .hide()
  					   .fadeIn()
  					   .hover(function(){
  					     highlightBullet($(this).attr('id'));	      
  					    showPopup($(this).attr('id'));
  					    highlightList($(this).attr('id'));})
  			});
  	}
  	
  	function highlightBullet(id){
  	   $(".bullet").removeClass('current');
	     $('#giants_mapbig a#'+id).addClass('current');
  	}
  	
  	function loadList(){
  	  $('.our_giants li').children('a').each(function(){
  	    $(this).hover(function(){
  	      showPopup($(this).parent().attr('id').substr(3));
  	      highlightList($(this).parent().attr('id').substr(3));
  	      highlightBullet($(this).parent().attr('id').substr(3));
  	    })  	    
  	  });
  	}
  	
  	function highlightList(id){
  	  $('.our_giants li').removeClass('current');
  	  $('li#gl_'+id).addClass('current');
  	}
  	
  	function intializeSmallMap(){
  	  $('.our_giants li').children('a').each(function(){
  	    $(this).hover(function(){
  	      switch($(this).parent().attr('id')){
  	        case 'gl_caernarfon':
  	          $('#giants_map .dots_all').css({ background:'url(/assets/images/dots_all.gif) no-repeat 0 0'})
  	          break;
  	        case 'gl_portmeirion':
  	          $('#giants_map .dots_all').css({ background:'url(/assets/images/dots_all.gif) no-repeat 0 -696px'})
  	          break;  	          
  	        case 'gl_bridge':
  	          $('#giants_map .dots_all').css({ background:'url(/assets/images/dots_all.gif) no-repeat 0 -348px'})
  	          break;
  	        case 'gl_slate':
  	          $('#giants_map .dots_all').css({ background:'url(/assets/images/dots_all.gif) no-repeat 0 -116px'})
  	          break;
  	        case 'gl_snowdon':
  	          $('#giants_map .dots_all').css({ background:'url(/assets/images/dots_all.gif) no-repeat 0 -812px'})
  	          break;
  	        case 'gl_bodnant':
  	          $('#giants_map .dots_all').css({ background:'url(/assets/images/dots_all.gif) no-repeat 0 -232px'})
  	          break;
  	        case 'gl_cathedral':
  	          $('#giants_map .dots_all').css({ background:'url(/assets/images/dots_all.gif) no-repeat 0 -580px'})
  	          break;
  	        case 'gl_aqueduct':
  	          $('#giants_map .dots_all').css({ background:'url(/assets/images/dots_all.gif) no-repeat 0 -464px'})
  	          break;
  	        default:        
  	      } }) })	}
});
