jQuery.fn.accessNews = function(settings) {
    settings = jQuery.extend({
        newsHeadline: "Top Stories",
        newsSpeed: "slow"
    }, settings);
    return this.each(function(i) {
        aNewsSlider.itemWidth = parseInt(jQuery(".item:eq(" + i + ")",".news_slider").css("width")) + parseInt(jQuery(".item:eq(" + i + ")",".news_slider").css("margin-right"));
        aNewsSlider.init(settings,this);
        jQuery(".view_all > a", this).click(function() {
            aNewsSlider.vAll(settings,this);
            return false;
        });
    });
};
var aNewsSlider = {
    itemWidth: 0,
    init: function(s,p) {
        jQuery(".messaging",p).css("display","none");
        itemLength = jQuery(".item",p).length;
        if (jQuery(".view_all",p).width() == null) {
            jQuery(".news_items",p).prepend("<p class='view_all'>" + s.newsHeadline + " [ " + itemLength + " au total ] &nbsp;-&nbsp; <a href='#'>Tout afficher</a></p>");
        }
        newsContainerWidth = itemLength * aNewsSlider.itemWidth;
        jQuery(".container",p).css("width",newsContainerWidth + "px");
        jQuery(".next",p).css("display","block");
        animating = false;
        jQuery(".next",p).click(function() {
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".container",p).css("left")) - (aNewsSlider.itemWidth * 5);
                if (animateLeft + parseInt(jQuery(".container",p).css("width")) > 0) {
                    jQuery(".prev",p).css("display","block");
                    jQuery(".container",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        if (parseInt(jQuery(".container",p).css("left")) + parseInt(jQuery(".container",p).css("width")) <= aNewsSlider.itemWidth * 7) {
                            jQuery(".next",p).css("display","none");
                        }
                        animating = false;
                    });
                } else {
                    animating = false;
                }
            }
            return false;
        });
        jQuery(".prev",p).click(function() {
            if (animating == false) {
                animating = true;
                animateLeft = parseInt(jQuery(".container",p).css("left")) + (aNewsSlider.itemWidth * 5);
                if ((animateLeft + parseInt(jQuery(".container",p).css("width"))) <= parseInt(jQuery(".container",p).css("width"))) {
                    jQuery(".next",p).css("display","block");
                    jQuery(".container",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        if (parseInt(jQuery(".container",p).css("left")) == 0) {
                            jQuery(".prev",p).css("display","none");
                        }
                        animating = false;
                    });
                } else {
                    animating = false;
                }
            }
            return false;
        });
    },
    vAll: function(s,p) {
        var o = p;
        while (p) {
            p = p.parentNode;
            if (jQuery(p).attr("class") != undefined && jQuery(p).attr("class").indexOf("news_slider") != -1) {
                break;
            }
        }
        if (jQuery(o).text().indexOf("Tout afficher") != -1) {
            jQuery(".next",p).css("display","none");
            jQuery(".prev",p).css("display","none");
            jQuery(o).text("Tout masquer");
            jQuery(".container",p).css("left","0px").css("width",aNewsSlider.itemWidth * 7 + "px");
        } else {
            jQuery(o).text("Tout afficher");
            aNewsSlider.init(s,p);
        }
    }
};

function displayFlash(swf, height, width, alt)
{
	document.write('<object type="application/x-shockwave-flash" data="'+swf+'" width="'+width+'" height="'+height+'">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+swf+'" />');
	document.write(alt);
	document.write('</object>');
}

/*
var SLIDETIMER = 3;
var SLIDESPEED = 3;
var SCROLLTIMER = 3;
var SCROLLSPEED = 3;
var STARTINGOPACITY = 40;

// handles section to section scrolling of the content //
function slideContent(id,prefix,timer) {
	var div = document.getElementById(id);
	var slider = div.parentNode;
	clearInterval(slider.timer);
	slider.section = parseInt(id.replace(/\D/g,''));
	slider.target = div.offsetTop;
	slider.style.top = slider.style.top || '0px';
	slider.current = slider.style.top.replace('px','');
	slider.direction = (Math.abs(slider.current) > slider.target) ? 1 : -1;
	slider.style.opacity = STARTINGOPACITY * .01;
	slider.style.filter = 'alpha(opacity=' + STARTINGOPACITY + ')';
	slider.timer = setInterval( function() { slideAnimate(slider,prefix,timer) }, SLIDETIMER);
}

function slideAnimate(slider,prefix,timer) {
	var curr = Math.abs(slider.current);
	var tar = Math.abs(slider.target);
	var dir = slider.direction;
	if((tar - curr <= SLIDESPEED && dir == -1) || (curr - tar <= SLIDESPEED && dir == 1)) {
		slider.style.top = (slider.target * -1) + 'px';
		slider.style.opacity = 1;
		slider.style.filter = 'alpha(opacity=100)';
		clearInterval(slider.timer);
		if(slider.autoscroll) {
			setTimeout( function() { autoScroll(slider.id,prefix,timer) }, timer * 1000);
		}
	}
	else {
		var pos = (dir == 1) ? parseInt(slider.current) + SLIDESPEED : slider.current - SLIDESPEED;
		slider.current = pos;
		slider.style.top = pos + 'px';
	}
}

// handles manual scrolling of the content //
function scrollContent(id,dir) {
	var div = document.getElementById(id);
	clearInterval(div.timer);
	var sections = div.getElementsByTagName('div');
	var length = sections.length;
	var limit;
	if(dir == -1) {
		limit = 0;
	}
	else {
		if(length > 1) {
			limit = sections[length-1].offsetTop;
		}
		else {
			limit = sections[length-1].offsetHeight - div.parentNode.offsetHeight + 20;
		}
	}
	div.style.opacity = STARTINGOPACITY * .01;
	div.style.filter = 'alpha(opacity=' + STARTINGOPACITY + ')';
	div.timer = setInterval( function() { scrollAnimate(div,dir,limit) }, SCROLLTIMER);
}

function scrollAnimate(div,dir,limit) {
	div.style.top = div.style.top || '0px';
	var top = div.style.top.replace('px','');
	if(dir == 1) {
		if(limit - Math.abs(top) <= SCROLLSPEED) {
			cancelScroll(div.id);
			div.style.top = '-' + limit + 'px';
		}
		else {
			div.style.top = top - SCROLLSPEED + 'px';
		}
	}
	else {
		if(Math.abs(top) - limit <= SCROLLSPEED) {
			cancelScroll(div.id);
			div.style.top = limit + 'px';
		}
		else {
			div.style.top = parseInt(top) + SCROLLSPEED + 'px';
		}
	}
}

// cancel the scrolling on mouseout //
function cancelScroll(id) {
	var div = document.getElementById(id);
	div.style.opacity = 1;
	div.style.filter = 'alpha(opacity=100)';
	clearTimeout(div.timer);
}

// initiate auto scrolling //
function autoScroll(id,prefix,timer,restart) {
	var div = document.getElementById(id);
	div.autoscroll = (!div.autoscroll && !restart) ? false : true;
	if(div.autoscroll) {
		var sections = div.getElementsByTagName('div');
		var length = sections.length;
		div.section = (div.section && div.section < length) ? div.section + 1 : 1;
	slideContent(prefix + '-' + div.section,prefix,timer);
	}
}

// cancel automatic scrolling //
function cancelAutoScroll(id) {
	var div = document.getElementById(id);
	div.autoscroll = false;
}
*/

var isf = { 'clock' : null, 'fade' : true, 'count' : 1 }
/*******************************************************



/*****************************************************************************
 List the images that need to be cached
*****************************************************************************/

isf.imgs = [
	'pictures/botanica_1/abstraction.jpg',
	'pictures/botanica_1/anemone.jpg',
	'pictures/botanica_1/anemone2.jpg',
	'pictures/botanica_1/betterave.jpg',
	'pictures/botanica_1/bota019.jpg',
	'pictures/botanica_1/bota020.jpg',
	'pictures/botanica_1/bota021.jpg',
	'pictures/botanica_1/bulbes.jpg',
	'pictures/botanica_1/capucine.jpg',
	'pictures/botanica_1/clematite-rouge.jpg',
	'pictures/botanica_1/clematite.jpg',
	'pictures/botanica_1/cosmos.jpg',
	'pictures/botanica_1/dahlia.jpg',
	'pictures/botanica_1/dahlia2.jpg',
	'pictures/botanica_1/echinacea.jpg',
	'pictures/botanica_1/escargot.jpg',
	'pictures/botanica_1/hydrangea.jpg',
	'pictures/botanica_1/lavatere.jpg',
	'pictures/botanica_1/marguerite.jpg',
	'pictures/botanica_1/parme.jpg',
	'pictures/botanica_1/pavot-blanc.jpg',
	'pictures/botanica_1/pavot-jaune.jpg',
	'pictures/botanica_1/pavot-rose.jpg',
	'pictures/botanica_1/pivoine.jpg',
	'pictures/botanica_1/poireaux.jpg',
	'pictures/botanica_1/rose-fanee.jpg',
	'pictures/botanica_2/1.jpg',
	'pictures/botanica_2/2.jpg',
	'pictures/botanica_2/3.jpg',
	'pictures/botanica_2/4.jpg',
	'pictures/botanica_2/5.jpg',
	'pictures/botanica_2/6.jpg',
	'pictures/botanica_2/7.jpg',
	'pictures/botanica_2/8.jpg',
	'pictures/botanica_2/9.jpg',
	'pictures/botanica_2/10.jpg',
	'pictures/botanica_2/11.jpg',
	'pictures/botanica_2/12.jpg',
	'pictures/botanica_2/13.jpg',
	'pictures/botanica_2/14.jpg',
	'pictures/botanica_2/15.jpg',
	'pictures/botanica_2/16.jpg',
	'pictures/botanica_2/17.jpg',
	'pictures/botanica_2/18.jpg',
	'pictures/botanica_2/19.jpg',
	'pictures/botanica_2/20.jpg',
	'pictures/botanica_2/21.jpg',
	'pictures/botanica_2/22.jpg',
	'pictures/botanica_2/23.jpg',
	'pictures/botanica_2/24.jpg',
	'pictures/botanica_2/25.png',
	'pictures/botanica_2/26.png',
	'pictures/botanica_2/27.jpg',
	'pictures/botanica_2/28.jpg'
	];

/*****************************************************************************
*****************************************************************************/



//cache the images
isf.imgsLen = isf.imgs.length;
isf.cache = [];
for(var i=0; i<isf.imgsLen; i++)
{
	isf.cache[i] = new Image;
	isf.cache[i].src = isf.imgs[i];
}

function swapfade()
{
	//if the timer is not already going
	if(isf.clock == null)
	{
		//copy the image object 
		isf.obj = arguments[0];
		
		//copy the image src argument 
		isf.src = arguments[1];
		
		//store the supported form of opacity
		if(typeof isf.obj.style.opacity != 'undefined')
		{
			isf.type = 'w3c';
		}
		else if(typeof isf.obj.style.MozOpacity != 'undefined')
		{
			isf.type = 'moz';
		}
		else if(typeof isf.obj.style.KhtmlOpacity != 'undefined')
		{
			isf.type = 'khtml';
		}
		else if(typeof isf.obj.filters == 'object')
		{
			//weed out win/ie5.0 by testing the length of the filters collection (where filters is an object with no data)
			//then weed out mac/ie5 by testing first the existence of the alpha object (to prevent errors in win/ie5.0)
			//then the returned value type, which should be a number, but in mac/ie5 is an empty string
			isf.type = (isf.obj.filters.length > 0 && typeof isf.obj.filters.alpha == 'object' && typeof isf.obj.filters.alpha.opacity == 'number') ? 'ie' : 'none';
		}
		else
		{
			isf.type = 'none';
		}
		
		//change the image alt text if defined
		if(typeof arguments[3] != 'undefined' && arguments[3] != '')
		{
			isf.obj.alt = arguments[3];
		}
		
		//if any kind of opacity is supported
		if(isf.type != 'none')
		{
			//copy and convert fade duration argument 
			//the duration specifies the whole transition
			//but the swapfade is two distinct transitions
			isf.length = parseInt(arguments[2], 10) * 500;
			
			//create fade resolution argument as 20 steps per transition
			//again, split for the two distrinct transitions
			isf.resolution = parseInt(arguments[2], 10) * 10;
			
			//start the timer
			isf.clock = setInterval('isf.swapfade()', isf.length/isf.resolution);
		}
		
		//otherwise if opacity is not supported
		else
		{
			//just do the image swap
			isf.obj.src = isf.src;
		}
		
	}
};


//swapfade timer function
isf.swapfade = function()
{
	//increase or reduce the counter on an exponential scale
	isf.count = (isf.fade) ? isf.count * 0.9 : (isf.count * (1/0.9)); 
	
	//if the counter has reached the bottom
	if(isf.count < (1 / isf.resolution))
	{
		//clear the timer
		clearInterval(isf.clock);
		isf.clock = null;

		//do the image swap
		isf.obj.src = isf.src;

		//reverse the fade direction flag
		isf.fade = false;
		
		//restart the timer
		isf.clock = setInterval('isf.swapfade()', isf.length/isf.resolution);

	}
	
	//if the counter has reached the top
	if(isf.count > (1 - (1 / isf.resolution)))
	{
		//clear the timer
		clearInterval(isf.clock);
		isf.clock = null;

		//reset the fade direction flag
		isf.fade = true;
		
		//reset the counter
		isf.count = 1;
	}

	//set new opacity value on element
	//using whatever method is supported
	switch(isf.type)
	{
		case 'ie' :
			isf.obj.filters.alpha.opacity = isf.count * 100;
			break;
			
		case 'khtml' :
			isf.obj.style.KhtmlOpacity = isf.count;
			break;
			
		case 'moz' : 
			//restrict max opacity to prevent a visual popping effect in firefox
			isf.obj.style.MozOpacity = (isf.count == 1 ? 0.9999999 : isf.count);
			break;
			
		default : 
			//restrict max opacity to prevent a visual popping effect in firefox
			isf.obj.style.opacity = (isf.count == 1 ? 0.9999999 : isf.count);
	}
};

function dimensions(i) {
	document.getElementById('botanica2').src = "pictures/dimensions"+i+".jpg";
}
