var About = function(idAbout){
	
	var arrFooters, 
		arrContent,
		indexArrFooter, //Quale dei tre banner del footer andremo a selezionare
		indexPagFooter, //Indice di quale set di footer sto usando PAG
		html,
		footerHtml,
		idWork = idAbout,
		me = this;

	this.init = function( footers, contents ){
			arrFooters = footers;
			arrContent = contents;
			indexPagFooter = 1;
			indexArrFooter = 1;
			html = '';

			if( $.address.baseURL().match('/ita/') )
			{
			
			}
			else if( $.address.baseURL().match('/en/') )
			{
					
			}
			else
			{
				var old = $.address.value();
				old = old.split('/');
				$.address.value(old[1]+'/'+'about'+'/'+arrFooters[indexPagFooter].name);				
			}			
	},

	this.generateFooterHtml = function(){		

		if( isInt(idWork) ){
			toLoad = idWork;
		} else {
			toLoad = indexArrFooter;
		}	

		var x = $('.foot-wrap').css('margin-left');
		var y = $('.foot-wrap').css('height');
		var k = $('.foot-wrap').css('bottom');
		footerHtml = '<div class="foot-wrap" style="margin-left:'+x+'; margin-right:'+x+'; height:'+y+'; bottom: '+k+';">';		
			footerHtml += '<div class="footer_about">'+arrFooters[toLoad]['text']+'</div>';
		footerHtml += '</div>';
	},

	this.changeContent = function(a, b){
			if(b){
				var id = b;
				var c = '#CA135A';
			} else {
				var id = a.attr('alt');	
				var c = a.css('color');
			}			

			var old = $.address.value();
			old = old.split('/');
			if( $.address.baseURL().match('/ita/') )
			{
				$.address.value('ita/'+'about'+'/'+arrFooters[id].name);			
			}
			else if( $.address.baseURL().match('/en/') )
			{
				$.address.value('en/'+'about'+'/'+arrFooters[id].name);				
			}
			else
			{
				$.address.value(old[1]+'/'+'about'+'/'+arrFooters[id].name);				
			}	

			this.changeWithFade(id, c);
	},

	this.setFooterPagination = function(data){
			indexPagFooter = data;
			this.generateFooterHtml();
	},

	this.changeWithFade = function(id, color){	
		$('.footer_about').fadeOut(function(){
			$(this).css('color', color);
			$(this).html(arrFooters[id]['text']).fadeIn();
		});
	},

	this.generateContentHtml = function(){
		
		var toLoad;
		
		//Per id, quindi durante la generazione dei loghi si dovrà predisporre il passaggio degli ID
	

		html = '<div id="about">';
			for(var i= 0 in arrContent){
				html += ''+arrContent[i]+'';
			}
		html += '</div>';
		

	},

	this.generateArrayFromJson = function(data){ //Handle ajax json responce 

			var footers = new Array();
			var content = new Array();
			
			$.each(data.content, function(key, value) { 			
				content[key] = value;
			});

			$.each(data.footer, function(key, value) { 			
				
				footers[key] = new Array();

				$.each(value, function(k, v) {
					footers[key][k] = v;
				});

			});			

			// $.each(data.footer, function(key, value) { 			
			// 	footers[key] = value;
			// });									
			
			this.init(footers, content);		
			this.generateContentHtml();
			this.generateFooterHtml();
	},	


	this.getContentHtml = function(){
		return html;	
	},

	this.getFooterHtml = function(){
		return footerHtml;	
	},

	this.getArrFooter = function(){
		return arrFooters;
	},

	this.getJavascript = function(){	    
		var isColor = true;
		var oneColor = false;
		

		$('.about').live('mouseenter', function(){
			if(!oneColor){
				var me = $(this).attr('src');

				$('.about').each(function(){
					if($(this).attr('src') != me && !$(this).attr('src').match('_grey') ){
						var color = $(this).attr('src').replace('.png', '_grey.png');		
						$(this).attr('src', color);																		
					}
				});
				oneColor = true;
				return;
			}

			if(oneColor){
				var me = $(this).attr('src');

				$('.about').each(function(){
					if(!$(this).attr('src').match('_grey')){
						var color = $(this).attr('src').replace('.png', '_grey.png');		
						$(this).attr('src', color);																		
					}															
				});
				
				$(this).attr('src', me.replace('_grey', ''));

				oneColor = true;				
				return;
			}
			return;
		});		

		$('.about').live('mouseout', function(){	
			var src = $(this).attr('src');
			if(isColor && !src.match('_grey')){
				var color = src.replace('.png', '_grey.png');					
				$(this).attr('src', color);				
				isColor = false;	
			}


			$('.about').each(function(){
				if($(this).attr('src').match('_grey')){
					var color = $(this).attr('src').replace('_grey', '');		
					$(this).attr('src', color);																		
				}															
			});			
			return

		});

		// $('.about').live('mouseout', function(){	
		// 	var src = $(this).attr('src');
		// 	if(isColor && !src.match('_grey')){
		// 		var color = src.replace('.png', '_grey.png');					
		// 		$(this).attr('src', color);				
		// 		isColor = false;	
		// 	}
		// 	return

		// });

		$('.about').live('click', function(){
			me.changeContent( $(this) );
		});

	},

	this.getArrContent = function(){
		return arrContent;
	}	

}
