var images = new Array('images/photo424x318.png', '/images/gallery/Table 14.jpg', '/images/gallery/The White Horse Inn.JPG', '/images/gallery/Food the Mediterranean way.JPG', '/images/gallery/Antonio Carluccio comes for supper.JPG', '/images/gallery/Dinner guests.jpg', '/images/gallery/The White Horse.jpg', '/images/gallery/Lunch in the courtyard.JPG',
'/images/gallery/Courtyard Dining Room.JPG', '/images/gallery/Moretonhampstead.jpg',
'/images/gallery/Courtyard Dining.JPG', '/images/gallery/The Pub.jpg', '/images/gallery/Open kitchen.jpg');
//var map = 'http://maps.google.com/maps/api/staticmap?center=50.660643,-3.765564&zoom=15&size=424x318&maptype=roadmap&markers=color:red|50.660643,-3.765564&sensor=false&key=ABQIAAAALlC9rgllzidUs6VWvlL7cBQnVmkbz8GoSudmcLPx1cFDSO5gohR9QezNYQhO_8jaGBU2d9bg30nstw';
var map = 'images/map.png';
var current = 0;
var delay = 500;
var map_link = 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=TQ13+8PG&sll=50.660678,-3.765596&sspn=0.009086,0.022724&ie=UTF8&hq=&hnear=Newton+Abbot,+Devon+TQ13+8PG,+United+Kingdom&ll=50.660616,-3.765371&spn=0.290762,0.727158&z=11';
var movie = false;
//var vidhtml = "<object width=\"424\" height=\"318\"><param name=\"allowfullscreen\" value=\"true\" /><param name=\"allowscriptaccess\" value=\"always\" /><param name=\"movie\" value=\"http://vimeo.com/moogaloop.swf?clip_id=9910373&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" /><embed src=\"http://vimeo.com/moogaloop.swf?clip_id=9910373&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" width=\"424\" height=\"318\"></embed></object><p><a href=\"http://vimeo.com/9910373\">The Making of WhiteHorseDevon.co.uk</a> from <a href=\"http://vimeo.com/whitehorse\">White Horse Inn</a> on <a href=\"http://vimeo.com\">Vimeo</a>.</p>";
var vidhtml = "<object width=\"424\" height=\"318\"><param name=\"allowfullscreen\" value=\"true\" /><param name=\"allowscriptaccess\" value=\"always\" /><param name=\"movie\" value=\"http://vimeo.com/moogaloop.swf?clip_id=9910373&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" /><embed src=\"http://vimeo.com/moogaloop.swf?clip_id=9910373&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" width=\"424\" height=\"318\"></embed></object>";

function whInit(){
  // preload images
  var map_image = new Image();
  map_image.src = map;
  $.each(images, function(i){
    //console.log(images[i]);
    img = new Image();
    img.src = images[i];
  });

  	$('.show-movie').click(function(){
		//$('#video-player').fadeIn();
		//console.log($('#video-player').html());
		movie = true;
		//var video_html = $('#vimeo').html();
		//console.log('video-html:'+vidhtml);
		$('#eye-catcher').html(vidhtml);
		return false;
	});
	
	//$('.media').media();

  $('.hover-me').hover(
	function(){
		if(current >= 0 && ! movie){
			$('.arrow').show();
		  $('#eye-catcher').css({cursor:''});
		} else {
		  $('#eye-catcher').css({cursor:'pointer'});
		}
	},
	function(){
		$('.arrow').hide();
	});
  
  $('a.displaymap').click(function(){
      swapFrontImage(map);
      $('#displaymap-container').hide();
      return false;
  });

  $('#eye-catcher').click(function(){
    if(current == -1){
      window.open(map_link);
    }
    return false;
  });

  $('a#arrow-left').click(function(){
    current = dec(current);
    swapFrontImage(images[current]);
    return false;
  });

  $('a#arrow-right').click(function(){
    current = inc(current);
    swapFrontImage(images[current]);
    return false;
  });

  $('a#pssst').click(function(){
    current = inc(current);
    swapFrontImage(images[current]);
    $('#displaymap-container').show();
    return false;
  });
  
  $('a#next-review').click(function(){
    curr = null;
    count = 0;
    $('.review').each(function(){
      if(! $(this).is(':hidden')){
        curr = $(this).attr('id').replace('review-', '');
        $(this).hide();
      }
      count++;
    });
    curr >= count ? curr=1 : curr=parseInt(curr)+1;
    $('#review-'+curr).show();
    return false;
  });
  
}

function inc(current){
  return current >= images.length-1 ? 0 : current+1;
}

function dec(current){
  return current == 0 ? images.length-1 : current-1;
}

function swapFrontImage(src){
  if(src==map){
    current = -1;
  }
  //console.log('swapping image: '+src);
	$('#eye-catcher').html('');
	movie = false;
  $('#eye-catcher').css( { opacity:0 } ).css( { background:"url('"+src+"') #000 no-repeat" } ).animate( { opacity:1 }, delay);
  //console.log($('#eye-catcher').css('background-image'));
  //console.log($('#eye-catcher').css('background'));
}



