$(document).ready(function() {
	/* If JS is present then Typekit should run, 
	so we can add a class to adjust the font sizing for Liberation Serif */
	$(".tk").addClass("tk-liberation-serif");

	get_tabbed();
  
  $.localScroll({
    duration:500,
    offset:-65,
    hash:true 
  });
  
	/* Remove Skype Plugin styling */
	window.setTimeout(function() {
		$('.skype_pnh_container').html('');
		$('.skype_pnh_print_container').removeClass('skype_pnh_print_container');
	}, 800);
  
  show_products();
	
	$("#tab1").click(show_products);
	$("#tab2").click(show_applications);
	$("#tab3").click(show_formulations);
});

function get_tabbed() {
	var $ctrl = $("#control");
	$("#control").addClass("tabbed");
	var $h3s = $ctrl.find("h3");
	
	var $list = $("<ul id=\"tabs\"></ul>");
	$h3s.each(function(i){
		_h3 = $(this);
		_h3.addClass("off_left");
		
		$list.append($("<li id=\"tab" + (i+1) + "\"></li>")
			.html(_h3.html())
		);
	});
	$ctrl.append($list);
	$("#leadin").html($("#leadin").text());
}

function show_products() {
	if ($("#tab1").hasClass("current")){ }
	else {
		$(".tab div").fadeOut(500);
		$(".tab div").hide();
		setTimeout("$('.tab div').hide();", 500);
		setTimeout("$('#products div').show();", 500);
		$("#products div").fadeIn(500);
		$("#tabs li").removeClass("current");
		$("#tab1").addClass("current");
	}
}

function show_applications() {
	if ($("#tab2").hasClass("current")){ }
	else {
		$(".tab div").fadeOut(500);
		$(".tab div").hide();
		setTimeout("$('.tab div').hide();", 500);
		setTimeout("$('#applications div').show();", 500);
		$("#applications div").fadeIn(500);
		$("#tabs li").removeClass("current");
		$("#tab2").addClass("current");
	}
}

function show_formulations() {
	if ($("#tab3").hasClass("current")){ }
	else {
		$(".tab div").fadeOut(500);
		$(".tab div").hide();
		setTimeout("$('.tab div').hide();", 500);
		setTimeout("$('#formulations div').show();", 500);
		$("#formulations div").fadeIn(500);
		$("#tabs li").removeClass("current");
		$("#tab3").addClass("current");
	}
}

function news_fade() {
	$("body").removeClass("no_js");

	var current = $("#news .current");
	var next = current.next().length ? current.next() : current.parent().children(":first");
	current.hide().removeClass("current");
	next.fadeIn().addClass("current");
	
	setTimeout(news_fade,7000);
}

