function mycarousel_initCallback(carousel) {
    jQuery('#jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		$("#jcarousel-control > li > a").removeClass("current");
		$(this).addClass("current");
        return false;
    });
};

function fadeHeader() {
    var image = $('#headerfade1');
	var image2 = $('#headerfade2');
	if ($(image2).css("display")=="block" || $(image2).css("display")=="inline") {
		$(image2).fadeOut("200");
		timer = setTimeout('fadeHeader()',7000);
	} else {
		$(image2).fadeIn("200");
		timer = setTimeout('fadeHeader()',2000);
	}
}

$(document).ready(function(){
	//skiptag = false;
	//$('#headerfade1').after('<img src="/res/images/logo2.jpg" width="349" height="97" alt="Txtlocal" id="headerfade2" style="display:none;" />');
	//timer = setTimeout('fadeHeader()',5000);
	
	if ($(".featurelist").length) {
		//$('.featurelist').contents().corner();
		//$('.featurelist').contents().find('strong').corner("top 5px");
	}

	if ($(".tabs").length) { //If .tabs are found, generate tabed content area (as seen on /api/)
		$(function () {
			var tabContainers = $('div.tabs > div');    
			$('div.tabs ul.tabNavigation a').click(function () {
				tabContainers.hide().filter(this.hash).show();        
				$('div.tabs ul.tabNavigation a').removeClass('selected');
				$(this).addClass('selected');        
				return false;
			}).filter(':first').click();
		});
	}
	
	if ($(".twisties").length) { //If .twisties are found, make the H2 show/hide the below DIV (as seen on /prices/)
		$('div.twisties > h2').addClass("twist");
		$('div.twisties > h2').each(function(element) {
			if ($(this).attr("id")=="expanded") {
				$(this).next().show();
				$(this).toggleClass("twist-down");
			} else {
				$(this).next().hide();
			}
		});
		$('div.twisties > h2').click(function() {
			$(this).toggleClass("twist-down");
			$(this).next().slideToggle('fast');
		});
	}
	
	if ($("#clientlogos").length) {
		$('#clientlogos div').css("display","none");
		$('#clientlogos div#set1').css("display","block");
		fadeEngine(0);
	}
	
	if ($("#carousel").length) {
		$('#bar02').show();
		$('#bar03').show();
		$('#bar04').show();
		$('#bar05').show();
		$("#carousel").after("<ol id=\"jcarousel-control\"><li class=\"one\"><a href=\"#\" class=\"current\"><span>1</span></a></li><li class=\"two\"><a href=\"#\"><span>2</span></a></li><li class=\"three\"><a href=\"#\"><span>3</span></a></li><li class=\"four\"><a href=\"#\"><span>4</span></a></li><li class=\"five\"><a href=\"#\"><span>5</span></a></li></ol>");
	}
	
	$('table tr:odd').addClass('alt'); 
		
});

jQuery(document).ready(function() {
    jQuery('#carousel').jcarousel({
        scroll: 1,
		start: 1,
		animation: "slow",
        initCallback: mycarousel_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null,
        auto: 5,
        wrap: 'last',
		itemFirstInCallback:  mycarousel_itemFirstInCallback
    });
});

function mycarousel_itemFirstInCallback(carousel, item, idx, state) {
	$("#jcarousel-control li a").removeClass("current");
	if (idx=="1") {$("#jcarousel-control > li.one > a").addClass("current");}
	if (idx=="2") {$("#jcarousel-control > li.two > a").addClass("current");}
	if (idx=="3") {$("#jcarousel-control > li.three > a").addClass("current");}
	if (idx=="4") {$("#jcarousel-control > li.four > a").addClass("current");}
	if (idx=="5") {$("#jcarousel-control > li.five > a").addClass("current");}
};

function fadeEngine(x) {
	var total_divs=5;
	var y=x;
	if(x==total_divs) y=1; else y++;
	$("#set"+x).css("display","none");
	$("#set"+y).fadeIn("slow");
	setTimeout('fadeEngine('+y+')',5000);
}

