$(document).ready(function() {
	openSubNav();
	theRotator();
	pdfChecker();
	tabSwitcher();
	VideoJS.setupAllWhenReady();
	videoLightbox();
	contactForm();
	$('.home #contentWrap').readMore({
		'characters'	:	300
	});
	
	$("#toutCol0").find('.reduceText').readMore({
		'characters'	:	148
	});
	
	$("#toutCol1").find('.reduceText').readMore({
		'characters'	:	340
	});
});



function openSubNav()
{
	var subNavActiveCheck = $("#secondNav li.active ul li.active").length;
	var ulHeight = $("#secondNav li.active ul").outerHeight();

	if (subNavActiveCheck !=0)
	{
		$("#secondNav li.active ul").show();
	}else
	{
		$("#secondNav li.active ul").slideDown(
			{
				duration	:	1000,
				easing		:	'easeOutBack'
			}
		);
	}

}

var rotatorTime = 4000,
	fadeTime = 1000;

function theRotator() {
	$('#rotators li').hide();
	$('#rotators li:first').show();
	setInterval('rotate()',rotatorTime);
}

function rotate() {
	//Get the first image
	var current = ($('#rotators li.show') ? $('#rotators li.show') : $('#rotators li:first'));
	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#rotators li:first'):current.next()): $('#rotators li:first'));
	//Set the fade in effect for the next image, the show class has higher z-index
	next.addClass('show').fadeIn(fadeTime);
	//Hide the current image
	current.fadeOut(fadeTime).removeClass('show');
}

function pdfChecker()
{
 $("#mainCol").find('a[href$=".pdf"]').addClass('pdf');	
}

function tabSwitcher()
{
	$("#productTabs li").click(function(){
		
		var thisid = $(this).attr('id');
		
		$('#productTabs li').removeClass('active');
		$(this).addClass('active');

			$("#productDivsWrap .productDiv").removeClass('active');
			$("#productDivsWrap ."+thisid).addClass('active');
		
/*
		$("#productDivsWrap").slideUp(500,function(){
			$("#productDivsWrap .productDiv").removeClass('active');
			$("#productDivsWrap ."+thisid).addClass('active');
			$("#productDivsWrap").slideDown(500);
		});
*/
		
	});
}

function videoLightbox()
{
	$(".lightboxVideo").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'autoDimensions'	: false,
		'width'			:	640,
		'height'		:	360,
		'type'			:	'iframe',
		'scrolling'		:	'no',
		'padding'		:	0
	});
}

function contactForm(){

	$(".contactLink").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'autoDimensions'	: false,
		'width'			:	410,
		'height'		:	340,
		'type'			:	'iframe',
		'padding'		:	40
	});
}
