$(document).ready(function(){
  
    // Fade BG on reference page
    if ($('body').hasClass('fade-bg')) {
        $('.fade').animate({opacity:0.95}, 2000);
    }

    // Highlight navigation
    var nav  = $('ul.navigation'),
        path = window.location.pathname,
        els = [];
    if (path.length) {
        for (; path.length; path.pop()) {
            els = nav.find('li>a[href="' + path + '"]').addClass("current");
            if (els) {
                break;
            }
        }
    } else {
        nav.find('li>a[href="/"]').addClass('current');
    }

    // Services
    $('#services dd').hide().eq(0).slideDown('slow').prev().addClass('active');
    $('#services dt')
        .hover(function() {
            $(this).addClass('hover')
        },function(){
            $(this).removeClass('hover')
        })
        .click(function() {
            $('#services dd').slideUp('fast').prev().removeClass('active');
            $(this).toggleClass('active').next().slideToggle('normal');
        });

    // Parallax effects
    /*
    $('#foreground').parallax({
      mouseport: $("body")
    });
    */
    $('#news-content > div').parallax({
        mouseport: $("#news-content")
    });
    $('#gallery-nav2 > ul').parallax({
        mouseport: $("#gallery-nav2")
    });

    // Fancybox
    $(".lightbox").fancybox({
        'overlayOpacity': 0.95,
        'overlayColor': '#2a190e',
        'titlePosition': 'inside'
    });
    $(".overlay").fancybox({
        'overlayOpacity': 0.95,
        'overlayColor': '#2a190e',
        'type': 'iframe',
        'width': 800,
        'height': 600
     });
     
     // Presentation on homepage
     $('#presentation').orbit({
          animation: 'vertical-slide',
          timer: true, 			 // true or false to have the timer
          advanceSpeed: 4000, 		 // if timer is enabled, time between transitions 
          pauseOnHover: false, 		 // if you hover pauses the slider
          startClockOnMouseOut: false, 	 // if clock should start on MouseOut
          startClockOnMouseOutAfter: 1000, 	 // how long after MouseOut should the timer start again
          directionalNav: false, 		 // manual advancing directional navs
          bullets: true			 // true or false to activate the bullet navigation
     });

    var initScrollable = function () {
        $('.scrollable').scrollable({
            onBeforeSeek: function (e, index) {
                if (index + 1 <= this.getSize()) { // we need this stupid guard,
                                                   // because onBeforeSeek is
                                                   // triggered even if we're
                                                   // already on the last item
                    this.getRoot().parent().find('.currentPos').text(index + 1);
                }
            }
        });
    };
    initScrollable();

    $('.refs a').pjax({
        container: '.gallery-content',
        fragment: '.gallery-content'
    }).live('click', function (e) {
        $('.refs a').not($(this).addClass('current')).removeClass('current');
    });
    $('#gallery').live('end.pjax', function () {
        initScrollable();
    });
		
		// Tooltips
		$('#gallery-nav1 > li > a').qtip({
		   content: {
		   		attr: 'title'
		   },
		   style: {
		   		classes: 'ui-tooltip-youtube'
		   },
			 position: {
					target: 'mouse',
			 		my: 'top left',
					at: 'bottom right',
					adjust: {
							x: 10,
							y: 10
					}
			 }
		})
		
});

