/* =========================================================

// jquery.innerfade.js
// Datum: 2007-01-29
// Firma: Medienfreunde Hofmann & Baldes GbR
// Autor: Torsten Baldes
// Mail: t.baldes@medienfreunde.com
// Web: http://medienfreunde.com
// based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/
// ========================================================= */
// jquery.animated.innerfade.js
// Datum: 2007-10-30
// Firma: OpenStudio
// Autor: Arnault PACHOT
// Mail: apachot@openstudio.fr
// Web: http://www.openstudio.fr
// ========================================================= */
// jquery.custom.innerfade.js
// Datum: 2009-05-25
// Firma: TFO
// Autor: Andre COLLIN
// Mail: acollin@tfo.org
// Web: http://www.tfo.org




(function($) {

$.fn.custominnerfade = function(options) {
	var mytimer;
	var pauseActivated=false;
	this.each(function(){ 	
		var settings = {
			speed: 'normal',
			captionSpeed: 'normal',
			timeout: 15000,
			containerheight: '341px',
			containerwidth: '605px',
			runningclass: 'custominnerfade',
			animationSpeed: 15000,
			controlButtonsPath: 'img',
			controlBox: 'none',
			controlBoxClass: 'none'
		};
		$(this).css('margin', '0 0 0 0').css('padding', '0 0 0 0').find('img').css('border', 'none');
		if(options)
			$.extend(settings, options);
		
		var elements = $(this).children();
		
		
		if (settings.controlBox != 'none')
		{
			if (settings.controlBoxClass != 'none') $(this).append("<div class='"+settings.controlBoxClass+" control-panel2'><a class='back-button2' href='#'><img src='"+settings.controlButtonsPath+"/previous.gif' alt='previous' style='border: none;' /></a> <a class='pause-button2' href='#'><img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' style='border: none;' /></a> <a class='next-button2' href='#'><img src='"+settings.controlButtonsPath+"/next.gif' alt='next' style='border: none;' /></a></div>");
			else $(this).append("<div class='control-panel2'><a class='back-button2' href='#'><img src='"+settings.controlButtonsPath+"/previous.gif' alt='previous' style='border: none;' /></a> <a class='pause-button2' href='#'><img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' style='border: none;' /></a> <a class='next-button2' href='#'><img src='"+settings.controlButtonsPath+"/next.gif' alt='next' style='border: none;' /></a></div>");
			
			if (settings.controlBox != "show")
			{
				$(this).find(".control-panel2").hide();
				$(this).bind('mouseover', function(){$(this).find(".control-panel2").show();});
				$(this).bind('mouseout', function(){$(this).find(".control-panel2").hide();});
			}
			
			$(this).find(".control-panel2").css('z-index', 350).css('position', 'absolute');
			if (settings.controlBoxClass == 'none')
				$(".control-panel2").css('right', '10px').css('top', '5px').css('textAlign', 'right').css('margin', 0).css('paddingTop', '0').css('marginRight', '0').css('fontSize', '20px').css('color', '#88d300');
			
			$(this).find(".control-panel2 a.next-button2").bind('click', function(){pauseActivated = false; clearTimeout(mytimer); $(".control-panel2 a.pause-button2").html("<img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' style='border: none;' />"); $.custominnerfade.next(elements, settings, 1, 0, mytimer, pauseActivated);return false;});
			$(this).find(".control-panel2 a.back-button2").bind('click', function(){pauseActivated = false; clearTimeout(mytimer); $(".control-panel2 a.pause-button2").html("<img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' style='border: none;' />"); $.custominnerfade.next(elements, settings, elements.length - 1, 0, mytimer, pauseActivated);return false;});
			$(this).find(".control-panel2 a.pause-button2").bind('click', function(){
			clearTimeout(mytimer);
			if (!pauseActivated){
				pauseActivated = true;
				$(this).html("<img src='"+settings.controlButtonsPath+"/play.gif' alt='play' style='border: none;' />");
				$(elements[0]).stop().stop();
			}else {
				pauseActivated = false;
				$(this).html("<img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' style='border: none;' />");
				var vwidth =  - (parseInt($(elements[0]).find("img").attr("width"))-parseInt(settings.containerwidth)); 
				if (vwidth > 0) vwidth = 0;
				var duree = parseInt(settings.timeout) - parseInt((parseInt($(elements[0]).css('left')) / parseInt(vwidth)) * parseInt(settings.timeout));
				$(elements[0]).animate({top: 0, left: vwidth}, duree);
				mytimer = setTimeout(function(){
					$.custominnerfade.next(elements, settings, 1, 0, mytimer, pauseActivated);
					}, duree);
			} 
			return false;
			});
		}
		
		
		if (elements.length > 1) {
		
			$(this).css('position', 'relative').css('overflow', 'hidden').css('height', settings.containerheight).css('width', settings.containerwidth);
			
			$(this).addClass(settings.runningclass);
			
			for ( var i = 0; i < elements.length; i++ ) {
				$(elements[i]).css('position', 'absolute').css('top', 0).css('left', 0).css('z-index', String(elements.length-i));
				$(elements[i]).hide();
				$(elements[i]).children(".capt").css('top', 340);
			};
			$(elements[0]).css('top', 0);
			$(elements[0]).css('left', 0);
			$(elements[0]).children(".capt").css('top', 291);
			
			$.custominnerfade.move_photo(elements[0], settings);
			
			
				mytimer = setTimeout(function(){
					$.custominnerfade.next(elements, settings, 1, 0, mytimer, pauseActivated);
				}, settings.timeout);
				
			
			$(elements[0]).show();
		}
		
	});
};


$.custominnerfade = function() {}
$.custominnerfade.next = function (elements, settings, current, last, mytimer, pauseActivated) {
var vwidth =  - (parseInt($(elements[current]).find("img").attr("width"))-parseInt(settings.containerwidth));
if ((parseInt($(elements[current]).css('left')) == 0) || (parseInt($(elements[current]).css('left')) == vwidth))
{	
	clearTimeout(mytimer); 

	
	var vwidth =  - (parseInt($(elements[current]).find("img").attr("width"))-parseInt(settings.containerwidth));
	
	var next, prev;
	if (current == (elements.length - 1))
		next = 0;
	else
		next = current+1;

	if (current == 0)
		prev = elements.length - 1;
	else
		prev = current - 1;

	for ( var i = 0; i < elements.length; i++ ) {
		if ((i != last) && (i != current))
		{
			$(elements[i]).css('z-index', '1');
			$(elements[i]).css('top', 0).css('left', 0);
			$(elements[i]).hide();
		}
	}

	$(elements[last]).css('z-index', '190');
	$(elements[current]).css('z-index', '195');

	if (settings.controlBox != 'none')
	{
		$(this).find(".control-panel2 a.next-button2").unbind('click'); $(".control-panel2 a.next-button2").bind('click', function(){pauseActivated = false;clearTimeout(mytimer);$(".control-panel2 a.pause-button2").html("<img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' style='border: none;' />"); $.custominnerfade.next(elements, settings, next, current, mytimer, pauseActivated);return false;});
		$(this).find(".control-panel2 a.back-button2").unbind('click'); $(".control-panel2 a.back-button2").bind('click', function(){pauseActivated = false; clearTimeout(mytimer);$(".control-panel2 a.pause-button2").html("<img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' style='border: none;' />"); $.custominnerfade.next(elements, settings, prev, current, mytimer, pauseActivated);return false;});
		$(this).find(".control-panel2 a.pause-button2").unbind('click');$(".control-panel2 a.pause-button2").bind('click', function(){
							clearTimeout(mytimer);
							if (!pauseActivated){
								pauseActivated = true;
								$(this).html("<img src='"+settings.controlButtonsPath+"/play.gif' alt='play' style='border: none;' />"); $(elements[current]).stop().stop();
							}else{
								pauseActivated = false; 
								$(this).html("<img src='"+settings.controlButtonsPath+"/pause.gif' alt='pause' style='border: none;' />");
								var vwidth =  - (parseInt($(elements[current]).find("img").attr("width"))-parseInt(settings.containerwidth));
								if (vwidth > 0) vwidth = 0;
								var duree = parseInt(settings.timeout) - parseInt((parseInt($(elements[current]).css('left')) / parseInt(vwidth)) * parseInt(settings.timeout));
								$(elements[current]).animate({top: 0, left: vwidth}, duree);
								mytimer = setTimeout((function(){$.custominnerfade.next(elements, settings, next, current, mytimer, pauseActivated);}), duree);
							}
							return false;
					});
	}				
	if (settings.bgFrame != 'none') 
		$(this).find(".bg-frame a").attr("href", $(elements[current]).find("a:first").attr("href")); 

   	$(elements[current]).css('top', 0).css('left', 0);
	$(elements[last]).children(".capt").animate({top: 340},settings.captionSpeed,function(){$(elements[last]).fadeOut(settings.speed)});
	$(elements[current]).fadeIn(settings.speed,function(){$(elements[current]).children(".capt").animate({top: 291},settings.captionSpeed)});
	$.custominnerfade.move_photo(elements[current], settings);

	mytimer = setTimeout((function(){$.custominnerfade.next(elements, settings, next, current, mytimer, pauseActivated);}), settings.timeout);
	 }
};

$.custominnerfade.move_photo = function (element, settings) {

	if (settings.animationSpeed > 0)
	{
		var vheight =  - (parseInt($(element).find("img").attr("height"))-parseInt(settings.containerheight));
		var vwidth =  - (parseInt($(element).find("img").attr("width"))-parseInt(settings.containerwidth));
		if (vheight > 0) vheight = 0;
		if (vwidth > 0) vwidth = 0;
		$(element).children(".illustration").css('left', 0).css('top', 0).animate({left: vwidth}, settings.animationSpeed);
	}
};

})(jQuery);


