// JavaScript Document
var mycarousel_itemList = [
    {title: 'Quit Tip 1', content: 'Make a quit plan. Pick a date and make a list of reasons you want to quit.', id:'quit-title-1'},
    {title: 'Quit Tip 2', content: 'Prepare for your quit date. This means getting rid of all  tobacco-related items, such as ashtrays, lighters and matches.', id:'quit-title-2'},
	{title: 'Quit Tip 3', content: 'Ask your family and friends to support you in your quit attempt. Tell them your quit date and ask them to be supportive and understanding.', id:'quit-title-3'},
	{title: 'Quit Tip 4', content: 'Keep a picture of your loved ones. Tape a message to the picture that reminds you that you are quitting for them. Look at the picture and read the message anytime you have an urge to smoke.', id:'quit-title-4'},
	{title: 'Quit Tip 5', content: 'When you feel an urge to reach for a cigarette, try taking a walk, playing with your kids or running up and down the stairs instead of lighting up.', id:'quit-title-5'},
	{title: 'Quit Tip 6', content: 'For the first few days after you quit smoking, spend as much free time as possible in public places where smoking is not allowed.', id:'quit-title-6'},
	{title: 'Quit Tip 7', content: 'Reward yourself when you reach milestones in your quit attempt, such as buying yourself a new book or treating yourself to a nice dinner with a supportive friend.', id:'quit-title-7'},
	{title: 'Quit Tip 8', content: 'Keep healthy snacks, gum, mints and toothpicks around, and drink plenty of water.', id:'quit-title-8'},
	{title: 'Quit Tip 9', content: 'Try to avoid people, places or other trigger habits you typically associate with smoking.', id:'quit-title-9'},
	{title: 'Quit Tip 10', content: 'Take deep, slow breaths and imagine your lungs filling with clean, fresh air.', id:'quit-title-10'},
	{title: 'Quit Tip 11', content: 'Create a smoke-free rule for your home and car. Smoke-free environments can support you in the quitting process.', id:'quit-title-11'},
	{title: 'Quit Tip 12', content: 'Don&acute;t give up. Most people have to try several times to quit smoking. You can do it.', id:'quit-title-12'}
];

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]));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    return '<h3 id="' + item.id + '">' + item.title + '</h3><p>' + item.content + '</p>';
};

jQuery(document).ready(function() {
	p = (mycarousel_itemList.length);
	quitNext = "'/quit-tip/next'";
	quitPrevious = "'/quit-tip/previous'";
	whichImage = Math.round(Math.random()*(p));
	if(whichImage == 0){
		whichImage = 1;
	}
	jQuery('#mycarousel').jcarousel({
        scroll: 1,
		animation: "fast",
		wrap: 'circular',
		start: whichImage,
		buttonNextHTML: '<a onClick="javascript: pageTracker._trackPageview('+quitNext+');"></a>',
		buttonPrevHTML: '<a onClick="javascript: pageTracker._trackPageview('+quitPrevious+');"></a>',
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });
});