var GialloRossa = {
  
  sound: 'sounds/goal.wav',
  
	
	start: function() {
	  $('html').addClass('js');
		if ($('body').is('#splash')) {
      // this.activateSplash();
		}
		if ($('body').is('.delivery')) {
		  this.enhanceScrollbars();
		}
		this.enhanceGallery();
		this.enhanceCopy();
    //this.enableSounds();
    this.enablePrint();
	},
	
	activateSplash: function() {
		$('li a').bind('click', function(e) {
			var strWindowFeatures = "menubar=no,location=no,resizable=no,scrollbars=no,status=no,";
			var strWindowDimensions = 'height=713, width=1000';
			window.open(this.href, 'Giallo Rossa', strWindowFeatures + strWindowDimensions);
			e.preventDefault();
		});
	},
	
	enhanceScrollbars: function() {
	  $('.scrollable').jScrollPane({
	    showArrows: true,
	    scrollbarWidth: 21,
	    arrowSize: 13
	  });
	},
	
	enhanceGallery: function() {
    // <ul class="gallery-steps">
    //   <li class="first-child previous"><a href="">Previous</a></li>
    //   <li class="next"><a href="">Next</a></li>
    // </ul>
		$('#content-gallery').each(function(i) {
		  var $this = $(this);
		  var width = 424;
		  var $gallery_nav = $this.find('.gallery-navigation');
		  var $gallery_pages = $this.find('.gallery-pages');
		  var $gallery_wrapper = $this.find('.gallery-thumbs-wrapper');
		  var $gallery_target = $this.find('.gallery-target');
		  
		  // add navigation arrows
		  var $gallery_steps = $('<ul class="gallery-steps"/>');
		  var $gallery_prev_cont = $('<li class="first-child previous"/>');
		  var $gallery_next_cont = $('<li class="next"/>');
		  var $gallery_prev = $('<a href="">Previous</a>');
		  var $gallery_next = $('<a href="">Next</a>');
      $gallery_prev.appendTo($gallery_prev_cont);
      $gallery_next.appendTo($gallery_next_cont);
		  $gallery_steps.append($gallery_prev_cont, $gallery_next_cont).appendTo($gallery_nav);
		  
		  // was gallery index specified by the URL hash?
		  var hash = /#gallery-\d$/;
  		var loc = document.location.href;
  		var page = 0;
  		if (loc.match(hash)) {
  			active = hash.exec(loc)[0].split('-')[1] - 1;
  		}
  		
  		// handle clicking on arrows
  		$gallery_steps.find('a').bind('click', function(e) {
  		  var is_prev = $(this).parent().is('.previous');
  		  if (is_prev) {
  		    page--;
  		    if (page < 0) { page = 0; }
  		  } else {
  		    page++;
  		    if (page > 2) { page = 2; }
  		  }
  		  $gallery_wrapper.animate({
		      left: 0 - (width * page)
		    });
        e.preventDefault();
  		});
  		
  		// handle clicking on tabs
  		$gallery_pages.find('a').bind('click', function(e) {
  		  var clicked = this.href.split('-')[1] - 1;
  		  $gallery_wrapper.animate({
		      left: 0 - (width * clicked)
		    });
        e.preventDefault();
  		});
  		
  		// handle clicking on pictures
  		$gallery_wrapper.find('a').lightBox();

		});
	},
	
	enhanceCopy: function() {
	  $('#content-navigation li').each(function() {
  	  var left = 0;
  	  if ($(this).is('.next')) {
        left = -616;
  	  }
  	  $(this).find('a').bind('click', function(e) {
  	    $('#content-primary-secondary-wrapper').animate({
  	      left: left
  	    });
        e.preventDefault();
  	  });
	  });
	},
	
	enableSounds: function() {
	  var url = this.sound;
	  
	  // all elements making sounds when moused over
	  var selectors = [
	    '#splash ul a',
	    '#content-title a',
	    '#link-signin a',
	    '#nav-restaurant a',
	    '#nav-take-away a'
	  ];
	  
	  for (var i=0; i < selectors.length; i++) {
	   $(selectors[i]).bind('mouseover', function(e) {
        $.sound.play(url, {
          timeout: 5000
        });
        e.preventDefault();
  	  });
	  };
	},
	
	enablePrint: function() {
	  $('#func-print a').bind('click', function(e) {
	    window.print();
      e.preventDefault();
	  });
	}
};

$(function() {
	GialloRossa.start();
});