function composeMail(obj,before, after, subject) {
	$(obj).attr("href","mailto:"+before+"@"+after+"?subject="+subject);
}
function initMenu() {
	var topmenu = $("ul.leftmenu").attr("class");
	topmenu = topmenu.replace("leftmenu ","");
	$("#menu").find("."+topmenu+" a").addClass("selected");
	$("#leftmenu ul ul").hide();
	var url = document.URL;
	$.each($("#leftmenu a"),function(){
		var regexp=$(this).attr("href");
		if(url.match(regexp)) {
			$(this).addClass("current").next("ul").show();
			$(this).closest("ul").show().prev("a").addClass("current");
			return;
		}
	});
}
function initTooltip() {
	if($("#areaDefault").length==0) $obj = $("area").eq(0);
	else $obj = $("#areaDefault");
	if($("#tooltipBoxSCM").length==0) {
		$obj.closest("div").append("<div style='display:none;' id='tooltipBoxSCM'><p></p></div>");
	}
	$box = $("#tooltipBoxSCM");
	if(typeof($obj.attr("coords"))=="undefined") return false;
	var coords = $obj.attr("coords").split(",");
	var boxWidth = parseInt(coords[2])-parseInt(coords[0]);
	var boxHeight = parseInt(coords[3])-parseInt(coords[1]);
	$box.css("width",boxWidth);
	$box.css("height",boxHeight);
	leftPosition = parseInt(coords[0])-(boxWidth/2)+(parseInt(coords[2])-parseInt(coords[0]))/2;
	topPosition = parseInt(coords[1]);
	$box.css("top",topPosition);
	$box.css("left",leftPosition);
	$box.show();		
}
/* tooltipSCM */
(function($){
	$.fn.tooltipSCM = function() {
		function show(obj) {
			var $obj = $(obj);
			var text = $obj.attr("alt");
			if($("#tooltipSCM").length==0) {
				$("body").append("<div style='display:none;' id='tooltipSCM'><p></p></div>");
			}
			$tooltip = $("#tooltipSCM");
			$tooltip.find("p").empty().html(text);
			var tooltipHeight = $tooltip.outerHeight();	
			var tooltipWidth = $tooltip.outerWidth();	
			var coords = $obj.attr("coords").split(",");
			var pos = $obj.closest(".prodmenu").offset();
			leftPosition = pos.left+parseInt(coords[0])-(tooltipWidth/2)+(parseInt(coords[2])-parseInt(coords[0]))/2;
			topPosition = pos.top-tooltipHeight+parseInt(coords[1]);
			$tooltip.css("top",topPosition);
			$tooltip.css("left",leftPosition);
			$tooltip.show();		
		}
		function hide(obj) {
			$tooltip.hide();		
		}
		function select(obj) {
			var $obj = $(obj);
			if($("#tooltipBoxSCM").length==0) {
				$obj.closest("div").append("<div style='display:none;' id='tooltipBoxSCM'><p></p></div>");
			}
			$box = $("#tooltipBoxSCM");
			var coords = $obj.attr("coords").split(",");
			var boxWidth = parseInt(coords[2])-parseInt(coords[0]);
			var boxHeight = parseInt(coords[3])-parseInt(coords[1]);
			$box.css("width",boxWidth);
			$box.css("height",boxHeight);
			leftPosition = parseInt(coords[0])-(boxWidth/2)+(parseInt(coords[2])-parseInt(coords[0]))/2;
			topPosition = parseInt(coords[1]);
			$box.css("top",topPosition);
			$box.css("left",leftPosition);
			$box.show();		
		}
		/* Main Plugin Code */
		return this.each(function() {
			/* Add events to various elements */
			$(this).hover(
				function () {
					show($(this));
				}, 
				function () {
					hide();
				}
			);
			$(this).click(function(){
				select($(this));
			});
		});
	};
})(jQuery);

/* gallerySCM */
var j_SCM = {};
(function($){
	$.fn.gallerySCM = function(options) {
		var opts = $.extend($.fn.gallerySCM.defaults,options);
		//Define jQuery objects for reuse
		var j_gallery;
		
		/* Plugin Methods */
		function showItem(index,j_gallery_id) {
			if(j_SCM[j_gallery_id].current==index) return;
			j_current = j_SCM[j_gallery_id].j_gallery;
			j_current.find("ul.filmstrip-panel li").removeClass("active");
			j_current.find("ul.filmstrip-panel li").eq(index).addClass("active");
			j_current.find("div.text-panel div").hide();
			j_current.find("div.text-panel div").eq(index).show();
			j_current.find("div.img-panel div").hide().css("z-index","0");
			j_current.find("div.img-panel div").eq(j_SCM[j_gallery_id].current).show();
			j_current.find("div.img-panel div").eq(index).css("z-index","1").fadeIn("slow",function(){
				j_SCM[j_gallery_id]['current'] = index;
			});
			j_SCM[j_gallery_id]['auto_wait'] = true;
		}
		function showNextItem(j_gallery_id) {
			if(j_SCM[j_gallery_id].current==j_SCM[j_gallery_id].max) showItem(0,j_gallery_id);
			else showItem(j_SCM[j_gallery_id].current+1,j_gallery_id);
		}
		function showPrevItem(j_gallery_id) {
			if(j_SCM[j_gallery_id].current==0) showItem(j_SCM[j_gallery_id].max,j_gallery_id);
			else showItem(j_SCM[j_gallery_id].current-1,j_gallery_id);
		}		
		function showNextSet(j_gallery_id) {
			if(j_SCM[j_gallery_id].set_current<j_SCM[j_gallery_id].set_count) {
				j_SCM[j_gallery_id].current_left = j_SCM[j_gallery_id].current_left-(j_SCM[j_gallery_id].filmstrip_max*j_SCM[j_gallery_id].li_width);
				j_SCM[j_gallery_id].set_current++;
				j_current = j_SCM[j_gallery_id].j_gallery;		
				if(j_SCM[j_gallery_id].set_current>=j_SCM[j_gallery_id].set_count) j_current.find("div.filmstrip-panel span.next").css("visibility","hidden");
				j_current.find("div.filmstrip-panel span.prev").css("visibility","visible");	
				j_current.find("ul.filmstrip-panel").dequeue().animate({ left: j_SCM[j_gallery_id].current_left }, j_SCM[j_gallery_id].speed, function() {
					showItem((j_SCM[j_gallery_id].set_current-1)*j_SCM[j_gallery_id].filmstrip_max,j_gallery_id);
				});
			}
		}
		function showPrevSet(j_gallery_id) {
			if(j_SCM[j_gallery_id].set_current>1) {
				j_SCM[j_gallery_id].current_left = j_SCM[j_gallery_id].current_left+(j_SCM[j_gallery_id].filmstrip_max*j_SCM[j_gallery_id].li_width);
				j_current = j_SCM[j_gallery_id].j_gallery;
				j_SCM[j_gallery_id].set_current--;
				if(j_SCM[j_gallery_id].set_current==1) j_current.find("div.filmstrip-panel span.prev").css("visibility","hidden");
				j_current.find("div.filmstrip-panel span.next").css("visibility","visible");
				j_current.find("ul.filmstrip-panel").dequeue().animate({ left: j_SCM[j_gallery_id].current_left }, j_SCM[j_gallery_id].speed, function() {
					showItem(((j_SCM[j_gallery_id].set_current-1)*j_SCM[j_gallery_id].filmstrip_max),j_gallery_id);
				});
			}
		}
		/* Main Plugin Code */
		return this.each(function() {
			j_gallery = $(this);
			if(opts.auto) {
				j_gallery.append("<div class='loading-num'><span>0</span>%</div>");
			}
			var j_gallery_id = $(this).attr("id");
			j_SCM[j_gallery_id] = {};
			j_SCM[j_gallery_id]['current'] = 0;
			j_SCM[j_gallery_id]['max'] = j_gallery.find("ul.filmstrip-panel li").length-1;
			j_SCM[j_gallery_id]['j_gallery'] = j_gallery;
			j_SCM[j_gallery_id]['filmstrip_max'] = opts.filmstrip_max;
			j_SCM[j_gallery_id]['current_left'] = 0;
			j_SCM[j_gallery_id]['speed'] = opts.speed;
			j_gallery.css("width",opts.gallery_width);
			j_gallery.css("height",opts.gallery_height);
			j_gallery.addClass("gallerySCM");
			j_gallery.prepend("<div class='img-panel'></div>");
			j_img = j_gallery.find("div.img-panel");
			j_img.after("<div class='filmstrip-panel'><div></div</div>").after("<div class='text-panel'></div>");
			j_gallery.find("ul.text-panel").appendTo(j_img.next());
			j_gallery.find("ul.filmstrip-panel").appendTo(j_img.next().next().children());
			j_count = 0;
			$.each(j_gallery.find("ul.filmstrip-panel li"),function(index){
				j_img.append("<div><img src='"+$(this).find("a").attr("href")+"'></div>");
				$(this).find("a").click(function() {
				  showItem(index,j_gallery_id);
				  return false;
				});
				j_count++;
			});
			
			j_SCM[j_gallery_id]['count'] = j_count;
			j_SCM[j_gallery_id]['set_current'] = 1;
			j_SCM[j_gallery_id]['set_count'] = Math.ceil(j_count/opts.filmstrip_max);
			
			$.each(j_gallery.find("ul.text-panel li"),function(){
				j_gallery.find("div.text-panel").append("<div style='display:none;'>"+$(this).html()+"</div>");
			});
			j_gallery.find("ul.text-panel").remove();
			j_gallery.find("div.text-panel").find("div").eq(0).show();
			
			j_gallery.find("ul.filmstrip-panel li").eq(0).addClass("active");
			j_SCM[j_gallery_id]['li_width'] = j_gallery.find("ul.filmstrip-panel li").eq(0).outerWidth();
			j_gallery.find("div.filmstrip-panel").prepend("<span class='prev' style='visibility:hidden;'></span>");
			j_gallery.find("div.filmstrip-panel").find("span.prev").click(function() {
				showPrevSet(j_gallery_id);
				return false;
			});
			j_gallery.find("div.filmstrip-panel").append("<span class='next' style='visibility:hidden;'></span>");
			
			j_gallery.find("div.filmstrip-panel").find("span.next").click(function() {
				showNextSet(j_gallery_id);
				return false;
			});
			if(j_count>opts.filmstrip_max) j_gallery.find("div.filmstrip-panel").find("span.next").css("visibility","visible");
			
			j_img.find("div").hide();
			
			if(opts.auto) {
				j_gallery.find("ul.filmstrip-panel").css("width",(j_SCM[j_gallery_id]['li_width']*j_count));
				j_gallery.find("div.filmstrip-panel div").css("width",(j_SCM[j_gallery_id]['li_width']*opts.filmstrip_max));
				j_gallery.find("div.text-panel").css("width",opts.gallery_width);
				j_gallery.find("div.text-panel").css("height",opts.text_height);
				j_gallery.find("div.text-panel").css("bottom",opts.filmstrip_height);
				j_gallery.find("div.filmstrip-panel").css("width",opts.gallery_width);
				j_gallery.find("div.filmstrip-panel").height(0);
				j_SCM[j_gallery_id]['auto'] = opts.auto;
				j_SCM[j_gallery_id]['auto_wait'] = false;
				j_SCM[j_gallery_id]['loading_num_current'] = 0;
				var img_count = j_img.find('img').length;
				var img_i = 1;
				j_SCM[j_gallery_id]['loading_num_tot'] = Math.ceil((99*img_i)/img_count);
				$.gallerySCM_loading_num(j_gallery_id);
				j_img.find('img').load(function() {
					if(img_i==img_count) {
						clearTimeout(j_SCM[j_gallery_id]['loading_num_timeout']);
						j_gallery.find("div.loading-num").remove();
						j_gallery.find("div.filmstrip-panel").animate({
							height: opts.filmstrip_height
						}, 500, function() {
							j_gallery.animate({ opacity: 1 }, 100);
							j_img.find("div").eq(0).css("z-index","1").fadeIn("slow");
							setTimeout("$.gallerySCM_autoPlay(\""+j_gallery_id+"\",\""+opts.auto+"\")", opts.auto);
						});
					}
					img_i++;
					j_SCM[j_gallery_id].loading_num_tot = Math.ceil((99*img_i)/img_count);
				});
			} else {
				j_img.find("div").eq(0).css("z-index","1").show();
				j_gallery.find("ul.filmstrip-panel").css("width",(j_SCM[j_gallery_id]['li_width']*j_count));
				j_gallery.find("div.filmstrip-panel div").css("width",(j_SCM[j_gallery_id]['li_width']*opts.filmstrip_max));
				j_gallery.find("div.text-panel").css("width",opts.gallery_width);
				j_gallery.find("div.text-panel").css("height",opts.text_height);
				j_gallery.find("div.filmstrip-panel").css("height",opts.filmstrip_height);
				j_gallery.find("div.text-panel").css("bottom",opts.filmstrip_height);
				j_gallery.find("div.filmstrip-panel").css("width",opts.gallery_width);
			}
			/* Add events to various elements */
		});
	};
	$.fn.gallerySCM.defaults = {
		gallery_width: 400,
		gallery_height: 300,
		text_height: 100,
		filmstrip_height: 100,
		filmstrip_max: 4,
		speed: 500,
		auto: 0
	};
})(jQuery);
jQuery.extend({
	gallerySCM_loading_num: function(j_gallery_id) {
		if(j_SCM[j_gallery_id].loading_num_current < j_SCM[j_gallery_id].loading_num_tot) {
			j_SCM[j_gallery_id].loading_num_current++;
			j_current = j_SCM[j_gallery_id].j_gallery;
			j_current.find("div.loading-num span").text(j_SCM[j_gallery_id].loading_num_current);
		}
		j_SCM[j_gallery_id]['loading_num_timeout'] = setTimeout("$.gallerySCM_loading_num(\""+j_gallery_id+"\")", 100);
	},
	gallerySCM_autoPlay: function(j_gallery_id) {
		if(!j_SCM[j_gallery_id].auto_wait) $.gallerySCM_showNextItem(j_gallery_id);
		else j_SCM[j_gallery_id].auto_wait = false;
		setTimeout("$.gallerySCM_autoPlay(\""+j_gallery_id+"\")", j_SCM[j_gallery_id].auto);
	},
	gallerySCM_showNextItem: function(j_gallery_id) {
		if(j_SCM[j_gallery_id].current==j_SCM[j_gallery_id].max) $.gallerySCM_showItem(0,j_gallery_id);
		else $.gallerySCM_showItem(j_SCM[j_gallery_id].current+1,j_gallery_id);
	},
	gallerySCM_showItem: function(index,j_gallery_id) {
		if(j_SCM[j_gallery_id].current==index) return;
		j_current = j_SCM[j_gallery_id].j_gallery;
		j_current.find("ul.filmstrip-panel li").removeClass("active");
		j_current.find("ul.filmstrip-panel li").eq(index).addClass("active");
		j_current.find("div.text-panel div").hide();
		j_current.find("div.text-panel div").eq(index).show();
		j_current.find("div.img-panel div").hide().css("z-index","0");
		j_current.find("div.img-panel div").eq(j_SCM[j_gallery_id].current).show();
		j_current.find("div.img-panel div").eq(index).css("z-index","1").fadeIn("slow",function(){
			j_SCM[j_gallery_id]['current'] = index;
		});
	},
	showGallerySCM: function(id) {
		if($('#'+id+':hidden').length){
			$('div.prodmenu ul li a').removeClass("current");
			var num = id.replace("imggallery", "");
			$('div.prodmenu ul li a').eq(num-1).addClass("current");
			$('.gallerySCM').css("z-index","0");
			$('#'+id).css("z-index","1").fadeIn("slow",function(){
				$('.gallerySCM').not('#'+id).hide();
			});
		}
	}
});

/* languageSCM */
(function($){
	$.fn.languageSCM = function() {
		function show() {
			$("#language_list").show();
		}
		function hide() {
			$("#language_list").hide();		
		}
		return this.each(function() {
			var language = ["lang_ita.png","index.htm","lang_en.png","index_en.htm"];
			$language = $(this).parent();
			var path_array = $language.find("img.flag").attr("src").split("/");
			var path = "";
			for(var i=0;i<(path_array.length-2);i++) {
				path+=path_array[i]+"/";
			}
			var path_image = path+path_array[i]+"/";
			var current_image = path_array[i+1];
			var str = "<div id='language_list'><ul>";
			for(var k=0;k<language.length;k++) {
				if(language[k]!=current_image) str+="<li><a href='"+path+language[k+1]+"'><img src='"+path_image+language[k]+"'></a></li>";
				k++;
			}
			str+="</ul></div>";
			$language.append(str);
			$(this).hover(
				function () {
					show();
				}, 
				function () {
					hide();
				}
			);
			$("#language_list").hover(
				function () {
					show();
				}, 
				function () {
					hide();
				}
			);
		});
	};
})(jQuery);
/* moreTextSCM */
var moreTextSCM_label = "";
(function($){
	$.fn.moreTextSCM = function() {
		return this.each(function() {
			//$(this).next("span").after("<a class='moreText' href='#' style='display:none;' onclick='return $.moreTextSCM_toggle(this);'>close</a>");
			var $a = $(this);
			var $span = $a.next("span");
			$span.after($a);
			$span.hide();
			moreTextSCM_label = $a.text();
			$a.click(function() {
				$.moreTextSCM_toggle(this);
				return false;
			});
		});
	};
})(jQuery);
jQuery.extend({
	moreTextSCM_open: function(obj) {
		$(obj).hide().next("span").slideDown("normal",function() {
			$(this).next("a").show();
		});
		return false;
	},
	moreTextSCM_close: function(obj) {
		$(obj).hide().prev("span").slideUp("normal",function() {
			$(this).prev("a").show();
		});
		return false;
	},
	moreTextSCM_toggle: function(obj) {
		if($(obj).prev("span:visible").length){
			$(obj).prev("span").slideUp("normal",function(){
				$(obj).text(moreTextSCM_label);
			});
		} else {
			$(obj).prev("span").slideDown("normal",function(){
				$(obj).text("«close");
			});
		}
		return false;
	}
});
