/**
 * IE 6 Warning Popup
 * 
 * @version		1.2-noOpacity
 * 
 * @license		MIT-style license
 * @author		Djamil Legato <djamil@djamil.it>
 * @copyright	Author
 */
 
 
var IEWarn = new Class({
	'site': 'sitename',
	'initialize': function() {
		var warning = "";
		warning += "<h3>ATTENZIONE</h3>\n";
		warning += "<p>Il browser che stai attualmente utilizzando &egrave; obsoleto.<br /><br />\n";
		warning += "Questo sito &egrave; stato studiato e realizzato per rendere la navigazione dell'utente il pi&ugrave; armoniosa e stimolante possibile, \n";
		warning += "pertanto sono stati utilizzati alcuni strumenti tecnologici aggiornati allo stato dell'arte che purtroppo il tuo browser non supporta.<br />\n";
		warning += "Microsoft ha rilasciato versioni pi&ugrave; aggiornate di Internet Explorer che, oltre a fornire una maggiore sicurezza nella navigazione, fanno rientrare il browser Internet Explorer tra i \"browser moderni\". \n";
		warning += "Per godere appieno dell'esperienza che questo sito ha da offrirti, ti suggeriamo di aggiornare il browser.<br /><br />\n";
		warning += "<br /><a href='http://www.microsoft.com/italy/windows/internet-explorer/default.aspx' target='_blank'>Scarica l'ultima versione di Internet Explorer.</a></p>";
		
		this.box = new Element('div', {'id': 'iewarn'}).inject(document.body, 'top');
		var div = new Element('div').inject(this.box).set('html', warning);
		
		var click = this.toggle.bind(this);
		var button = new Element('a', {'id': 'iewarn_close'}).addEvents({
			'mouseover': function() {
				this.addClass('cHover');
			},
			'mouseout': function() {
				this.removeClass('cHover');
			},
			'click': function() {
				click();	
			}
		}).inject(div, 'top');
		
		this.height = $('iewarn').getSize().y;
		
		this.fx = new Fx.Morph(this.box, {duration: 1000}).set({'margin-top': $('iewarn').getStyle('margin-top').toInt()});
		this.open = false;
		
		var cookie = Cookie.read('IEWarn'), height = this.height;
		//cookie = 'open'; // added for debug to not use the cookie value
		if (!cookie || cookie == "open") this.show();
		else this.fx.set({'margin-top': -height});

		
		return ;
	},
	
	'show': function() {
		this.fx.start({
			'margin-top': 0
		});
		this.open = true;
		Cookie.write('IEWarn', 'open', {duration: 7});
	},	
	'close': function() {
		var margin = this.height;
		this.fx.start({
			'margin-top': -margin
		});
		this.open = false;
		Cookie.write('IEWarn', 'close', {duration: 7});
	},	
	'status': function() {
		return this.open;
	},
	'toggle': function() {
		if (this.open) this.close();
		else this.show();
	}
});

window.addEvent('domready', function() {
	if (Browser.Engine.trident4) { (function() {var iewarn = new IEWarn();}).delay(2000); }
});