
var Madara = new Class({
	
	
	
	initialize: function() {
		window.addEvent('domready', this.onDOMReady.bindWithEvent(this));
		window.addEvent('load', this.onLoad.bindWithEvent(this));
		this.sIFR_init();
	},
	
	onDOMReady: function() {
		
		if(window.SqueezeBox) {
			SqueezeBox.initialize({
		        size: {x: 510, y: 350},
				overlayOpacity: 0.8
		    });
		}
	
		$$('a.INCI').set('href', '#INCI').set('rel', 'boxed');
		if(window.SqueezeBox) {
		    SqueezeBox.assign($$('a.INCI'), { onOpen: this.sIFR_initSBox.bind(this) });		// INCI
			SqueezeBox.assign($$('a.template-27'), {	// Skin test
				handler: 'iframe',
				size: {x: 650, y: 400 }
			});
			SqueezeBox.assign($$('a.popupImage'), {
				handler: 'image'
			});
		}
		
		
		// the landing page
		if($('landingContainer')) {
			$$('li.country').each(function(item) {
				languageSpans = item.getElements('span.lng');
				languageSpanFx = new Fx.Elements(languageSpans, {
					duration: 'short',
					link: 'cancel',
					transition: Fx.Transitions.Quad.easeOut
				});
				
				onValues = new Hash();
				offValues = new Hash();
				languageSpans.each(function(item, idx) {
					onValues.set(idx, { 'opacity': 1 });
					offValues.set(idx, { 'opacity': 0.5 });
				});
				
				item.store('fx', languageSpanFx);
				item.store('fx_on', onValues);
				item.store('fx_off', offValues);
				
				item.addEvent('mouseenter', function() {
					var fx = this.retrieve('fx');
					var to = this.retrieve('fx_on').getClean();
					//console.debug(this, fx, this.retrieve('fx_on'));
					fx.start(to);
				}.bind(item));
				item.addEvent('mouseleave', function() {
					var fx = this.retrieve('fx');
					var to = this.retrieve('fx_off').getClean();
					fx.start(to);
				}.bind(item));
			});
			
			
		}
		
		this.commentsForm_init();
		this.blogCommentsForm_init();
		this.subscribeForm_init();
		this.visitingForm_init();
		
		if(window.UvumiDropdown) {
			this.menu_init();
			this.langMenu_init();
		}
		
		this.facebook_init();
		
		this.news_init();
		this.whereToBuy_init();
		
	},
	
	
	onLoad: function() {
		this.refreshFooterPosition();
	},
	
	
	
	
	
	
	menu_init: function() {
		new UvumiDropdown('headerMenu', { delay:100, duration: 150, transition: Fx.Transitions.easeOutQuint });
	},
	
	langMenu_init: function() {
		//if($('languagesMenu'))
		//	new UvumiDropdown('languagesMenu', { delay:100, duration: 150, transition: Fx.Transitions.easeOutQuint/*, /*clickToOpen: true*//*, position: 'top'*/ });
	},
	
	
	
	news_init: function() {
		var newsBodies = $$('.newsBody-More');
		if(newsBodies && newsBodies.length >= 1) {
			newsBodies.forEach(function(nBody) {
				var intro = nBody.getPrevious();
				if(intro.hasClass('newsBody-Intro')) {
					introLastBlock = intro.getLast('p')
					if(introLastBlock.get('tag') == 'p') {
						var plusElement = new Element('A', { 'href': '#', 'class': 'newsReadMore' }).set('html', '&nbsp;&nbsp;&nbsp;');
						plusElement.inject(introLastBlock, 'bottom');
						intro.addEvent('mouseover',	this.news_onIntroOver.bindWithEvent(this));
						intro.addEvent('mouseover',	this.news_onIntroOut.bindWithEvent(this));
						intro.addEvent('click', 	this.news_onIntroClick.bindWithEvent(this));
						intro.addClass('newsBody-Intro-clickable');
					} else {
						//plusElement.inject(introLastBlock, 'after');
						nBody.setStyle('display', 'block');	// can't handle anything but P
					}
				}
				
			}, this);
			
		}
	},
	news_onIntroOver: function(event) {
		
	},
	news_onIntroOut: function(event) {
		
	},
	news_onIntroClick: function(event) {
		//event.stop(); // don't stop the event, as the user might have clicked on a link
		var target = $(event.target);
		if(target.hasClass('newsReadMore')) event.stop();
		if(!target.hasClass('newsBody-Intro')) target = target.getParent('.newsBody-Intro');
		if(!target.get('opened')) {
			target.removeClass('newsBody-Intro-clickable');
			target.getElement('a.newsReadMore').fade('show').fade('out');
			target.set('opened', true);
			this.news_openBody(target.getNext());
		}
	},
	news_openBody: function(body) {
		body.set('slide', {
			duration: 800, 
			'link':'cancel', 
			transition: Fx.Transitions.Quint.easeInOut
		}); //.get('slide').removeEvents('complete');
		body.setStyle('display', 'block').slide('hide').slide('in');
		
		// refresh footer position for IE
		this.refreshFooterPosition();
	},
	
	refreshFooterPosition: function() {
		/*var footerContainer = $('footerContainer');
		if(footerContainer) {
			$('footerContainer').setStyle('display', 'none');
			$('footerContainer').setStyle.delay(800, $('footerContainer'), ['display', 'block']);
		}*/
	},
	
	
	commentsForm_init: function() {		// add click event to submit link and insert a hidden CMD field
		if($('commentsFormContainer') && $('commentsFormContainer').getElement('form')) {
			$('commentsFormContainer').getElement('a.specialLinkWithArrow').addEvent('click', this.commentsForm_submit.bindWithEvent(this));
			new Element('input', { 'type': 'hidden', 'name': 'comments_cmd', 'value': 'post' }).inject($('commentsFormContainer').getElement('form'));
		}
	},
	commentsForm_submit: function(event) { 
		event = new Event(event);
		event.preventDefault();
		$('commentsFormContainer').getElement('form').submit(); 
	},
	
	blogCommentsForm_init: function() {		// add click event to submit link and insert a hidden CMD field
		if($('blogCommentsFormContainer') && $('blogCommentsFormContainer').getElement('form')) {
			$('blogCommentsFormContainer').getElement('a.specialLinkWithArrow').addEvent('click', this.blogCommentsForm_submit.bindWithEvent(this));
			new Element('input', { 'type': 'hidden', 'name': 'blogcomments_cmd', 'value': 'post' }).inject($('blogCommentsFormContainer').getElement('form'));
		}
	},
	blogCommentsForm_submit: function(event) { 
		event = new Event(event);
		event.preventDefault();
		$('blogCommentsFormContainer').getElement('form').submit(); 
	},
	
	
	subscribeForm_init: function() {	// add click event to submit link and insert a hidden CMD field
		if($('subscribeFormContainer') && $('subscribeFormContainer').getElement('form')) {
			$('subscribeFormContainer').getElement('a.specialLinkWithArrow').addEvent('click', this.subscribeForm_submit.bindWithEvent(this));
			new Element('input', { 'type': 'hidden', 'name': 'subscribe_cmd', 'value': 'post' }).inject($('subscribeFormContainer').getElement('form'));
		}
	},
	subscribeForm_submit: function(event) { 
		event = new Event(event);
		event.preventDefault();
		$('subscribeFormContainer').getElement('form').submit(); 
	},
	
	
	
	visitingForm_init: function() {	// add click event to submit link and insert a hidden CMD field
		if($('visitingFormContainer') && $('visitingFormContainer').getElement('form')) {
			$('visitingFormContainer').getElement('a.specialLinkWithArrow').addEvent('click', this.visitingForm_submit.bindWithEvent(this));
			new Element('input', { 'type': 'hidden', 'name': 'visiting_cmd', 'value': 'post' }).inject($('visitingFormContainer').getElement('form'));
		}
	},
	visitingForm_submit: function(event) { 
		event = new Event(event);
		event.preventDefault();
		$('visitingFormContainer').getElement('form').submit(); 
	},
	
	
	
	whereToBuy_init: function() {
		if($('countrySelect')) {
			$('countrySelect').addEvent('change', function(event) {
				event = new Event(event);
				window.location = $(event.target).get('value');
			});
			
			if($('regionSelect')) {
				$('regionSelect').addEvent('change', function(event) {
					event = new Event(event);
					window.location = $(event.target).get('value');
				});
			}
			
			if($('typeSelect')) {
				$('typeSelect').addEvent('change', function(event) {
					event = new Event(event);
					window.location = $(event.target).get('value');
				});
			}
		}

	},
	
	
	facebook_init: function() {
		$$('a.facebook-share').addEvent('click', this.facebook_onShareClick.bindWithEvent(this));
		
	},
	facebook_onShareClick: function(event) {
		event.stop();
		u = location.href;
		t = document.title;
		window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;
	},
	
	
	sIFR_init: function() {
		
		sIFR.useStyleCheck = true;
		//sIFR.useDomLoaded = true;
		
		var fontScript = window.FONT_SCRIPT ? window.FONT_SCRIPT : 'western';
		
		this.Serifa = { src: '/_content/sifr/fonts/serifa-' + fontScript + '.swf' };
		sIFR.activate(this.Serifa);
		
		
		// landing page
		/*sIFR.replace(this.Serifa, {
			selector: '#landingContainer h2',
			css: '.sIFR-root { color: #819814; }'
		});*/
		sIFR.replace(this.Serifa, {
			selector: '#landingContainer ul.countries li span.continent',
			css: '.sIFR-root { color: #819814; }',
			wmode: 'transparent'
		});
		
		
		

		// heading 1
		sIFR.replace(this.Serifa, {
			selector: '#mainContainer h1 span',
			css: [
				'.sIFR-root { color: #373A3B; leading: -7; }',
				'em { font-style: normal; color: #819814; }'
			],
			wmode: 'transparent',
			ratios: [8, 1.41, 11, 1.31, 15, 1.29, 25, 1.25, 33, 1.23, 43, 1.22, 65, 1.21, 66, 1.2, 70, 1.21, 74, 1.2, 75, 1.21, 1.2]
		});

		// heading 1 - sub
		sIFR.replace(this.Serifa, {
			selector: '#mainContainer h1 small',
			css: '.sIFR-root { color: #667966; }',
			wmode: 'transparent',
			ratios: [8, 1.41, 11, 1.31, 15, 1.29, 25, 1.25, 33, 1.23, 43, 1.22, 65, 1.21, 66, 1.2, 70, 1.21, 74, 1.2, 75, 1.21, 1.2]
		});
		//sIFR.debug.ratios({ src: '/_content/sifr/fonts/serifa-' + fontScript + '.swf', selector: '#mainContainer h1 small' });

		// heading 2
		sIFR.replace(this.Serifa, {
			selector: '#mainContainer h2',
			css: '.sIFR-root { color: #819814; }',
			wmode: 'transparent',
			ratios: [8, 1.41, 11, 1.31, 15, 1.29, 25, 1.25, 33, 1.23, 43, 1.22, 65, 1.21, 66, 1.2, 70, 1.21, 74, 1.2, 75, 1.21, 1.2]
		});
		//sIFR.debug.ratios({ src: '/_content/sifr/fonts/serifa-' + fontScript + '.swf', selector: '#mainContainer h2' });
	
		// heading 3
		sIFR.replace(this.Serifa, {
			selector: '#mainContainer h3 span',
			css: '.sIFR-root { color: #819814; }',
			wmode: 'transparent',
			ratios: [8, 1.41, 11, 1.31, 15, 1.29, 25, 1.25, 33, 1.23, 43, 1.22, 65, 1.21, 66, 1.2, 70, 1.21, 74, 1.2, 75, 1.21, 1.2]
		});
		//sIFR.debug.ratios({ src: '/_content/sifr/fonts/serifa-' + fontScript + '.swf', selector: '#mainContainer h3 span' });
		
		// heading 5
		sIFR.replace(this.Serifa, {
			selector: '#mainContainer .product h5',
			css: [
				'.sIFR-root { color: #373A3B; }',
				'a { color: #373A3B; text-decoration: none; }',
				'a:hover { color: #373A3B; text-decoration: none; }'
			],
			wmode: 'transparent',
			ratios: [8, 1.41, 11, 1.31, 15, 1.29, 25, 1.25, 33, 1.23, 43, 1.22, 65, 1.21, 66, 1.2, 70, 1.21, 74, 1.2, 75, 1.21, 1.2]
		});
		//sIFR.debug.ratios({ src: '/_content/sifr/fonts/serifa-' + fontScript + '.swf', selector: '#mainContainer .product h5' });
	},
	
	sIFR_initSBox: function() {
		//sIFR.redraw();
		//setTimeout(this.sIFR_initSBoxDo, 2000);
	},
	
	sIFR_initSBoxDo: function() {
		/*sIFR.redraw();
		sIFR.replace(this.Serifa, {
			selector: 'h1.INCI span',
			css: [
				'.sIFR-root { color: #373A3B; leading: -7; }',
				'em { font-style: normal; color: #819814; }'
			],
			wmode: 'transparent'
		});*/
	}
	
	
	
	
});


var madara = new Madara();






















/**
 * This script contains embed functions for common plugins. This scripts are complety free to use for any purpose.
 */

function writeFlash(p) {
	writeEmbed(
		'D27CDB6E-AE6D-11cf-96B8-444553540000',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'application/x-shockwave-flash',
		p
	);
}

function writeShockWave(p) {
	writeEmbed(
	'166B1BCA-3F9C-11CF-8075-444553540000',
	'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0',
	'application/x-director',
		p
	);
}

function writeQuickTime(p) {
	writeEmbed(
		'02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
		'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
		'video/quicktime',
		p
	);
}

function writeRealMedia(p) {
	writeEmbed(
		'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'audio/x-pn-realaudio-plugin',
		p
	);
}

function writeWindowsMedia(p) {
	p.url = p.src;
	writeEmbed(
		'6BF52A52-394A-11D3-B153-00C04F79FAA6',
		'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
		'application/x-mplayer2',
		p
	);
}

function writeEmbed(cls, cb, mt, p) {
	var h = '', n;

	h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
	h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
	h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
	h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
	h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
	h += typeof(p.align) != "undefined" ? 'align="' + p.align + '"' : '';
	h += '>';

	for (n in p)
		h += '<param name="' + n + '" value="' + p[n] + '">';

	h += '<embed type="' + mt + '"';

	for (n in p)
		h += n + '="' + p[n] + '" ';

	h += '></embed></object>';

	document.write(h);
}





