jQuery(function(){
   jQuery("div.svw").prepend("<!-- img src='/img/svwloader.gif' class='ldrgif' alt='loading...'/ -->"); 
});
//var j = 0;
//var quantofamo = 0;
//var current=0;

jQuery.fn.slideView = function(settings,postfix) {

     if(postfix == null) postfix = "";
	 settings = jQuery.extend({
        easeFunc: "easeInOutExpo",
        easeTime: 750,
		current: 0,
        toolTip: false}, settings);


	 return this.each(function(){
		  var container = jQuery(this);
		  container.find("img.ldrgif").remove(); // removes the preloader gif
		  container.removeClass("svw").addClass("stripViewer");		
		
		  var pictWidth = container.find("img").width();
		  var pictHeight = container.find("img").height();
		  var pictEls = container.find("li").size();
		  var stripViewerWidth = pictWidth*pictEls;
		
		  container.find("ul").css("width" , stripViewerWidth); //assegnamo la larghezza alla lista UL	
		  container.css("width" , pictWidth);
		  container.css("height" , pictHeight);
		
		  var i = 0;
		
		  jQuery(this).find("img").each(function(z) 
		  {
			   i++;
			   var title = "";
			   var block = "";
			   var caption = ""; 
			
			   if(jQuery(this).attr("rel").length == 0 && jQuery(this).attr("alt").length==0)
				  block = "style='display:none;'";

			   var f =  jQuery(this).attr("alt").search(/©/);
			   if(f>=0)
			   {
				  caption = jQuery(this).attr("alt").substring(0,f)+"<font style=\"font-size:8pt;color:#92a4a7;font-family:arial;\">"+jQuery(this).attr("alt").substring(f)+"</font>";
			   }else{ 
		  		  caption = jQuery(this).attr("alt");
			   }
			
			   if(jQuery(this).attr("rel").length > 0)
   			      title = "<span class='typo_header'>"+jQuery(this).attr("rel")+"</span><br>";

			   jQuery(this).after("<span id='s"+postfix+''+i+"' class='typo' "+block+"><\/span><span id='d"+postfix+''+i+"' class='typo1'> "+title+""+caption+"<\/span>");
		  });


		  container.find("span.typo").css({position: "absolute", width: (pictWidth-30)+"px",height:"auto", margin: (pictHeight-80)+"px 0 0 "+(-pictWidth)+"px"});
		  container.find("span.typo1").css({position: "absolute", width: (pictWidth-30)+"px",height:"auto", margin: (pictHeight-80)+"px 0 0 "+(-pictWidth)+"px"});
		
//		  jQuery("span.typo").css({position: "absolute", width: (pictWidth-30)+"px",height:"auto", margin: (pictHeight-80)+"px 0 0 "+(-pictWidth)+"px"});
//		  jQuery("span.typo1").css({position: "absolute", width: (pictWidth-30)+"px",height:"auto", margin: (pictHeight-80)+"px 0 0 "+(-pictWidth)+"px"});

		  i = 0;
		  container.find("img").each(function(z) {
			i++;
			$("#s"+postfix+''+i).height($("#d"+postfix+''+i).height());
			jQuery("#d"+postfix+''+i).css({position: "absolute", width: (pictWidth-30)+"px",height:$("#d"+postfix+''+i).height(), margin: (pictHeight-$("#d"+postfix+''+i).height()-12)+"px 0 0 "+(-pictWidth)+"px"});
			jQuery("#s"+postfix+''+i).css({position: "absolute", width: (pictWidth-30)+"px",height:$("#d"+postfix+''+i).height()+2, margin: (pictHeight-$("#d"+postfix+''+i).height()-12)+"px 0 0 "+(-pictWidth)+"px"});
		  });


		  $('#next'+postfix).bind("click", function()
		     {
			    if(settings.current+1 < pictEls)
			    {
				   ++settings.current;
				   var cnt = -(pictWidth*settings.current);
				   container.find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
				
				   if(settings.current==pictEls-1){ $("#dnext"+postfix).hide();}
				   if(settings.current==1){$("#dprev"+postfix).show();}
			    }
			    return false;
		     });
		
		  $('#prev'+postfix).bind("click", function()
		     {
			    if(settings.current-1 >= 0)
			    {
				   --settings.current;
				   var cnt = -(pictWidth*settings.current);
				   container.find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
				
				   if(settings.current==pictEls-2){ $("#dnext"+postfix).show();}
				   if(settings.current==0){$("#dprev"+postfix).hide();}
			    }
			    return false;
		     });
     });		
};