/*!
 * slideViewer 1.2
 * Examples and documentation at: 
 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/imagestrip/imageslide-plugin.html
 * 2007-2010 Gian Carlo Mingati
 * Version: 1.2.3 (9-JULY-2010)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Requires:
 * jQuery v1.4.1 or later, jquery.easing.1.2
 * 
 */

jQuery(function(){
   jQuery("div.svw").prepend("<img style=\"position:relative; top:100px; left:143px;\" src='../img/template/loading.png' class='ldrgif' alt='loading...'/ >"); 
});
var j 							= 0;
jQuery.fn.slideView 			= function(settings) {
	settings 					= jQuery.extend({
		easeFunc: 	"jswing",
		easeTime: 	500,
		autoslide: 	true,
		asTimer: 	5000, 
		uiBefore: 	false,
		toolTip: 	false,
		ttOpacity: 	0.9
	}, settings);
	return this.each(function(){
		var container 			= jQuery(this);
		container.find("img.ldrgif").remove();
		var auto_slide = container.attr("autoslide");
		container.removeClass("svw").addClass("stripViewer");		
		var pictWidth 			= container.find("div").width();
		var pictHeight 			= container.find("div").height();
		var pictEls 			= container.find("li").size();
		var stripViewerWidth 	= pictWidth*pictEls;
		container.find("ul").css("width", stripViewerWidth);
		container.css("width", pictWidth);
		container.css("height", pictHeight);
		container.each(function(i) {
    		(!settings.uiBefore) ? 
				jQuery(this).after("<div class='stripTransmitter' id='stripTransmitter"  + (j) + "'><\/div><ul class='ulTransmitter' id='ulTransmitter" + (j) + "'><\/ul>") : 
				jQuery(this).before("<div class='stripTransmitter' id='stripTransmitter" + (j) + "'><\/div><ul id='ulTransmitter" + (j) + "'><\/ul>");
			$tot = jQuery(this).find("li").length;
			//----------------------------------------
			for ($n = 1; $n <= $tot; $n++) {

				jQuery("div#stripTransmitter" + j).append("<div id=\"tooltip"+j+$n+"\" class=\"tooltip\" style=\""+($n == 1 ? "" : "display:none")+";\">"+tooltip[j][$n - 1]+"<\/div>");
				jQuery("div#stripTransmitter" + j + " div.tooltip").css("width" , (pictWidth - ($tot * 20) - $tot - 5 - 5));

				jQuery("ul#ulTransmitter" + j).append("<li><a href='#'>" + ($n) + "<\/a><\/li>");												
			};
			//----------------------------------------
			jQuery("ul#ulTransmitter" + j + " a").each(function(z) {
				jQuery(this).bind("click", function(){		
					jQuery(this).addClass("current").parent().parent().find("a").not(jQuery(this)).removeClass("current");
					var cnt 	= -(pictWidth*z);
					container.find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
					$numero = parseInt(jQuery(this).text());
					//jQuery("div#tooltip" + $numero).css("display", "inline-block").parent().find("div").not(jQuery("div#tooltip" + $numero)).css("display", "none");
					$pos = parseInt(jQuery(this).parent().parent().attr('id').replace('ulTransmitter',''));
					jQuery("div#tooltip" + $pos + $numero).show(500).parent().find("div").not(jQuery("div#tooltip" + $pos + $numero)).hide(500);
					return false;
				});
			});
		
			container.bind("click", function(e){
				var ui 			= (!settings.uiBefore) ? jQuery(this).next().find("a.current") : jQuery(this).prev().find("a.current");
				var bTotal 		= parseFloat(jQuery(this).css('borderLeftWidth').replace("px", "")) +  parseFloat(jQuery(this).css('borderRightWidth').replace("px", ""));
				var dOs 		= jQuery(this).offset();
				var zeroLeft 	= (bTotal/2 + pictWidth) - (e.pageX - dOs.left);
				if(zeroLeft >= pictWidth/2) { 
					var uiprev 	= ui.parent().prev().find("a");	
					(jQuery(uiprev).length != 0)? uiprev.trigger("click") : ui.parent().parent().find("a:last").trigger("click");
				} 
				else {
					var uinext 	= ui.parent().next().find("a");
					(jQuery(uinext).length != 0)? uinext.trigger("click") : ui.parent().parent().find("a:first").trigger("click");
				}
			});

			if ((settings.autoslide) && (auto_slide == 1)){
				var i = 1;
				
				jQuery("div#stripTransmitter" + j).everyTime(settings.asTimer, "asld", function() {			
					jQuery(this).find("a").eq(i).trigger("click");

					var ui 			= (!settings.uiBefore) ? jQuery(this).next().find("a.current") : jQuery(this).prev().find("a.current");
					var bTotal 		= parseFloat(jQuery(this).css('borderLeftWidth').replace("px", "")) +  parseFloat(jQuery(this).css('borderRightWidth').replace("px", ""));
					var dOs 		= jQuery(this).offset();
					var zeroLeft 	= (bTotal/2 + pictWidth) - (this.pageX - dOs.left);
					if(zeroLeft >= pictWidth/2) { 
						var uiprev 	= ui.parent().prev().find("a");	
						(jQuery(uiprev).length != 0)? uiprev.trigger("click") : ui.parent().parent().find("a:last").trigger("click");							
					} 
					else {
						var uinext 	= ui.parent().next().find("a");
						(jQuery(uinext).length != 0)? uinext.trigger("click") : ui.parent().parent().find("a:first").trigger("click");
					}
					(i < pictEls - 1)?	i++ : i = 0;
				});		
				
				//stops autoslidemode	
				jQuery("ul#ulTransmitter" + j + " a").bind("mouseup", function(){
					jQuery(this).parent().parent().siblings(".stripTransmitter").stopTime("asld");
				});
			}

			jQuery("div#stripTransmitter" + j).css("width" , (pictWidth - ($tot * 20) - $tot));
			jQuery("ul#ulTransmitter" + j + " li a:first").addClass("current");
		});
		j++;
		//--------------------------------------------
/*		infobox = 0;
		if ($(".right_sidebar_info").length > 0)
			infobox = $(".right_sidebar_info").height() + 54 + 45;
		//--------------------------------------------
		var $tot_genres_artists	= $("#id_genres").height();
		var $tot_horizontalthumb 	= 0
		for ($w = 0; $w < $(".right_sidebar_horizontalthumb").length; $w++){
			$tot_horizontalthumb 	+= $("#id_horizontalthumb"+$w).height() + 35;
		}
		var $tot_slideview 		= 0
		for ($w = 0; $w < $(".right_sidebar_slideview").length; $w++){
			$tot_slideview 		+= $("#id_slideview"+$w).height() + 35;
		}
		var $tot_verticalthumb 	= 0
		for ($w = 0; $w < $(".right_sidebar_verticalthumb").length; $w++){
			$tot_verticalthumb 	+= $("#id_verticalthumb"+$w).height() + 35;
		}
		max0 					= $tot_genres_artists + $tot_horizontalthumb + $tot_slideview + $tot_verticalthumb + infobox;
		max1 					= $tot_genres_artists + $tot_horizontalthumb + $tot_slideview + $tot_verticalthumb + infobox;

		var page 				= String(window.location.pathname);
		var $tot_content = 0;
		for ($w = 0; $w < $(".content_titolo_about_violet").length; $w++){
			$tot_content 		+= $(".content_titolo_about_violet").height() + 20;
		}
		for ($w = 0; $w < $(".content_titolo_about_black").length; $w++){
			$tot_content 		+= $(".content_titolo_about_black").height() + 20;
		}
		for ($w = 0; $w < $(".content_testo_about").length; $w++){
			$tot_content 		+= $(".content_testo_about").height();
		}
		if (page == "/about.php")
			max1 = (max1 > $tot_content ? max1 : $tot_content);

		max1					= (max1 < 700 ? 700 : max1);
		//--------------------------------------------
		height0 = max1;
		//alert("A."+max0+" - "+max1+" - "+height0);

		//--------------------------------------------
		$('.container_main1').animate(	{height: 	height0 + 30}, 0 );
		//--------------------------------------------
		$('.xspacer1').animate(			{height: 	height0 + 30}, 0 );
		$('.xspacer2').animate(			{height: 	height0 + 30}, 0 );
		//--------------------------------------------
		$('.content').animate(			{height: 	height0 + 5}, 0 );
		//--------------------------------------------
		$('.right_sidebar').animate(	{height:	height0 + 5}, 0 );
		//--------------------------------------------
		$('.container_main2').animate(	{height:	height0 + 30}, 0 );
		//--------------------------------------------
*/
		$('#session_contact').load('../modules/session_contact.php');
		//--------------------------------------------
		$('#session_contact_c').load('../modules/session_contact.php');
	});	
};
