function removeHTMLTags(testo){
 	if(testo){
 		var strInputCode = testo;
 		/* 
  			This line is optional, it replaces escaped brackets with real ones, 
  			i.e. < is replaced with < and > is replaced with >
 		*/	
 	 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
 		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
 		return strTagStrippedText;
 	}	
}


var setBarSwf = function (container,ibig_container,pimages,title_container,title){
	selectedIndex = 0
	images = pimages;
	container_cropper_name = container;
	if($(title_container)){
		$(title_container).setProperty('html',title);
	}
	if ($(container_cropper_name)) {
		$(container_cropper_name).setStyle('float', 'left');
		$(container_cropper_name).setStyle('overflow', 'hidden');
		$(container_cropper_name).setStyle('position', 'relative');
		//$(container_cropper_name).setStyle('background-color', '#ffff00');
		if (images.length > 0) {
			if ($(ibig_container)) {
				$(ibig_container).setStyle('position', 'relative');
				$(ibig_container).setStyle('background', 'url(/images/loader.gif) no-repeat');
				$(ibig_container).setStyle('background-position', ($(ibig_container).getSize().x - 16) / 2 + 'px ' + ($(ibig_container).getSize().y - 16) / 2 + 'px');
				
				
				if(images[selectedIndex].type == 'YOUTUBE') {
					var ibigFlash = new Swiff('http://www.youtube.com/v/'+images[selectedIndex].url+'&autoplay=1', {
					    width: 320,
					    height: 320,		    
					    container: $('videocontainer'),
					    events: {
					        onLoad: function() 
					        {
					            alert("Flash is loaded!")
					        }
					    }
					});
				}else{
					var ibigFlash = new Swiff('/flash/player.swf', {
					    width: 320,
					    height: 320,
					    params: {
					        flashvars: 'videoPath=/' + images[selectedIndex].url + "&autoplay=true&skinPath=/flash/SteelExternalAll.swf"
					    },			    
					    container: $('videocontainer'),
					    events: {
					        onLoad: function() 
					        {
					            alert("Flash is loaded!")
					        }
					    }
					});
				}	
				
				var ibig = new Element('img', {
					'id': 'image_big',
					//'src': images[selectedIndex].url,
					'styles': {
						'opacity': '0',
						'position': 'relative',
						'z-index': '100'
					}
				})
				
				
				var imgBigCheckRequest = new Request({url:images[selectedIndex].url,				
					method:'HEAD',
					onSuccess: function(txt) {
						this.img.setProperty('src',this.options.url)
						this.img.tween('opacity', 1);
					},
					onFailure: function() {
						//alert("onFailure");
						/*if(Browser.Engine.trident){
							this.img.setProperty('src',this.options.url)	
							this.img.tween('opacity', 1);
						}*/
					},
					onException: function(headerName, value){
						alert(headerName+", "+value)
					}
				});
				imgBigCheckRequest.img = ibig;
				//imgBigCheckRequest.send();
				$(ibig_container).adopt(ibig);

				//ibig.setProperty('src',images[selectedIndex].url)
				//ibig.tween('opacity', 1);
			}
			var image_container = new Element('div', {
				'id': 'image_container',
				'styles': {
					'float': 'left',
					'position': 'absolute',
					'left': 0
				}
			});
			for (var img = 0; img < images.length; img++) {			
				var data_alt = '';
				if(images[img].description && images[img].description != ''){
					data_alt = images[img].description;
					data_alt = removeHTMLTags(data_alt);
					data_alt = data_alt.replace(/&#(\d+);/g,
					function() {
					return String.fromCharCode(arguments[1]);
					});
				}
								
				var newLinkBox = new Element('p', {
					'styles': {
						'padding': '0 ' + space + 'px 0 ' + space + 'px',
						'float': 'left'
					}
				});
				var newLinkImg = new Element('a', {
					'href': 'javascript:openImg(' + img + ')',
					'styles': {
						'display': 'block',
						'float': 'left'
					},
					//'rel': data_alt,
					'id': 'link_' + img
				});
				var newLinkDescription = new Element('span', {
					'html' : data_alt,
					'styles': {
						'display': 'block',
						'width': '90px',
						'height': '40px',
						'text-align' : 'left',
						'background-color' : '#DDD',
						'margin': '5px 0 5px 0',
						'padding': '3px',
						'float': 'left'
					},
					'id': 'desc_' + img
				});
				//newLinkImg.addEvent('mouseover', showDescription.bind(this,[newLinkImg.getProperty('rel')]));
				//newLinkImg.addEvent('mouseout', hideDescription.bind(this));

				var imgPlace = new Element('p', {
					'styles': {
						'float': 'left',
						'display': 'block',
						'background-color': '#CCCCCC',
						'height': '90px',
						'width': '90px',
						'cursor': 'hand',
						'filter': 'chroma(color=#A57B94)'
					},
					'id': 'place_' + img
				});
			
				var newImg = new Element('img', {
					'styles': {
						'float': 'left',
						'display': 'none'
					},
					
					'id': 'thumb_' + img
				});
				newImg.index = img;
				newImg.addEvent('load',resizeBar);
				if (img == selectedIndex) {
					newImg.addClass('imgacceso');
					imgPlace.addClass('imgacceso');
				}
				else {
					newImg.addClass('imgspento');
					imgPlace.addClass('imgspento');
				}
				
				var imgCheckRequest = new Request({url: images[img].urlthumb,
					method:'HEAD',
					onSuccess: function(txt) {	
						loaded_thumbs++;
						onImgLoad(this.img,this.options.url);
					},
					onFailure: function() {
						//alert("onFailure");
						/*if(Browser.Engine.trident){						
							loaded_thumbs++;
							onImgLoad(this.img,this.options.url);
						}*/
						resizeBar.delay(160);
					},
					onException: function(headerName, value){
						alert(headerName+", "+value)
					}

				});
				

				imgCheckRequest.img = newImg;
				//imgCheckRequest.send();



				$(container_cropper_name).adopt(image_container.adopt(newLinkBox.adopt(newLinkImg.adopt(imgPlace, newImg), new Element('br',{'clear':'all'}),newLinkDescription)));
				loaded_thumbs++;
				onImgLoad(newImg,images[img].urlthumb);
			}
		}
		checkArrow();
	}
}
var openSwf = function(iImg,isSlideBig,dir){
	selectedIndex = iImg;	
	//
	
	if (!isSlideBig) {
	//	$('image_container').tween('left', (startX +(space)) - ($('link_' + selectedIndex).getCoordinates($('image_container')).left + space))
		$('image_container').tween('left', (startX  - $('link_' + selectedIndex).getCoordinates($('image_container')).left) + space)
	}else{
		var maskSize = $(container_cropper_name).getSize().x;
		var container_pos = ($('image_container').getPosition($(container_cropper_name)).x-startX);
		var image_pos = $('link_' + selectedIndex).getCoordinates($('image_container')).left+((dir==1)?($('link_' + selectedIndex).getSize().x):(0));
		var diff = (image_pos-Math.abs(container_pos));
		if (diff>maskSize) {
			$('image_container').tween('left', startX - ($('link_' + selectedIndex).getCoordinates($('image_container')).left + (space)));
		}else if (diff < 0) {
			var pos = (startX - ($('link_' + selectedIndex).getCoordinates($('image_container')).left + space))+($(container_cropper_name).getSize().x - space -$('link_' + selectedIndex).getSize().x);
			pos = (pos>startX)?startX:pos;
			$('image_container').tween('left',pos );
		}
	}
	if ($('image_big')) {
		//$('image_big').setStyle('opacity', 0);
		//$('image_big').setProperty('src', images[selectedIndex].url);
		var imgBigCheckRequest = new Request({
			url:images[selectedIndex].url, 
			method:'HEAD',
			onSuccess: function(txt) {
				this.img.setProperty('src',this.options.url)
				this.img.tween('opacity', 1);
			},
			onFailure: function() {
				//alert("onFailure");
				/*if(Browser.Engine.trident){
					this.img.setProperty('src',this.options.url)	
					this.img.tween('opacity', 1);
				}*/
			},
			onException: function(headerName, value){
				alert(headerName+", "+value)
			}
		});
		//imgBigCheckRequest.setHeader('Content-Type','image/jpeg');
		//imgBigCheckRequest.img = $('image_big');
		


			if(images[selectedIndex].type == 'YOUTUBE') {
				var obj = new Swiff('http://www.youtube.com/v/'+images[selectedIndex].url+'&autoplay=1', {
				    width: 320,
				    height: 320,		    
				    container: $('videocontainer'),
				    events: {
				        onLoad: function() 
				        {
				            alert("Flash is loaded!")
				        }
				    }
				});
			}else{
				var obj = new Swiff('/flash/player.swf', {
				    width: 320,
				    height: 320,
				    params: {
				        flashvars: 'videoPath=/' + images[selectedIndex].url + "&autoplay=true&skinPath=/flash/SteelExternalAll.swf"
				    },			    
				    container: $('videocontainer'),
				    events: {
				        onLoad: function() 
				        {
				            alert("Flash is loaded!")
				        }
				    }
				});
			}	


			// $('image_big').setProperty('src',images[selectedIndex].URL)
			// $('image_big').tween('opacity', 1);

	}
	//
	$('thumb_' + oldSelectedIndex).removeClass('imgacceso');
	$('place_' + oldSelectedIndex).removeClass('imgacceso');	
	$('thumb_' + oldSelectedIndex).addClass('imgspento');
	$('place_' + oldSelectedIndex).addClass('imgspento');
	checkArrow();
	oldSelectedIndex = selectedIndex;
	$('thumb_' + oldSelectedIndex).removeClass('imgspento');
	$('place_' + oldSelectedIndex).removeClass('imgspento');
	$('thumb_' + selectedIndex).addClass('imgacceso');
	$('place_' + selectedIndex).addClass('imgacceso');
}
/*var showDescription = function(){
	try{ $(description_name).getElement("td").setProperty('html',arguments[0]); } catch(err) {}
	try{ console.info(this+":"+arguments[0]); } catch(err) {}
}
var hideDescription = function(){
	try{ $(description_name).getElement("td").setProperty('html', '' ); } catch(err) {}
}*/