

	

$(function() 
{
	
		$('#img.gallery').click( function() {gallery( $(this).attr('title'))} );

	// custom transition fn (trying to get it to scroll forward and backward)
	// effect by Nathan Colgate 
	//http://www.nathancolgate.com/post/96953675/jquery-cycle-different-effects-for-previous-and-next
	$.fn.cycle.transitions.scrollBothWays = function($cont, $slides, opts) {
	$cont.css('overflow','hidden');

	opts.before.push($.fn.cycle.commonReset);
	opts.fxFn = function(curr, next, opts, cb, fwd) {
		var w = $cont.width();
		opts.cssFirst = { left: 0 };
		opts.animIn	  = { left: 0 };

		if(fwd){

			opts.cssBefore= { left: w, top: 0 };
			opts.animOut  = { left: 0-w };

		}else{

			opts.cssBefore= { left: -w, top: 0 };
			opts.animOut  = { left: w };
		};

		

		var $l = $(curr), $n = $(next);
		var speedIn = opts.speedIn, speedOut = opts.speedOut, easeIn = opts.easeIn, easeOut = opts.easeOut, animOut = opts.animOut, animIn = opts.animIn;
		$n.css(opts.cssBefore);

		var fn = function() {$n.show();$n.animate(animIn, speedIn, easeIn, cb);};
		$l.animate(animOut, speedOut, easeOut, function() {

			if (opts.cssAfter) $l.css(opts.cssAfter);
			if (!opts.sync) fn();
		});

		if (opts.sync) fn();

	};
};
		
});


function notice()
{

    $('<div></div>').modal({
			onOpen: function (dialog) {
				dialog.overlay.fadeIn('fast', function () {
					dialog.container.slideDown('fast', function () {
						dialog.data.fadeIn('fast');
					});
				});
				auto_resize();
			},

			onClose: function (dialog) {
				dialog.data.fadeOut('fast', function () {
					dialog.container.slideUp('fast', function () {
						dialog.overlay.fadeOut('fast', function () {
							$.modal.close();
						});
					});
				});
			},

			containerCss:{
				backgroundColor:"#fff",
				borderColor:"#0063dc",
				height:450,
				width: 400,
				'text-align':'center',
				padding:0
			},


			opacity : 65,
			overlayCss : {background: '#666'},

			close : true,
			closeHTML: '<div style="background-color:#fff; padding-right:5px;  text-align:right" class="close"><a href="#" class="simplemodal-close">chiudi x</a></div>'
		});
}

function gallery( product_id)
{
	//prendo una copia dell'immagine l'immagine
	
	//levo gli attributi per la grandezza
	
	
	$.post('http://'+document.domain+'/index.php?/commerce/commerce/products_images/'+product_id,
	function(data){

	//guardiamolo meglio
	$(data).modal({ 
			onOpen: function (dialog) {
				dialog.overlay.fadeIn('fast', function () {
					dialog.container.slideDown('fast', function () {
						dialog.data.fadeIn('fast');
					});
				});
				auto_resize();
			},

			onClose: function (dialog) {
				dialog.data.fadeOut('fast', function () {
					dialog.container.slideUp('fast', function () {
						dialog.overlay.fadeOut('fast', function () {
							$.modal.close(); 
						});
					});
				});
			},

			containerCss:{
				backgroundColor:"#fff",
				borderColor:"#0063dc",
				height:450,
				width: 400,
				'text-align':'center',
				padding:0
			},


			opacity : 65,
			overlayCss : {background: '#666'},
			
			close : true,
			closeHTML: '<div style="background-color:#fff; padding-right:5px;  text-align:right" class="close"><a href="#" class="simplemodal-close">chiudi x</a></div>'
		});
	      
		 $('#slideshow').height(400);
		
		$('#slideshow').cycle({ 
		  fx:     'scrollBothWays', 
		  next:   '#next', 
		  prev:   '#prev',
		  easeIn: 'easeOutSine',
		  easeOut: 'easeOutSine'
		});

	});
	
}

function auto_resize()
{
	$('.auto_resize').each(function(i){
		
		//nasconilo mentro lo carichi el suo posto scrivi loading
		$(this).hide();

		this.onload = function(){
			$(this).prev('p').hide();
	    		if( this.naturalHeight > 300)
			{
		      		$(this).attr('height','300');
			}
		$(this).show();
		}
	});
}
