//var BASE_URL = '/pinkograf';
var BASE_URL = '';

var Pinkograf = {
	initLanding: function()
	{
		$('#landing_top_tabs li a', function($a, i)
		{
			$a.addEvent('click', function(event)
			{
				$('#landing_top_tabs li a', function($aa)
				{
					$aa.removeClass('active');
				});
				
				$a.addClass('active');
				
				I('landing_top_container').morph({
					css: {
						left: ['px', ACTUAL, -(i * 890)]
					}
				});
				
				return event.stop();
			});
		});
	},
	initLastminuteBox: function()
	{
		$('#lastminutes_box > ul a', function($a, i)
		{
			var id = $a.parent().id.replace('_tab', '');
			
			$a.addEvent('mouseover', function()
			{
				$('#lastminutes_box > ul a', function($aa)
				{
					$aa.removeClass('active');
				});
				
				this.addClass('active');
				
				I('lastminutes_box_container').morph({
					css: {
						left: ['px', ACTUAL, -(i * 575)] 
					}
				});
			});
			
			
		});
		
		var lastminutes = $('#lastminutes_box .lastminute');
		
		if (lastminutes.length > 1) 
		{
		
			lastminutes.each(function($div, i)
			{
				if (i) 
				{
					if (Agent.trident) 
					{
						$div.css('display', 'none');
					}
					else 
					{
						$div.css('opacity', 0);
					}
				}
			});
			
			var actls = 0;
			
			function changels()
			{
				nextls = actls + 1;
				
				if (nextls > lastminutes.length - 1) 
				{
					nextls = 0;
				}
				
				if (Agent.trident) 
				{
					lastminutes[actls].hide();
					lastminutes[nextls].show();
					
					setTimeout(changels, 7000);
					actls = nextls;
					
					return;
				}
				
				lastminutes[actls].morph(
				{
					css: 
					{
						opacity: [1, 0]
					},
					onFinish: function()
					{
						lastminutes[nextls].morph(
						{
							css: 
							{
								opacity: [0, 1]
							}
						});
						
						setTimeout(changels, 7000);
					}
				});
				
				actls = nextls;
			}
			
			setTimeout(changels, 7000);
			
		}
		
	},
	initLoginBox: function()
	{
		if (I('lb_username')) 
		{
			Require.module('form', function()
			{
				Form.labeledInput('lb_username', 'username');
				Form.labeledInput('lb_password', 'password');
			});
		}
		
		if (I('lb_socials')) 
		{
			Require.module('tooltips', function()
			{
				$('#lb_socials a', function($a)
				{
					new Tooltip({
						target: $a,
						content: $a.title,
						className: 'lb-tooltip',
						offsetX: -90,
						offsetY: -70
					});
					
					$a.title = ''; 
				});
			});
		}
		
		
		var $link = I('lb_login');
		
		if ($link) 
		{
			var $text = $('strong', $link, true), $div = $('span', $link, true), $arrow = $('em', $link, true);
			
			$link.addEvent('click', function(event)
			{
				I('lb_form').submit();
				
				event.preventDefault();
				
			}).addEvent('mouseenter', function()
			{
				$text.morph({
					css: {
						left: ['px', ACTUAL, 55]
					}
				});
				
				$div.morph({
					css: {
						left: ['px', ACTUAL, 46]
					}
				});
				
				$arrow.morph({
					css: {
						left: ['px', ACTUAL, 10]
					}
				});
				
			}).addEvent('mouseleave', function()
			{
				$text.morph({
					css: {
						left: ['px', ACTUAL, 10]
					}
				});
				
				$div.morph({
					css: {
						left: ['px', ACTUAL, 53]
					}
				});
				
				$arrow.morph({
					css: {
						left: ['px', ACTUAL, 60]
					}
				});
			});
		}

	},
	totalProducts: 0,
	lastProductsFrame: 0,
	actualFrame: 0,
	initProductsList: function()
	{
		// Filtro prodotti
		
		var url = document.location + '',
		mt = url.match(/type-([0-9]+)/i), type = mt ? mt[1] : 0,
		mm = url.match(/material-([0-9]+)/i), material = mm ? mm[1] : 0;
		
		if(!type && !material)
		{
			var saved = Cookie.get('prod_filter') || '';
			saved = saved.split(' ');
			type = (saved[0] || '0').toInt();
			material = (saved[1] || '0').toInt();
		}
		
		$('#products_list_product_filter_menu a', function($a)
		{
			$a.addEvent('click', function(event)
			{
				$('#products_list_product_filter_menu a.active', function($aa)
				{
					$aa.removeClass('active');
				});
				
				this.addClass('active');
				
				Pinkograf.refreshProductsList();
				
				return event.stop();
			});
			
			if((mt = $a.href.match(/type-([0-9]+)/i)) && mt[1] == type)
			{
				$a.addClass('active');
			}
		});
		
		
		$('#products_list_material_filter_menu a', function($a)
		{
			$a.addEvent('click', function(event)
			{
				$('#products_list_material_filter_menu a.active', function($aa)
				{
					$aa.removeClass('active');
				});
				
				this.addClass('active');
				
				Pinkograf.refreshProductsList();
				
				return event.stop();
			});
			
			if($a.href.has('material-' + material))
			{
				$a.addClass('active');
			}
		});
	
		
		// Lista prodotti
		
		var products = $('#products_list_container .product');
		
		Pinkograf.totalProducts = products.length;
		Pinkograf.lastProductsFrame = Math.ceil(Pinkograf.totalProducts / 6) - 1;
		
		
		I('products_list_nav_prev').addEvent('click', function()
		{
			if(Pinkograf.actualFrame > 0)
			{
				Pinkograf.actualFrame--;
				
				I('products_list_container').morph({
					css: {
						top: ['px', ACTUAL, -(Pinkograf.actualFrame * 400)]
					}
				});
				
				if(Pinkograf.actualFrame === 0)
				{
					I('products_list_nav_prev').css('opacity', 0.5);
				}
				
				I('products_list_nav_next').css('opacity', 1);
				
				I('products_list_nav_count').replaceChilds((Pinkograf.actualFrame + 1) + ' / ' + (Pinkograf.lastProductsFrame + 1));
			}
		});
		
		I('products_list_nav_next').addEvent('click', function()
		{
			if(Pinkograf.actualFrame < Pinkograf.lastProductsFrame)
			{
				Pinkograf.actualFrame++;
				
				I('products_list_container').morph({
					css: {
						top: ['px', ACTUAL, -(Pinkograf.actualFrame * 400)]
					}
				});
				
				if(Pinkograf.actualFrame === Pinkograf.lastProductsFrame)
				{
					I('products_list_nav_next').css('opacity', 0.5);
				}
				
				I('products_list_nav_prev').css('opacity', 1);
				
				I('products_list_nav_count').replaceChilds((Pinkograf.actualFrame + 1) + ' / ' + (Pinkograf.lastProductsFrame + 1));
			}
		});
		
		
		I('products_list_nav_prev').css('opacity', 0.5);
		
		if(Pinkograf.lastProductsFrame === 0)
		{
			I('products_list_nav_next').css('opacity', 0.5);
		}
		
		I('products_list_wrapper').append(['div', {
			id: 'products_list_noone',
			style: {
				display: 'none'
			}
		}, 'Non ci sono prodotti per la combinazione di filtri che hai impostato']);
		
		if(type || material)
		{
			Pinkograf.refreshProductsList();
		}
	},
	refreshProductsList: function()
	{
		var $typeA = $('#products_list_product_filter_menu a.active')[0], type = 0;
		
		if($typeA)
		{
			type = $typeA.href.split('-').pop();
		}
		
		var $materialA = $('#products_list_material_filter_menu a.active')[0], material = 0;
		
		if($materialA)
		{
			material = $materialA.href.split('-').pop();
		}
		
		
		var lang = I('root').hasClass('en') ? 'en' : 'it';
		
		Ajax.get({
			url: BASE_URL + '/index.php?mdu=products-list/ajax-list&language=' + lang + '&type=' + type + '&material=' + material,
			cache: true,
			onFinish: function(text)
			{
				var result = text.parseJSON();
				
				if(result && result.success)
				{
					Cookie.set('prod_filter', type + ' ' + material);
					
					var $productsContainer = I('products_list_container');
					
					// Rimuovo i prodotti attuali
					$productsContainer.removeChilds();
					
					$productsContainer.css('top', 0);
					
					var data = result.data;
					
					
					
					data.each(function(row)
					{
						$productsContainer.append(['div', {
							className: 'product'
						}, ['a', {
							href: row.url
						}, ['img', {
							src: row.image
						}], ['span'], ['strong', row.name]]]);
					});
					
					
					Pinkograf.totalProducts = data.length;
					Pinkograf.lastProductsFrame = Math.ceil(Pinkograf.totalProducts / 6) - 1;
					Pinkograf.actualFrame = 0;
					
					I('products_list_nav_prev').css('opacity', 0.5);
					
					if(Pinkograf.lastProductsFrame <= 0)
					{
						I('products_list_nav_next').css('opacity', 0.5);
					}
					else
					{
						I('products_list_nav_next').css('opacity', 1);
					}
					
					if (Pinkograf.lastProductsFrame > 0) 
					{
						I('products_list_nav_count').show().replaceChilds('1 / ' + (Pinkograf.lastProductsFrame + 1));
					}
					else
					{
						I('products_list_nav_count').hide();
					}
					
					if(Pinkograf.totalProducts > 0)
					{
						I('products_list_noone').hide();
					}
					else
					{
						I('products_list_noone').show();
					}
				}
			}
		});
	},
	initProductDetail: function()
	{
		if (I('product_image_wrapper')) 
		{
			Require.module('images-transitions', function()
			{
				var visualSize = I('product_image_wrapper').sizes();
				
				var trans = new ImageTransitions({
					width: visualSize[0],
					height: visualSize[1],
					target: 'product_image_wrapper',
					transitions: [ImageTransitions.presets.openRight]
				});
				
				trans.nextImage();
				
				ImageTransitions.presets.openLeft.time = 0.5;
				ImageTransitions.presets.openRight.time = 0.5;
				
				I('product_image_prev').addEvent('click', function()
				{
					trans.prevImage(ImageTransitions.presets.openLeft);
				});
				
				I('product_image_next').addEvent('click', function()
				{
					trans.nextImage(ImageTransitions.presets.openRight);
				});
			});
		}
		
		// quantità prodotto
		
		function initOption($select)
		{
			if ($select.id == 'pc_prod_drafts') 
			{
				if ($select.value > 0) 
				{
					I('pc_prod_drafts_text').hide();
				}
			}
			
			$select.addEvent('change', function()
			{
				if($select.id == 'pc_prod_drafts')
				{
					if($select.value > 0)
					{
						I('pc_prod_drafts_text').hide();
					}
					else
					{
						I('pc_prod_drafts_text').show();
					}
				}
				
				changeOption(this);
				
				this.blur();
				
				Pinkograf.refreshOrderTotal();
				
			}).addEvent('focus', function()
			{
				this.parent().addClass('focus');
			}).addEvent('blur', function()
			{
				this.parent().removeClass('focus');
			});
			
			changeOption($select);
		}
		
		
		
		function changeOption($select)
		{
			var label;
			
			$('option', $select, function($option)
			{
				if($option.selected)
				{
					label = $option.getText();
				}
			});
			
			
			var $span = $('span', $select.parent(), true);
			
			$span.replaceChilds(label)
		}
		
		initOption(I('pc_prod_quantity'));
		initOption(I('pc_prod_drafts'));
		
		
		
		

		$('.spec-field', function($div)
		{
			$div.addEvent('click', function()
			{
				if (!this.hasClass('disabled')) 
				{
					this.toggleClass('checked');
					
					I($div.id.replace('label', 'field')).checked = this.hasClass('checked');
					
					Pinkograf.refreshOrderTotal();
				}
			});
		});
		
		$('.spec-field-baloon', function($div)
		{
			$div.addEvent('click', function(event)
			{
				document.location = $('a', this, true).href;
				
				return event.stop();
			});
		});
		
		$('#order_button_1', function($div)
		{
			$div.addEvent('click', function(event)
			{
				// Controllo per biglietti alluminio anodizzato
				if((document.location + '').has('biglietti-da-visita-metallo.') || (document.location + '').has('metal-aluminium-business-cards.'))
				{
					var colorsIds = [32, 33, 34, 35, 36], selected = false;
					
					colorsIds.each(function(id)
					{
						var $field = I('field_spec_' + id);
						
						if($field && $field.checked)
						{
							selected = true;
						}
					});
					
					if(!selected)
					{
						if(Pinkograf.en)
						{
							alert('You must select a color for anodizing. You can find them among special designs\' options.');
						}
						else
						{
							alert('Devi selezionare un colore per l\'anodizzazione.\nTrovi quelli disponibili tra le lavorazioni aggiuntive.');
						}
						
						return event.stop();
					}
				}
				
				if (I('field_spec_10') || I('field_spec_27') || I('field_spec_28') || I('field_spec_29')) 
				{
				
					var quant = I('pc_prod_quantity').value, $field;
					
					
					
					var nom_en = 'Orders with multiple names are possible with a minimum quantity of 500 units per name.\n\n',
					nom_it = 'Ordini con nominativi multipli sono possibili con una quantità minima di 500 unità per nominativo.\n\n',
					
					
					// Controllo per 2 nominativi multipli
					
					$field = I('field_spec_10');
					
					if ($field && $field.checked && (quant < 1000 || quant % 1000 !== 0)) 
					{
						if (Pinkograf.en) 
						{
							alert(nom_en + 'With two names are possible orders only with a quantity of 1000, 2000, 3000, 4000 or 5000 units');
						}
						else 
						{
							alert(nom_it + 'Con due nominativi multipli sono possibili ordini con una quantità di 1000, 2000, 3000, 4000 o 5000 unità');
						}
						
						return event.stop();
					}
					
					
					// Controllo per 3 nominativi multipli
					
					$field = I('field_spec_27');
					
					if ($field && $field.checked && (quant < 1500 || quant % 1500 !== 0)) 
					{
						if (Pinkograf.en) 
						{
							alert(nom_en + 'With three names are possible orders only with a quantity of 1500, 3000 or 4500 units');
						}
						else 
						{
							alert(nom_it + 'Con tre nominativi multipli sono possibili ordini con una quantità di 1500, 3000 o 4500 unità');
						}
						
						return event.stop();
					}
					
					
					// Controllo per 4 nominativi multipli
					
					$field = I('field_spec_28');
					
					if ($field && $field.checked && (quant < 2000 || quant % 2000 !== 0)) 
					{
						if (Pinkograf.en) 
						{
							alert(nom_en + 'With four names are possible orders only with a quantity of 2000 or 4000 units');
						}
						else 
						{
							alert(nom_it + 'Con quattro nominativi multipli sono possibili ordini con una quantità di 2000 o 4000 unità');
						}
						
						return event.stop();
					}
					
					
					// Controllo per 5 nominativi multipli
					
					$field = I('field_spec_29');
					
					if ($field && $field.checked && (quant < 2500 || quant % 2500 !== 0)) 
					{
						if (Pinkograf.en) 
						{
							alert(nom_en + 'With five names are possible orders only with a quantity of 2500 or 5000 units');
						}
						else 
						{
							alert(nom_it + 'Con cinque nominativi multipli sono possibili ordini con una quantità di 2500 o 5000 unità');
						}
						
						return event.stop();
					}
				}
				
				I('product_form').submit();
			});
		});
		
		
		// Rendere cliccabile uno alla volta i colori pantone
		
		$('#label_spec_3, #label_spec_4, #label_spec_15, #label_spec_38, #label_spec_39, #label_spec_40', function($label)
		{
			$label.addEvent('click', function()
			{
				$('#label_spec_3, #label_spec_4, #label_spec_15, #label_spec_38, #label_spec_39, #label_spec_40', function($subLabel)
				{
					if($subLabel != $label)
					{
						$subLabel.removeClass('checked');
						I($subLabel.id.replace('label', 'field')).checked = false;
					}
				});		
			});
		});
		
		
		//  Con Fustellatura personalizzata	rendere non cliccabile Formato non standard
		
		$('#label_spec_55, #label_spec_8, #label_spec_9', function($label)
		{
			$label.addEvent('click', function()
			{
				$('#label_spec_55, #label_spec_8, #label_spec_9', function($subLabel)
				{
					if($subLabel != $label)
					{
						$subLabel.removeClass('checked');
						I($subLabel.id.replace('label', 'field')).checked = false;
					}
				});		
			});
		});
		
		
		// Nominativi multipli

		if (I('field_spec_10') || I('field_spec_27') || I('field_spec_28') || I('field_spec_29')
		 || I('field_spec_56') || I('field_spec_57') || I('field_spec_58') || I('field_spec_59') || I('field_spec_60')) 
		{
			$('#label_spec_10, #label_spec_27, #label_spec_28, #label_spec_29, #label_spec_56, #label_spec_57, #label_spec_58, #label_spec_59, #label_spec_60', function($label)
			{
				$label.addEvent('click', function()
				{
					$('#label_spec_10, #label_spec_27, #label_spec_28, #label_spec_29, #label_spec_56, #label_spec_57, #label_spec_58, #label_spec_59, #label_spec_60', function($subLabel)
					{
						if($subLabel != $label)
						{
							$subLabel.removeClass('checked');
							I($subLabel.id.replace('label', 'field')).checked = false;
						}
					});		
				});
			});
			
			function disableField(id, cl)
			{
				var $f = I(id);
				
				if (!cl) 
				{
					$f.addClass('disabled');
					$f.removeClass('checked');
					I($f.id.replace('label', 'field')).checked = false;
				}
				else
				{
					$f.removeClass('disabled');
				}
			}
			
			function checkQuant(quant)
			{
				switch(quant)
				{
					case '250':
					
						disableField('label_spec_10');
						disableField('label_spec_27');
						disableField('label_spec_28');
						disableField('label_spec_29');
						disableField('label_spec_56');
						disableField('label_spec_57');
						disableField('label_spec_58');
						disableField('label_spec_59');
						disableField('label_spec_60');
					
					break;
					case '500':
					
						disableField('label_spec_10');
						disableField('label_spec_27');
						disableField('label_spec_28');
						disableField('label_spec_29');
						disableField('label_spec_56');
						disableField('label_spec_57');
						disableField('label_spec_58');
						disableField('label_spec_59');
						disableField('label_spec_60');
					
					break;
					case '1000':
					
						disableField('label_spec_10', true);
						disableField('label_spec_27');
						disableField('label_spec_28');
						disableField('label_spec_29');
						disableField('label_spec_56');
						disableField('label_spec_57');
						disableField('label_spec_58');
						disableField('label_spec_59');
						disableField('label_spec_60');
					
					break;
					case '1500':
					
						disableField('label_spec_10');
						disableField('label_spec_27', true);
						disableField('label_spec_28');
						disableField('label_spec_29');
						disableField('label_spec_56');
						disableField('label_spec_57');
						disableField('label_spec_58');
						disableField('label_spec_59');
						disableField('label_spec_60');
					
					break;
					case '2000':
					
						disableField('label_spec_10', true);
						disableField('label_spec_27');
						disableField('label_spec_28', true);
						disableField('label_spec_29');
						disableField('label_spec_56');
						disableField('label_spec_57');
						disableField('label_spec_58');
						disableField('label_spec_59');
						disableField('label_spec_60');
					
					break;
					case '2500':
					
						disableField('label_spec_10');
						disableField('label_spec_27');
						disableField('label_spec_28');
						disableField('label_spec_29', true);
						disableField('label_spec_56');
						disableField('label_spec_57');
						disableField('label_spec_58');
						disableField('label_spec_59');
						disableField('label_spec_60');
					
					break;
					case '3000':
					
						disableField('label_spec_10', true);
						disableField('label_spec_27', true);
						disableField('label_spec_28');
						disableField('label_spec_29');
						disableField('label_spec_56', true);
						disableField('label_spec_57');
						disableField('label_spec_58');
						disableField('label_spec_59');
						disableField('label_spec_60');
					
					break;
					case '3500':
					
						disableField('label_spec_10');
						disableField('label_spec_27');
						disableField('label_spec_28');
						disableField('label_spec_29');
						disableField('label_spec_56');
						disableField('label_spec_57', true);
						disableField('label_spec_58');
						disableField('label_spec_59');
						disableField('label_spec_60');
					
					break;
					case '4000':
					
						disableField('label_spec_10', true);
						disableField('label_spec_27');
						disableField('label_spec_28', true);
						disableField('label_spec_29');
						disableField('label_spec_56');
						disableField('label_spec_57');
						disableField('label_spec_58', true);
						disableField('label_spec_59');
						disableField('label_spec_60');
					
					break;
					case '4500':
					
						disableField('label_spec_10');
						disableField('label_spec_27', true);
						disableField('label_spec_28');
						disableField('label_spec_29');
						disableField('label_spec_56');
						disableField('label_spec_57');
						disableField('label_spec_58');
						disableField('label_spec_59', true);
						disableField('label_spec_60');
					
					break;
					case '5000':
					
						disableField('label_spec_10', true);
						disableField('label_spec_27');
						disableField('label_spec_28');
						disableField('label_spec_29', true);
						disableField('label_spec_56');
						disableField('label_spec_57');
						disableField('label_spec_58');
						disableField('label_spec_59');
						disableField('label_spec_60', true);
					
					break;
					case '5500':
					
						disableField('label_spec_10');
						disableField('label_spec_27');
						disableField('label_spec_28');
						disableField('label_spec_29');
					
					break;
					case '6000':
					
						disableField('label_spec_10', true);
						disableField('label_spec_27', true);
						disableField('label_spec_28');
						disableField('label_spec_29');
						disableField('label_spec_56', true);
						disableField('label_spec_57');
						disableField('label_spec_58');
						disableField('label_spec_59');
						disableField('label_spec_60');
					
					break;
				}
			}
			
			I('pc_prod_quantity').addEvent('change', function()
			{
				checkQuant(this.value);
			});
			
			checkQuant(I('pc_prod_quantity').value);
			
			Pinkograf.refreshOrderTotal();
		}
		
		
	},
	
	initOrder: function()
	{
		$('#order-box-pay-method label', function($input)
		{
			$input.addEvent('click', function()
			{
				setTimeout(function()
				{
					Pinkograf.refreshOrderTotal();
				}, 100);
			});
		});
		
		if(I('order-box-login'))
		{
			I('order-box-login').addEvent('click', function(event)
			{
				I('order-box-username-h').value = I('order-box-username-v').value;
				I('order-box-password-h').value = I('order-box-password-v').value;
				
				I('order-box-login-form').submit();
				
				return event.stop();
			});
		}
		
		
		if (I('order_cart_button')) 
		{
			I('order_cart_button').addEvent('click', function(event)
			{
				I('order_form').submit();
			});
		}
	},
	refreshOrderTotal: function()
	{
		var postData = {}, specsData = [];
		
		$('#product_form input, #product_form select, #order_form input, #order_form select').each(function($input)
		{
			var type = $input.type;
			
			if(type == 'radio' || type == 'checkbox')
			{
				if($input.checked)
				{
					if ($input.name == 'specs[]') 
					{
						specsData.push($input.value);
					}
					else 
					{
						postData[$input.name] = $input.value;
					}
				}
			}
			else
			{
				if ($input.name == 'specs[]') 
				{
					specsData.push($input.value);
				}
				else 
				{
					postData[$input.name] = $input.value;
				}
			}
		});
		
		postData.product_id = I('field_product_id').value;
		postData.specs = specsData;
		
		Ajax.get({
			url: BASE_URL + '/index.php?mdu=order/ajax-price',
			post: postData,
			onFinish: function(result)
			{
				result = result.parseJSON();
				
				if(result && result.success)
				{

					
					var en = I('root').hasClass('en');
					
					if (I('order_cart_total_noiva')) 
					{
						I('order_cart_pay').replaceChilds((result.pay_cost.toInt() > 0 ? (en ? 'PayPal costs: € ' : 'Addizionale PayPal: € ') + result.pay_cost : ''));
						I('order_cart_total_noiva').replaceChilds((en ? 'Order total WITHOUT VAT: € ' : 'Totale ordine IVA ESCLUSA: € ') + result.total_ship);
						I('order_cart_total_iva').replaceChilds((en ? 'TOTAL TO PAY: € ' : 'TOTALE DA PAGARE: € ') + result.total_iva);
						I('order_cart_total_iva_msg').replaceChilds((en ? 'Including VAT' : 'Compreso IVA') + (result.pay_cost.toInt() > 0 ? (en ? ' and PayPal costs' : ' e addizionale PayPal') : ''));
					}
					else 
					{
						for(var i in result.specs)
						{
							var specPrice = result.specs[i],
								specLabel = $('#label_' + i + ' span span', true);
							
							if(specLabel)
							{
								specLabel.replaceChilds(': ' + specPrice + ' €');
							}
						}
						
						
						I('prod_order_total').replaceChilds((en ? 'ORDER TOTAL: € ' : 'TOTALE ORDINE: € ') + result.total);
					}
				}
			}
		});
	},
	initPageDetail: function()
	{
		if (I('detail_image_wrapper')) 
		{
			if ($('#detail_image_wrapper img').length > 1) 
			{
				Require.module('images-transitions', function()
				{
					var visualSize = I('detail_image_wrapper').sizes();
					
					var trans = new ImageTransitions(
					{
						width: visualSize[0],
						height: visualSize[1],
						target: 'detail_image_wrapper',
						transitions: [ImageTransitions.presets.openRight]
					});
					
					trans.nextImage();
					
					ImageTransitions.presets.openLeft.time = 0.5;
					ImageTransitions.presets.openRight.time = 0.5;
					
					I('detail_image_prev').addEvent('click', function()
					{
						trans.prevImage(ImageTransitions.presets.openLeft);
					});
					
					I('detail_image_next').addEvent('click', function()
					{
						trans.nextImage(ImageTransitions.presets.openRight);
					});
				});
			}
			else
			{
				I('detail_image_prev').hide();
				I('detail_image_next').hide();
			}
		}
	},
	initList: function()
	{
		$('div.list-item').each(function($div)
		{
			var $a = $('a', $div, true), href = $a.href;
			
			$div.addEvent('mouseover', function()
			{
				$div.addClass('active');
			}).addEvent('mouseout', function()
			{
				$div.removeClass('active');
			}).addEvent('click', function()
			{
				document.location = href;
			});
			
		});
	},
	initRightProductsList: function()
	{
		$('#get_them_now .product').each(function($div)
		{
			var $a = $('a', $div, true), href = $a.href;
			
			$div.addEvent('mouseover', function()
			{
				$div.addClass('active');
			}).addEvent('mouseout', function()
			{
				$div.removeClass('active');
			}).addEvent('click', function()
			{
				document.location = href;
			});
		});
	},
	initTopBar: function()
	{
		Require.module('form', function()
		{
			Form.labeledInput('tb_search_q', I('root').hasClass('en') ? 'want to search?' : 'vuoi effettuare una ricerca?');
		});
	},
	initSocialsLink: function()
	{

		
	}
};

Event.onReady(function()
{
	var en = I('root').hasClass('en');
	
	Pinkograf.en = en;
	
	
	(function($link)
	{
		var $text = $('strong', $link, true),
		$div = $('span', $link, true),
		$arrow = $('em', $link, true);
		
		$link.addEvent('mouseenter', function()
		{
			$text.morph({
				css: {
					left: ['px', ACTUAL, (en ? 76 : 60)]
				}
			});
			
			$div.morph({
				css: {
					left: ['px', ACTUAL, 49]
				}
			});
			
			$arrow.morph({
				css: {
					left: ['px', ACTUAL, 10]
				}
			});
			
		}).addEvent('mouseleave', function()
		{
			$text.morph({
				css: {
					left: ['px', ACTUAL, 10]
				}
			});
			
			$div.morph({
				css: {
					left: ['px', ACTUAL, 153]
				}
			});
			
			$arrow.morph({
				css: {
					left: ['px', ACTUAL, 160]
				}
			});
		});
		
		
	})(I('sample_link'));
	
	
	
	if(I('landing_top_wrapper'))
	{
		Pinkograf.initLanding();
	}
	
	if (I('products_list')) 
	{
		Pinkograf.initProductsList();
	}
	
	if(I('products_detail'))
	{
		Pinkograf.initProductDetail();
	}
	
	if(I('products_detail_specs'))
	{
		Pinkograf.initProductDetailSpecs();
	}
	
	if(I('order_module'))
	{
		Pinkograf.initOrder();
	}
	
	if(I('page_detail'))
	{
		Pinkograf.initPageDetail();
	}
	
	if(I('products_specs_detail'))
	{
		Pinkograf.initPageDetail();
	}
	
	if(I('lastminutes_box'))
	{
		Pinkograf.initLastminuteBox();
	}
	
	if(I('news_list') || I('clients_list') || I('lastminutes_list'))
	{
		Pinkograf.initList();
	}
	
	if(I('get_them_now'))
	{
		Pinkograf.initRightProductsList();
	}
	
	if(I('top_bar'))
	{
		Pinkograf.initTopBar();
	}
	
	if(I('login_box'))
	{
		Pinkograf.initLoginBox();
	}
	
	if(I('socials_link'))
	{
		Pinkograf.initSocialsLink();
	}

});

