
/* due javascript uniti font size in cartella principale e tabs in js/tabs come da suggerimenti page speed di google
---
script: tabs.js
description: MGFX.Tabs, extension of base class that adds tabs to control the rotater. 
authors: Sean McArthur (http://mcarthurgfx.com) 
license: MIT-style license 
requires:
 core/1.2.4: '*'
 more/1.2.4.1: [Fx.Elements]
provides: [MGFX.Tabs]
...
*/

//MGFX.Tabs. Copyright (c) 2008-2010 Sean McArthur <http://mcarthurgfx.com/>, MIT Style License.

var MGFX = MGFX || {};

MGFX.Tabs = new Class({
	
	Extends: MGFX.Rotater,
	
	options: {
		autoplay: false,
		onShowSlide: function(slideIndex) {
			this.tabs.removeClass('active');
			this.tabs[slideIndex].addClass('active');
		}
	},
	
	initialize: function(tabs, slides, options){
		this.setOptions(options);
		this.tabs = $$(tabs);
		this.createTabs();
		
		
		//salvo il nome
		this.mioLegaleName = tabs;
		//uso l'id
		var positionCookie = getCookie(tabs);
		if (positionCookie != null && positionCookie != ""){
			options.startIndex = positionCookie;
		}
		
		//commenta questi perché il prgrammatore mgfx prevedeva di usare il path noi usiamo i cookie per la persistent tab
		//if(options.hash && window.location.hash) {
		//	this.getHashIndex(options);
		//}
		
		//if(this.options.hash && window.location.hash) {
		//	var hash = window.location.hash.substring(1);
		//	this.tabs.each(function(el, index) {
		//		if(el.get('id') == hash) {
		//			options.startIndex = index;
		//		}
		//	});
		//}
		
		
		return this.parent(slides,options);
	},
	
	createTabs: function () {
		var that = this; 
		this.tabs.each(function(tab,index){
			tab.addEvent('click', function(event){ 
				event.preventDefault();
				
				
				//aggiungi questa riga
				setCookie(that.mioLegaleName,index);
				
				
				this.showSlide(index);
				this.stop(true);
			}.bind(this));
		}.bind(this));
	}.protect()
	
});

function setCookie(c_name,value,exdays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name) {
var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++) {
	  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
	  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
	  x=x.replace(/^\s+|\s+$/g,"");
	  if (x==c_name){
		return unescape(y);
	  }
	}
}

/////////////////////////////////////////
// la funzione che segue e stata spostata qui dal layout */
window.addEvent('domready',function(){
		this.tabs = new MGFX.Tabs('.c_tab','.c_feature',{
		autoplay: false,
		transitionDuration:400,
		lideInterval:3000,
		hover:true
	});
});



/**
 * JS from MioLegale
 */

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = '; expires='+date.toGMTString();
  }
  else expires = '';
  
  document.cookie = name+'='+value+expires+'; path=/';
  
  //var myCookie = Cookie.write('username', 'Harald');
}

function readCookie(name) {
	
	/* OLD
  var nameEQ = name + '=';
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
	 */
  
  var myCookie = Cookie.read(name);
  if (myCookie) {
	  setFontSize(myCookie);
  }
  return null;
}

function setFontSize(size) {
	
	var body = document.getElementsByTagName('body')[0];
	//var percentuale = "62,5%"; // default
	//TODO: Parametric
	if (size == 1) percentuale = "52%";
	if (size == 3) percentuale = "72%";
	//NEXT 85%
	if (size == 2){
		body.set('style','');
	}
	else {
		body.style.fontSize = percentuale;
	}
	createCookie('MLFontSize',size,365);
}

window.onload = function() {
	size = readCookie('MLFontSize');
}




