function RotatorFusion(name)
{
	this.RotatorGroupID = 0;
	this.delay = 5000;
	this.menuColor = '#808080';
	this.menuColorSelected = '#000000';
	this.textColor = '#ffffff';
	this.backgroundColor = '#ffffff';
	this.fontFamily = 'Arial, Helvetica, sans serif';
	this.imageHeight = 250;
	this.rotatorWidth = 606;
	this.mirror = true;
	
	var name = name;
	var self = this;
	var timer = null;
	var rotatorHeight = 0;
	var current, current_menu, next, next_menu, change;
	var imageList = new Array();
	
	this.convertXMLspecialChars = function(text)
	{
		ret = html_entity_decode(text);
		ret = ret.replace(/'/g, '%%quot%%');
		ret = ret.replace(/&/g, '%%amp%%');
		return ret;
	}
	
	this.revertXMLspecialChars = function(text)
	{		
		ret = text.replace(/%%quot%%/g, "'");
		ret = ret.replace(/%%amp%%/g, '&');
		return ret;
	}
	
	this.drawLists = function(xml_text)
	{
		xml_text = this.convertXMLspecialChars(xml_text);
		var xml = $.fromXMLString(xml_text),
		i = 0,
		html_text = '<ul>',		
		html_menu = '<ul style="z-index:32">';

		$(xml).find('jpg').each(function(){
			imageList.push($(this).attr('image'));
			if ($(this).attr('targetLink') == '_self' || !$(this).attr('targetLink')){
				html_text += '<li id="li#main_rotator_' + name + '" ' + ((i == 0) ? ' class="show"' : '') + ' head="' +  self.revertXMLspecialChars($(this).attr('head')) + '" desc="' +  self.revertXMLspecialChars($(this).attr('desc')) + '" ><div id="#inner"><div><a href="' +  self.revertXMLspecialChars($(this).attr('link')) + '"><img id="rotator_image_' + i + '" src="' +  $(this).attr('image') + '" alt="' +  self.revertXMLspecialChars($(this).attr('title')) + '" target="' + $(this).attr('targetLink') + '"/></a></div>';
			}
			else{
					html_text += '<li id="li#main_rotator_' + name + '" ' + ((i == 0) ? ' class="show"' : '') + ' head="' +  self.revertXMLspecialChars($(this).attr('head')) + '" desc="' +  self.revertXMLspecialChars($(this).attr('desc')) + '" ><div id="#inner"><div><a href="javascript:" onclick="openUrlInNewWindow(\'' +  self.revertXMLspecialChars($(this).attr('link')) + '\');"><img id="rotator_image_' + i + '" src="' +  $(this).attr('image') + '" alt="' +  self.revertXMLspecialChars($(this).attr('title')) + '"/></a></div>';
			}
			if (self.mirror){
				html_text += '<div class="mirror"><a href="' +  self.revertXMLspecialChars($(this).attr('link'))+ '"><img src="' +  $(this).attr('image') + '"  alt="' +  self.revertXMLspecialChars($(this).attr('title')) + '" /></a></div>';
				html_text += '<div id="mirrorout_' + name + '" class="mirrorout"></div>';
			}
			html_text += '</div></li>';
			
			html_menu += '<li id="li#menu_rotator_' + name + '" ' + ((i == 0) ? ' class="show"' : '') + ' title="' +  self.revertXMLspecialChars($(this).attr('title')) + '" onClick="' + name + '.rotate(' + i + ')">' +  self.revertXMLspecialChars($(this).attr('title')) + '</li>';
			
			if (i === 0){
				if ($(this).attr('head').length > 0){	
					$("#rotator_head_" + name).html(self.revertXMLspecialChars($(this).attr('head')));
					$("#rotator_head_" + name).css("display","block");
				}
				else{
					$("#rotator_head_" + name).css("display","none");
				}
				
				if ($(this).attr('desc').length > 0){	
					$("#rotator_desc_" + name).html(self.revertXMLspecialChars($(this).attr('desc')));
					$("#rotator_desc_" + name).css("display","block");
				}
				else{
					$("#rotator_desc_" + name).css("display","none");
				}
			}
			i++;
		});
		html_text += '</ul>';
		html_menu += '</ul>';
		$("#main_rotator_" + name).append(html_text);
		$("#rotator_menu_" + name).append(html_menu);
		
		this.preloadImages();
	};
	

	this.preloadImages = function()
	{		
		var i;
		var preload_html = '<div id="rotator_pix">';
		for (i = 0; i < imageList.length; i++){
			preload_html += '<img src="' + imageList[i] + '" />';
		}
		preload_html += '</div>';
		
		$('#main_rotator_' + name).append(preload_html);
		$('#rotator_pix').onImagesLoaded(function(){
			self.start();
		});
	}
	

	this.draw = function()
	{
		if (detectPlatform()){
			var platform = detectPlatform();
			if (platform.device != 'pc'){
				this.mirror = false;
			}
		}
		rotatorHeight = this.mirror ? (this.imageHeight + 40) : this.imageHeight;

		var css_html;
		
		css_html = '<style type="text/css"> \
		.main_rotator_container{ \
			position:relative; \
			width: ' + (this.rotatorWidth + 1) + 'px;\
			height:' + rotatorHeight + 'px;'
		css_html += '} \
		.main_rotator { \
			position:relative; \
			height:' + this.imageHeight + 'px; \
			margin-left: 0px; \
			margin-bottom: 10px; \
			margin-top: 0px; \
		} \
		.main_rotator ul { \
			margin:0px; \
		} \
		.main_rotator ul li { \
			position:absolute; \
			display: none; \
			float:left; \
			list-style: none; \
		} \
		.main_rotator ul li.hide { \
			display: none; \
			list-style: none; \
		} \
		.main_rotator ul li.show { \
			display: block; \
			z-index:30; \
		} \
		.main_rotator ul li img { \
			border:0px; \
			padding: 0px; \
			background-color: ' + this.backgroundColor + '; \
		} \
		.rotator_menu { \
			position: absolute; \
			font-size: 12px; \
			z-index: 33; \
			height: 250px; \
			width: 175px; \
			top: 0px; \
			float: right; \
			right: 0px; \
			margin: 0 5px 0 0; \
		} \
		.rotator_menu ul li { \
			list-style:none; \
			background-color:' + this.menuColor + '; \
			width: 145px; \
			height:30px; \
			margin-bottom:5px; \
			padding-left:10px; \
			padding-top:12px; \
			font-family: ' + this.fontFamily + '; \
			font-weight: normal; \
			color:' + this.textColor + '; \
			cursor:pointer; \
		} \
		.rotator_menu ul li.show { \
			background-color:' + this.menuColorSelected + '; \
			background-image:url(/Pics/Rotator/fleche.png); \
			background-repeat:no-repeat; \
			background-position:top left; \
			margin-left:-20px; \
			padding-left:30px; \
			cursor:default; \
			z-index: 20; \
		}';
		if (this.mirror){
		css_html += '.mirror{ \
			position:absolute; \
			z-index:32; \
			height:40px; \
			overflow:hidden; \
			-moz-opacity:0.4; \
			opacity: 0.4; \
			filter:alpha(opacity=40); \
		} \
		.mirror_show{ \
			position:absolute; \
			z-index:32; \
			height:40px; \
			overflow:hidden; \
			-moz-opacity:0.4; \
			opacity: 0.4;*/ \
			filter:alpha(opacity=40); \
		} \
		.mirror a img { \
			-moz-transform: scaleY(-1); \
			-webkit-transform: scaleY(-1); \
			transform: scaleY(-1); \
			filter: flipv; IE \
		} \
		.mirror_show a img { \
			-moz-transform: scaleY(-1); \
			-webkit-transform: scaleY(-1); \
			transform: scaleY(-1); \
			filter: flipv; IE \
		} \
		.mirrorout{ \
			position:absolute; \
			z-index:34; \
			width:100%; \
			height:40px; \
			background-image:url(/Pics/Rotator/gradient.png); \
			background-repeat:repeat-x; \
			background-position:bottom left; \
		}';
		}
		css_html += '.rotator_head{ \
			position: absolute; \
			display: none; \
			z-index:35; \
			bottom: 25px; \
			height: 30px; \
			width:auto; \
			padding: 5px; \
			background-color:' + this.menuColorSelected + '; \
			font-family: ' + this.fontFamily + '; \
			color:' + this.textColor + '; \
			font-size: 22px; \
			font-weight: normal; \
		} \
		.rotator_desc{ \
			position: absolute; \
			display: none; \
			z-index:36; \
			bottom: 0px; \
			width:auto; \
			padding:5px; \
			background-color:' + this.menuColor + '; \
			font-family: ' + this.fontFamily + '; \
			color:' + this.textColor + '; \
			font-weight: normal; \
			font-size: 13px; \
		} \
		#rotator_pix{ \
			display:none; \
		} \
		</style>';		
		
		document.write(css_html);
		
		var html_text = '';
		html_text += '<div id="div_' + name + '" class="main_rotator_container"><div id="main_rotator_' + name  + '" class="main_rotator"></div><div id="rotator_menu_' + name  + '" class="rotator_menu"></div><div ID="rotator_head_' + name  + '" class="rotator_head"></div><div ID="rotator_desc_' + name  + '" class="rotator_desc"></div></div>';
		
		document.write(html_text);
		
		var date = new Date();
		$.ajax({
			type:"GET",
			url:"/_SHARED/ApplicationData/Public/FlashWriter.aspx?RotatorGroupID=" + this.RotatorGroupID + "&cb=" + date.getTime(),
			dataType:"text",
			success:function(xml_text){
				self.drawLists(xml_text);
			}
		});		
	};
	

	this.rotate = function(position)
	{
		this.stop();		
		var last_position;

		current = ($('div#main_rotator_' + name + ' ul li.show') ? $('div#main_rotator_' + name + ' ul li.show') : $('div#main_rotator_' + name + ' ul li:first'));
		current_menu = ($('div#rotator_menu_' + name + ' ul li.show') ? $('div#rotator_menu_' + name + ' ul li.show') : $('div#rotator_menu_' + name + ' ul li:first'));
		last_position = $('div#main_rotator_' + name + ' ul li').index(current);
		change = true;

		if (position === undefined){
			next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#main_rotator_' + name + ' ul li:first') :current.next()) : $('div#main_rotator_' + name + ' ul li:first'));
			next_menu = ((current_menu.next().length) ? ((current_menu.next().hasClass('show')) ? $('div#rotator_menu_' + name + ' ul li:first') :current_menu.next()) : $('div#rotator_menu_' + name + ' ul li:first'));
			position = ($('div#main_rotator_' + name + ' ul li').index(next) == $('div#main_rotator_' + name + ' ul li').length) ? 0 : $('div#main_rotator_' + name + ' ul li').index(next);
		}
		else{
			next = $('div#main_rotator_' + name + ' ul li').eq(position);
			next_menu = $('div#rotator_menu_' + name + ' ul li').eq(position);
			change = next.hasClass("show") ? false : true;
		}

		if (change)
		{			
			current_menu.removeClass('show');
			next_menu.addClass('show');			
			
			current.fadeOut(400, function(){ current.removeClass('show') });
			next.fadeIn(400, function(){ next.addClass('show') });
			
			if ($('div#main_rotator_' + name + ' ul li').eq(position).attr('head').length > 0){	
				$("#rotator_head_" + name).html($('div#main_rotator_' + name + ' ul li').eq(position).attr('head'));
				$("#rotator_head_" + name).css("display","block");
			}
			else{
				$("#rotator_head_" + name).css("display","none");
			}
			
			if ($('div#main_rotator_' + name + ' ul li').eq(position).attr('desc').length > 0){	
				$("#rotator_desc_" + name).html($('div#main_rotator_' + name + ' ul li').eq(position).attr('desc'));
				$("#rotator_desc_" + name).css("display","block");
			}
			else{
				$("#rotator_desc_" + name).css("display","none");
			}
			$("#rotator_head_" + name).css("bottom",($("#rotator_desc_" + name).height()+10));
		}		

		this.start();
	};
	

	this.stop = function()
	{
		if (timer){
			clearTimeout(timer);
		}
	};
	

	this.start = function()
	{
		timer = setTimeout(name + '.rotate()',this.delay);
	};	
}
