var testi = Array();
testi['moquettes']     = "La nostra Azienda può elaborare qualsiasi progetto per pavimentazione tessile.<br />";
testi['moquettes']    +=  "Forniamo moquette con disegni, colori e dimensioni su richiesta del Cliente, compreso lo studio e la progettazione sulle dimensioni degli ambienti.";
testi['poltrone']      = "Produciamo poltrone e i divani con qualsiasi tipo di rivestimento. Possiamo produrre anche modelli su vostro disegno corredandole della certificazione 1 IM, secondo la normativa vigente."
testi['scarting']      = "Cieffe Arredi – Il fascino del tavolo vestito";
testi['divaniletto']   = "Cieffe Arredi – La comodità del letto supplementare";
testi['testataletto']  = "Produciamo vari modelli di serie. Inoltre realizziamo modelli e misure su progetto del cliente.";
testi['tendaggi']	   = "Siamo in grado di fornire tendaggi confezionati nelle diverse fogge richieste dagli ambienti.<br />L’importanza del tessuto d’arredo è indiscutibile; infatti gli ambienti possono essere cambiati radicalmente solo sostituendo i tessuti.<br />Possiamo riprodurre su tessuto ignifugo qualsiasi disegno o colore su Vostro progetto.";
testi['sale'] 	       = 'Eleganza, praticità e tecnica per le sale convegni';
testi['azienda'] 	   = "Cieffe Arredi, specializzata in arredi per Hotel, navi, uffici e comunità, opera nel settore arredo tessile, con esperienza di oltre 60 anni di attività, avendo eseguito lavori in tutto il mondo. Cieffe Arredi dispone di personale qualificato in grado di produrre e confezionare tessuti, poltrone, moquettes, colori e misure su disegno del Cliente, con eventuale posa in opera.<br />";
testi['azienda'] 	  += "Tutti i nostri prodotti sono certificati secondo le attuali normative antincendio.";

$(document).ready(function(){
	$('#loading').ajaxStart(function(){
		$(this).fadeIn();
	}).ajaxStop(function(){
		$(this).fadeOut();
	});
	ajax('home');
});

function gallery(dir, mode){
	$.getJSON('action/file.php', {'dir': dir}, function(data){
		// Imposto descrizione
		var html = testi[mode];

		$('#text').empty().fadeIn(1000).html(html);
		
		// Creo gli elementi HTML necessari
		$('#body').empty();
		var gallery_div = $('<div></div>')
			.attr('id', 'gallery');
		$('#body').append(gallery_div);
		$('#gallery').empty();
		var option_div = $('<div></div>')
			.attr('id', 'gallery-option');
		option_div.append($('<a></a>')
			.attr('href', 'javascript:increase_size();')
			.attr('title', 'Aumenta dimensioni foto')
			.text('+'));
		option_div.append($('<a></a>')
			.attr('href', 'javascript:decrease_size();')
			.attr('title', 'Diminuisci la dimensione delle foto')
			.text('-'));
		$('#body').append(option_div);
		
		var images_dir = 'images/';
		
		$.each(data, function(i, obj){
			
			var href = images_dir+dir+obj.link;
			var src = images_dir+dir+'thumbs/'+obj.link;
			if(mode=='poltrone') {
				var title = 'Codice foto: '+obj.link;
			} else {
				var title = 'Codice foto: '+parseInt(i+1);
			}
			var altTitle = 'Codice foto: '+parseInt(i+1);
			
			var a = $('<a></a>')
				.attr('href', href)
				.attr('title', title)
				.attr('id', i)
				.css('display','inline');
			var img = $('<img/>')
				.attr('src', src)
				.attr('alt', altTitle)
				.attr('rel','gallery')
				.css({
					'width':'227px',
					'height':'150px'
				});
			// Azienda
			if(mode=='azienda' && i==5) {
				img.css({
					'width':'458px',
					'height':'150px'
				});
			}
			if(mode=='azienda' && (i==4 || i==7 || i==11)) {
				$('#gallery').append('<br />').append(a.append(img));
			} else if(mode=='divaniletto' && (i==2 || i==4 || i==6)) {
				$('#gallery').append('<br />').append(a.append(img));
			} else {
				$('#gallery').append(a.append(img));
			}
			//$('#'+i).fadeIn();			
		});
		//$('#gallery').fadeIn();
		$('#gallery a').fancybox({path:'images/zoom/'});
	});
}
/*---------------------------------------*/
/* GALLERY								 */
function increase_size() {
	var increase = 1.2;
	var size = get_size();
	width = size.width * increase;
	height = size.height * increase;
	change_size(width, height);
}
function decrease_size() {
	var increase = .8;
	var size = get_size();
	width = size.width * increase;
	height = size.height * increase;
	change_size(width, height);
}
function get_size() {
	var width  = $('#gallery  img:first').css('width');
	var height = $('#gallery img:first').css('height')
	
	width = parseInt(width.substring(0, width.length-2));
	height = parseInt(height.substring(0, height.length-2));
	return {'width':width, 'height': height};
}

function change_size(width, height) {
	width = width+'px';
	height = height+'px';
	$('#gallery img').each(function(i, e){
		$(e).css({
			'width':width,
			'height':height
		}, 300);
	});
}
