/*
	Author: NetConstruct, Alastair Hodgson
*/

$('html').removeClass('no-js');


// Fix inputs with placeholders
$('input[placeholder], textarea[placeholder]').placeholder();

//Create fading dropdowns and fixes ie6 li:hover fix
$('#h1 nav ul').superfish();


// enable home banner using jQuery ui tabs
$('#home #tabs').tabs({
	event: 'mouseover',
	fx: {
		opacity: "toggle",
        duration: 'fast'
	}
}).tabs("rotate", 4000, false);


// Create tab interface for the product page
$('#tabs-02').tabs({
    event: 'mouseover',
    fx: {
        opacity: "toggle",
        duration: 'fast'
    }
}).tabs("rotate", 4000, false);

(function () {
    var height = 0;

    $('#tabs-02 .slideWrapper-02 div').each(function () {
        var thisHeight = $(this).height();

        if (thisHeight > height) {
            height = thisHeight;
        }
    });

    $('#tabs-02 .slideWrapper-02').height(height + 15);
})();



// Gallery image swapper that creates thumbnails and page numbers,
// check to see if gallery exists first otherwise we get an error from the cycle plugin
if($('#gallery').length) {
	$('#gallery .imgWrap').after('<ul class="noBullet" id="galleryNav">').cycle({
		fx:     'fade',
		speed:  'fast',
		timeout: 0,
		pager:  '#galleryNav',

		// callback fn that creates a thumbnail to use as pager anchor
		pagerAnchorBuilder: function(idx, slide) {
		    return '<li><a href="#"><img src="' + $(slide).children('a').children('img').attr('src') + '"></a></li>';
		},
	    next:   '#galleryNext',
	    prev:   '#galleryPrev', 
	    after:  onAfter
	});
}

// callback function used by the above gallery script call
function onAfter(curr,next,opts) {
	var caption = (opts.currSlide + 1) + ' of ' + opts.slideCount;
	$('#gallery p.slideIndex').html(caption);
}

$(function() {
	// Use this example, or...
	$('a[rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
});



// Brewery Process Script
if ($('.videoLinkA').length) {

    $(".videoLinkA").fancybox({
        'modal': true,
        'titleShow': false,
        'overlayColor': '#000',
        'overlayOpacity': 0.5,
        'speedIn': 300,
        'speedOut': 300,
        'padding': 0,
        'onComplete': function (el) {
            var modalElem = $(el).attr('href');
            $('article', modalElem).delay(1000).fadeIn('slow');
        }
    });

    $('#VideoPlayer .close').click(function(){
      $(this).parent('article').fadeOut('fast');

      setTimeout(function(){
        $.fancybox.close();
      }, 300)

      return false;
    })
}
