var mycarousel_itemList = [

          {type:'image',
            thumb:'/images/slide_show/thumb/How_we_fight_wildfires_thmb.jpg',
            large:'<a href=/FightingWildfire/Crews/><img src=/images/slide_show/How_we_fight_wildfires.jpg></a>',
            alt:'Learn What It Takes to Be a World-Class Wildfire Fighter',
   			cutline:'<a href=/FightingWildfire/Crews><h4>What does it take to be a wildfire fighter?</h4><p>B.C. has some of the world&rsquo;s most sought-after wildfire fighters. Comprehensive training and professional standards help our crews prepare for challenging fires across the province. Learn more about the different types of wildfire fighters at work each summer.</p></a>'},
             
            {type:'image',
            thumb:'/images/slide_show/thumb/How_aircraft_help_fight_fires_thmb.jpg',
            large:'<a href=/FightingWildfire/Aviation/><img src=/images/slide_show/How_aircraft_help_fight_fires.jpg></a>',
            alt:'Fighting Wildfires From Above',
   			cutline:'<a href=/FightingWildfire/Aviation><h4>Fighting Wildfires From Above</h4><p>B.C.&rsquo;s highly-mobile airtanker program supports ground crews and stops small fires from spreading. Learn about the different tools we use to fight fire from the air.</p></a>'},

            {type:'image',
            thumb:'/images/slide_show/thumb/Prescribed_Fire_thmb.jpg',
            large:'<a href=/Prevention/fuelmanagement.htm><img src=/images/slide_show/Prescribed_Fire.jpg></a>',
            alt:'Managing B.C.&rsquo;s Forest Fuels',
   			cutline:'<a href=/Prevention/fuelmanagement.htm><h4>Managing B.C.&rsquo;s Forest Fuels</h4><p>Years of fire suppression in B.C. communities have contributed to a build-up of flammable debris in surrounding forests. Learn how prescribed fire and fuel management can protect your community while restoring natural ecosystems.</p></a>'},
			
			      {type:'image',
            thumb:'/images/slide_show/thumb/2009_C40429_KellyCreekSept2_RockyMtnUC_BCFS(Gwen_Eamer)106_thmb.jpg',
            large:'<a href=/FightingWildfire/><img src=/images/slide_show/2009_C40429_KellyCreekSept2_RockyMtnUC_BCFS(Gwen_Eamer)106.jpg></a>',
            alt:'How We Fight Wildfires',
   			cutline:'<a href=/FightingWildfire><h4>How We Fight Wildfires</h4><p>Ever wonder how we put out wildfires? Learn about different types of fires, and the tactics we use to manage them.</p></a>'},
				
				    {type:'image',
            thumb:'/images/slide_show/thumb/2005_Rose_Valley_Fire_BCFS(Ryan_Bouchard)_thmb.jpg',
            large:'<a href=/hprScripts/WildfireNews/Bans.asp><img src=/images/slide_show/2005_Rose_Valley_Fire_BCFS(Ryan_Bouchard).jpg></a>',
            alt:'Why Restrict Burning?',
   			cutline:'<a href=/hprScripts/WildfireNews/Bans.asp><h4>Why Restrict Burning?</h4><p>Learn more about the fine balance between the responsible use of fires and protecting B.C.&rsquo;s communities from wildfire emergencies.</p></a>'},
    
            {type:'image',
            thumb:'/images/slide_show/thumb/Prevent_your_fire_from_escaping_thmb.jpg',
            large:'<a href=/Prevention/FireSmart.htm><img src=/images/slide_show/Prevent_your_fire_from_escaping.jpg></a>',
            alt:'FireSmart Your Home and Property',
   			cutline:'<a href=/Prevention/FireSmart.htm><h4>FireSmart Your Home and Property</h4><p>Have you taken steps to protect your home in the event that a wildfire threatens your community? Learn more about FireSmart landscaping, building and property maintenance.</p></a>'},

            {type:'image',
            thumb:'/images/slide_show/thumb/2004_ShawnHeather_BCFS_thmb.jpg',
            large:'<a href=/AboutUs/><img src=/images/slide_show/2004_ShawnHeather_BCFS.jpg></a>',
            alt:'Learn More About Our Organization',
   			cutline:'<a href=/AboutUs><h4>Learn More About Our Organization</h4><p>The Wildfire Management Branch has been responding to wildfires since 1912. Find out what makes our organization internationally-recognized, learn where fire centres are located and get in touch with our staff.</p></a>'},

            {type:'image',
            thumb:'/images/slide_show/thumb/2008_CFCSmokeytheBearintheStampedeParade_BCFS(RLloyd)_thmb.jpg',
            large:'<a href=/Prevention/><img src=/images/slide_show/2008_CFCSmokeytheBearintheStampedeParade_BCFS(RLloyd).jpg></a>',
            alt:'Half of All Wildfires Caused by People',
   			cutline:'<a href=/Prevention><h4>Half of All Wildfires Caused by People</h4><p>Every year, half of B.C.&rsquo;s wildfires are caused by people. These fires are entirely preventable. Learn how to prevent wildfires: tips to safely burn debris on your property, build a responsible campfire and landscape your home to limit the impact of wildfires.</p></a>'}						

];

function initializeCarousel() {

	var randomnumber=Math.floor(Math.random()*mycarousel_itemList.length)
	var item = mycarousel_itemList[randomnumber];
	if(item.type == 'image')
		updateCarousel(item.large, item.cutline)
	if(item.type == 'flash')
		create_flashCarousel(item.video, item.large, item.cutline);
}				

function create_flashCarousel(video, large, cutline)
{
	ReplaceCutline(cutline);
	var so = new SWFObject('/images/flash/player.swf','mpl','400','285','9');
	so.addParam('allowfullscreen','true');
	so.addParam('allowscriptaccess','always');
	so.addParam('wmode','opaque');
	so.addVariable('file', video);
	so.addVariable('image', large);
	so.write('display');
};

function updateCarousel(image, cutline)
{
	ReplaceContentInContainer(image);
	ReplaceCutline(cutline);
}

function ReplaceContentInContainer(content) {
	var container = document.getElementById('display');
	container.innerHTML = content;
}

function ReplaceCutline(content) {
	var container = document.getElementById('carousel-cutline');
	container.innerHTML = content;
}

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)
{
	if(item.type == 'image')
		return '<img style="cursor:pointer;" onclick="javascript:updateCarousel(\'' + item.large + '\',\'' + item.cutline + '\');" src="' + item.thumb + '" alt="' + item.alt + '" />';
	if(item.type == 'flash')
		return '<img style="cursor:pointer;" onclick="javascript:create_flashCarousel(\'' + item.video + '\',\'' + item.large + '\',\'' + item.cutline + '\');" src="' + item.thumb + '" alt="' + item.alt + '" />';
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
				size: mycarousel_itemList.length,
		scroll: 4,
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });
});
