// JavaScript Document
if($.browser.msie) {
	var mycarousel_itemList = [
		{url: './img/scroll_drruth.jpg', title: 'slide-drruth', slidetext: '<div class="white-box"><a href="./our-ads/#dr-ruth"><strong>Dr. Ruth and Corn Sugar:</strong><br/> Watch our latest commercial</a></div>'},
		{url: './img/scroll_sciencenutrition.jpg', title: 'slide-science', slidetext: '<div class="white-box"><a href="./science-and-nutrition"><strong>Science &amp; Nutrition:</strong><br/> Separate scientific fact from sweetener fiction</a></div>'},
		{url: './img/scroll_mythmakers.jpg', title: 'slide-mythmakers', slidetext: '<div class="white-box"><a href="./mythmakers/"><strong>Sweet Secrets:</strong><br/> Find out who&rsquo;s scamming your sweets</a></div>'},
		{url: './img/scroll_commercial.jpg', title: 'slide-commercial', slidetext: '<div class="white-box"><a href="jw-player/player.swf?flashvars=file=../img/SweetScam-lineup.mp4&allowfullscreen=true&image=img/SweetScam-lineup.jpg?allowscriptaccess=always" rel="prettyPhoto" ><strong>Sweetener Lineup:</strong><br/> Watch our commercial</a></div>'},
		{url: './img/scroll_howitsmade.jpg', title: 'slide-howitsmade', slidetext: '<div class="white-box"><a href="./how-its-made/"><strong>How It&rsquo;s Made:</strong><br/> Sugar cubes don&rsquo;t grow on trees. See how all sweeteners are processed</a></div>'},
			{url: './img/scroll_printad.jpg', title: 'slide-printad', slidetext: '<div class="white-box"><a href="./img/ad_wronglyAccusedFull.jpg" rel="prettyPhoto" ><strong>Wrongly Accused:</strong><br/> Check out our nationally running ad</a></div>'},
		{url: './img/scroll_mythfacts.jpg', title: 'slide-mythsfacts', slidetext: '<div class="white-box"><a href="./myths-and-facts/"><strong>Myths &amp; Facts:</strong><br/> Get the facts about Sweeteners</a></div>'},
		{url: './img/scroll_quiz.jpg', title: 'slide-quiz', slidetext: '<div class="white-box"><a href="./quiz/"><strong>Quiz:</strong><br/> Take the Sweetener Quiz</a></div>'}
	
	];
} else {
	var mycarousel_itemList = [
			{url: './img/scroll_drruth.jpg', title: 'slide-drruth', slidetext: '<a class="bigclickarea clearfix" href="./our-ads/#dr-ruth"><div class="white-box"><a href="./our-ads/#dr-ruth"><strong>Dr. Ruth and Corn Sugar:</strong><br/> Watch our latest commercial</a></div></a>'},
		
		{url: './img/scroll_sciencenutrition.jpg', title: 'slide-science', slidetext: '<a class="bigclickarea clearfix" href="./science-and-nutrition"><div class="white-box"><a href="./science-and-nutrition"><strong>Science &amp; Nutrition:</strong><br/> Separate scientific fact from sweetener fiction</a></div></a>'},
		{url: './img/scroll_mythmakers.jpg', title: 'slide-mythmakers', slidetext: '<a class="bigclickarea clearfix"  href="./mythmakers/"><div class="white-box"><a href="./mythmakers/"><strong>Sweet Secrets:</strong><br/> Find out who&rsquo;s scamming your sweets</a></div></a>'},
		{url: './img/scroll_commercial.jpg', title: 'slide-commercial', slidetext: '<a class="bigclickarea clearfix" href="jw-player/player.swf?flashvars=file=../img/SweetScam-lineup.mp4&allowfullscreen=true&image=img/SweetScam-lineup.jpg?allowscriptaccess=always" rel="prettyPhoto"><div class="white-box"><a href="jw-player/player.swf?flashvars=file=../img/SweetScam-lineup.mp4&allowfullscreen=true&image=../img/SweetScam-lineup.jpg?allowscriptaccess=always" rel="prettyPhoto" ><strong>Sweetener Lineup:</strong><br/> Watch our commercial</a></div></a>'},
		{url: './img/scroll_howitsmade.jpg', title: 'slide-howitsmade', slidetext: '<a class="bigclickarea clearfix" href="./how-its-made/"><div class="white-box"><a href="./how-its-made/"><strong>How It&rsquo;s Made:</strong><br/> Sugar cubes don&rsquo;t grow on trees. See how all sweeteners are processed</a></div></a>'},
			{url: './img/scroll_printad.jpg', title: 'slide-printad', slidetext: '<a class="bigclickarea clearfix" href="./img/ad_wronglyAccusedFull.jpg" rel="prettyPhoto"><div class="white-box"><a href="./img/ad_wronglyAccusedFull.jpg" rel="prettyPhoto" ><strong>Wrongly Accused:</strong><br/> Check out our nationally running ad</a></div></a>'},
		{url: './sweetscam/img/scroll_mythfacts.jpg', title: 'slide-mythsfacts', slidetext: '<a class="bigclickarea clearfix" href="./myths-and-facts/"><div class="white-box"><a href="./myths-and-facts/"><strong>Myths &amp; Facts:</strong><br/> Get the facts about Sweeteners</a></div></a>'},
		{url: './sweetscam/img/scroll_quiz.jpg', title: 'slide-quiz', slidetext: '<a class="bigclickarea clearfix" href="./quiz/"><div class="white-box"><a href="./quiz/"><strong>Quiz:</strong><br/> Take the Sweetener Quiz</a></div></a>'}
	
	];
}

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
	// The index() method calculates the index from a
	// given index who is out of the actual item range.
	var idx = carousel.index(i, mycarousel_itemList.length);
	carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
	
	
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'fast', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: true, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	});
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
	carousel.remove(i); 
	// AJT - Removing the above line makes it so the old list item doesn't disappear, but it does make the HTML get very long
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
	return '<div class="slide-wrapper"><div class="slide ' + item.title + '">' + item.slidetext + '</div></div>';
	// return '<img src="' + item.url + '" width="480" height="325" alt="' + item.title + '" />';
};

jQuery(document).ready(function() {
	var carousel_arr = [];

	blah = jQuery('#mycarousel').jcarousel({
		// Configuration goes here
		auto: 8,
		scroll: 1,
		start: 1,
		easing:'easeInOutCubic',
		animation:1500,
		/*visible: 5,*/
		wrap: 'circular',
		// initCallback: carouselInitCallback,
		itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
		itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
	});
	
	$("#twitter li").each(function(z) {
		if(!$(this).is('.last')) {
			$(this).children('.serif').html(prototype.string.autolink($(this).text()));
		}
	});
/*
	function carouselInitCallback(carousel){
		$.each($('#mycarousel ul').children(),function(){
			carousel_arr.push($(this).html());
		});
		$('.jcarousel-next,.jcarousel-prev').insertAfter('#carousel-wrap');
		var auto_carousel = setInterval("scrollCarousel()", 5000);
		$('#mycarousel, .jcarousel-next, .jcarousel-prev').mouseover(function(e){
			e.stopPropagation();
			
			carousel.options.animation = 1000;
			carousel.options.easing = 'easeOutCubic';
			clearInterval(auto_carousel);
			carousel.startAuto(0);
			
			// Adds mouseover function for body, to resume auto carousel motion
			// Added 2009-03-25
			$('body').mouseover(function(){
				carousel.options.animation = 1500;
				carousel.options.easing = 'easeInOutCubic';
				$('.jcarousel-next').trigger('click');
				auto_carousel = setInterval("scrollCarousel()", 5000);
				$(this).unbind('mouseover');
			});
			
		});
	}

	// Fired after carousel move, removes item from end of carousel (same one which was appended beforehand)
	function carouselOutCallback(carousel, item, i, state, evt){
		carousel.remove(i);
	}
	
	// Fired before carousel moved, appends new item to carousel to give illusion of infininate list
	function carouselInCallback(carousel, item, i, state, evt){
		var idx = carousel.index(i, carousel_arr.length);
		new_item = carousel.add(i,carousel_arr[idx - 1]);
	}
*/
});
	
var prototype = {};
prototype.string = {};

prototype.string.autolink = function (tweet, options){
	
  if(tweet.search(/(https?:\/\/[-\w\.]+:?\/[\w\/_\.]*(\?\S+)?)/) > -1) {
    tweet = tweet.replace(/(https?:\/\/[-\w\.]+:?\/[\w\/_\.]*(\?\S+)?)/, "<a href='$1'>$1</a>")
  }

  if(tweet.search(/@\w+/) > -1) {
    tweet = tweet.replace(/(@)(\w+)/g, "$1<a href='http://twitter.com/$2'>$2</a>");
  }

  return tweet;
};


