
$(function() {
	/* HIDE FUNCTIONS */

	$("#econtent").hide();
	$("#ec-minus").hide();
	$("#video").hide();
    $("#vipit-info").hide();
    //$("#send").hide();
    $("#share-content").hide();
    //$("#callback").hide();

	/* HIGHLIGHTS */
	
	$('body').removeClass('js-disabled').addClass('js-enabled');
	$('#highlight-nav').navInit();

	/* TABS */

	$('#tabs > ul').tabs();

	/* TESTIMONIALS */

	$('#testimonial blockquote').innerfade({
		speed: 2000,
		timeout: 5500,
		type: 'random_start',
		containerheight: '140px'
	});
	
	/* OPTIONS */

	$('#options').innerfade({
		speed: 1000,
		timeout: 7000,
		type: 'random_start',
		containerheight: '60px'
	});
    
    /* MEDIA CONTROLS */
	
	$("#slideshow-control").click(function () {
		$("#slideshow").show();
		$("#video").hide();
    });
    
	$("#video-control").click(function () {
		$("#slideshow").hide();
		$("#video").show();		
    });
    
    /* WIDGET CONTROLS */
    
    $("li.shareme a").click(function () {
		$("#share-content").toggle();
    });
    
    
	/* VIP IT */
    
	$("#vipit").click(function () {
		$("#vipit-info").toggle();
    	$("#std-price").toggle();
    });
    
	$("#vipit-return").click(function () {
		$("#vipit-info").toggle();
    	$("#std-price").toggle();
    });
   
	
});

$.fn.navInit = function() {
  return this.each(function(){
    var jump_nav = $('.jump a',this);
    jump_nav.click(function() {
			if (scrolling) window.clearInterval(scrolling);
			scrollSplashTo.call(this)
    });

		function scrollSplashTo() {
      var splash = $("#"+$(this).parents('li').get(0).id.replace(/^nav-/, 'highlight-'));
			var splashLeft = splash.parent().children().index(splash) * 940 + 'px';
    
      $("#scroller").animate({scrollLeft: splashLeft}, 1000);
    
      jump_nav.parent("li").removeClass("selected");
      $(this).parent("li").addClass("selected");
      this.blur();
    
      return false;
		}
  
    $('#nav_prev', this).click(function() {
			if (scrolling) window.clearInterval(scrolling);
      $('#highlight-nav .jump li.selected').prev('li').children('a').click();
      return false;
    });
  
    $('#nav_next', this).click(function() {
			if (scrolling) window.clearInterval(scrolling);
      $('#highlight-nav .jump li.selected').next('li').children('a').click();
      return false;
    });

		// initialise the scroller back to the first on page reload incase of DOM caching
    scrollSplashTo.call($('#highlight-nav ul.jump a:first'));
  
		// automate the scroller
		var scrolling = window.setInterval(function(){
			currentLi = $('#highlight-nav .jump li.selected');
			if (currentLi.next('li').length>0) {
				scrollSplashTo.call(currentLi.next('li').children('a'));
			}
			else {
				scrollSplashTo.call($('#highlight-nav .jump li:first>a'));
			}
		},9000);
  });
}
