$(document).ready(function() {
  /* set variables locally for increased performance */
	var scroll_timer;
	var displayed = false;
	var $brand = $('#brand a');
	var $window = $(window);
	var top = $(document.body).children(0).position().top; 
	/* react to scroll event on window */
	$window.scroll(function () {
		window.clearTimeout(scroll_timer);
		scroll_timer = window.setTimeout(function () { // use a timer for performance
			if($window.scrollTop() <= top) // hide if at the top of the page
			{
				displayed = false;
				$brand.fadeOut(500);
			}
			else if(displayed == false) // show if scrolling down
			{
				displayed = true;
				$brand.stop(true, true).fadeIn().click(function () { $brand.fadeOut(500); });
			}
		}, 100);
	});
  $(".tooltip").tooltip({ effect: 'slide', offset:[100, 0]});
  $('#services-slider').tinycarousel({ controls: false, pager: true, duration: 500 });
  $('#package-slider').tinycarousel({ controls: false, pager: true, duration: 500 });	
  // hover...
  // $("#splash").tabs({ event: "mouseover"}).tabs("rotate", 10000, true);
  $("#splash").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 10000, true);
  $("#splash").hover( 
  function() { 
  $("#splash").tabs("rotate",0,true); 
  }, 
  function() { 
  $("#splash").tabs("rotate",10000,true); 
  });  
	$('.faq-toggle').click(function () {
	  $(this).toggleClass('faq-toggle-on');
    $(this).next('.faq-answer').slideToggle('fast');
    $(this).parent('div').toggleClass('view');
  });
  $("ul#nav li").hover(function() { //Hover over event on list item
    $(this).find("div").fadeIn('fast'); //Show the subnav
  } , function() { //on hover out...
   $(this).find("div").hide(); //Hide the subnav
  });  
  $("#nav div a:last-child").addClass("non");
	$("a[rel=fancybox]").fancybox({
	  'padding'         : '0', 
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
  		
  $('#quotes').tinycarousel({
   axis: 'y',
   interval: true,
   intervaltime: 6000,
   controls: false,
   duration: 1000
  });
  var anchor = $(document).attr('location').hash; // the anchor in the URL
	if (anchor.match('#')) { // the URL contains an anchor
		$('.pager a[href="' + anchor + '"]').click();
	} else {
	  $('.pager li a:first').click();
	}
});

