/*
 * By Mario Zambon (http://www.urbangap.com)
 * Copyright (c) 2008 cody urbangap
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/

function marchio() {
	
	// Funione transizioni
	function fx(el, tmp, type) {el.set(type, {duration: tmp, transition: Fx.Transitions.linear})}	

	$$('#news .imgLeftTh').set('styles', {'behavior': 'url(iepngfix.htc)'})

	// Effetti lingue
	var mnLang = $$('.mnLang a')
	fx(mnLang, 300, 'morph')
	if (mnLangActive=='it') {
		mnLang[0].addClass('active')
		//mnLang[0].addEvent('click', $lambda(false))
		mnLang[1].addEvents({
			'mouseover': 	function(){ this.morph('.mnLangIn')  },
			'mouseleave': 	function(){ this.morph('.mnLangOut') }
		})
	} 
	if (mnLangActive=='en') {
		mnLang[1].addClass('active')
		//mnLang[1].addEvent('click', $lambda(false))
		mnLang[0].addEvents({
			'mouseover': 	function(){ this.morph('.mnLangIn')  },
			'mouseleave': 	function(){ this.morph('.mnLangOut') }
		})
	}
	
	// Effetto "Scroll toElement"
	var mnFaq 	= $$('ul.faq a', 'a.su')
	mnFaq.addEvent('click', $lambda(false))
	mnFaq.addEvent('click', function(){
		var href 	= this.getProperty('href')
		var strHref = href.replace('#', '')
		var prova = $(strHref).getPosition()
		new Fx.Scroll(document.body, {duration: 1000, transition: Fx.Transitions.Expo.easeInOut}).toElement(strHref)
	})


	// Effetti menù Principale
	var mn = $$('#mn-it a', '#mn-en a')
	mn.removeProperty('title')
	mn.each(function(item, index){
		var i = index
		if (i==mnActive) {
			item.addClass('active')
			//item.addEvent('click', $lambda(false))
		} else {
			fx(item, 300, 'tween')
			item.addEvents({
				'mouseover': 	function(){ this.tween('opacity', 0.1) },
				'mouseleave': 	function(){ this.tween('opacity', 1) }
			})
		}
	})


	// Effetti pulsanti prodotti home page
	var mn = $$('#prodHome a')
	mn.removeProperty('title')
	mn.each(function(item, index){
		fx(item, 300, 'tween')
		item.addEvents({
			'mouseover': 	function(){ this.tween('opacity', 0.1) },
			'mouseleave': 	function(){ this.tween('opacity', 1) }
		})
	})

	// Effetti pulsanti form e alpha generico
	var form = $$('#sendMail .bt', '.alpha')
	fx(form, 300, 'tween')
	form.set('opacity', 0.5)
	form.addEvents({
		'mouseover': 	function(){ this.tween('opacity', 1) },
		'mouseleave': 	function(){ this.tween('opacity', 0.5) }
	})

	// Effetti menù Prodotti
	var mnProd = $$('.mnProd a', '#mnProd a')
	mnProd.removeProperty('title')
	mnProd.each(function(item, index){
		var i = index
		var css = item.hasClass('active')
		if (i==mnProdActive || css) {
			if (!css) item.addClass('active')
			//item.addEvent('click', $lambda(false))
		} else {
			fx(item, 150, 'morph')
			item.addEvents({
				'mouseover': 	function(){ this.morph('.mnProdIn')  },
				'mouseleave': 	function(){ this.morph('.mnProdOut') }
			})
		}
	})
	var subMnProd = $$('#mnProd .subMnProd a')
	subMnProd.removeProperty('title')
	subMnProd.each(function(item, index){
		var i = index
		var css = item.hasClass('active')
		if (css) {
			//item.addEvent('click', $lambda(false))
		} else {
			fx(item, 150, 'morph')
			item.addEvents({
				'mouseover': 	function(){ this.morph('.mnProdInSub')  },
				'mouseleave': 	function(){ this.morph('.mnProdOutSub') }
			})
		}
	})


	// Effetti link generici
	var lnk = $$('a.lnk', '.lnk a')
	lnk.removeProperty('title')
	lnk.each(function(item, index){
		fx(item, 200, 'morph')
		item.addEvents({
			'mouseover': 	function(){ this.morph('.lnkIn')  },
			'mouseleave': 	function(){ this.morph('.lnkOut') }
		})
	})

	
	// Effetti link news
	var lnkNews = $$('a.lnkNews', '.lnkNews a')
	lnkNews.removeProperty('title')
	lnkNews.each(function(item, index){
		fx(item, 200, 'morph')
		item.addEvents({
			'mouseover': 	function(){ this.morph('.lnkIn')  },
			'mouseleave': 	function(){ this.morph('.lnkOutNews') }
		})
	})

	
	// Maschera immagini Statiche
	var imgLeft = $('mask')
	if (imgLeft) {
		var mask = new Element('img', {'class': 'imgMask', 'src': 'i/t/maskImage.png'}).inject(imgLeft)
		mask.set('styles', {
			'behavior': 'url(iepngfix.htc)'
		})
	}

	// Maschera immagini Thumb Statiche




	var news = $$('#news span.mouse')
	news.each(function(item, index){
					  
		var imgLeftTh = $('maskTh'+index)
		if (imgLeftTh) {
			imgLeftTh.set('styles', {
				'width': '146px',
				'height': '108px',
				'margin-right': '10px',
				'margin-bottom': '2px',
				'float': 'left'
			})
		}
	})


	var maskProd = $$('.maskProd')
	maskProd.getElement('img').setStyle('behavior', 'url(iepngfix.htc)')
	maskProd.each(function(item, index){
		fx(item, 200, 'morph')
		fx(item, 200, 'tween')
		item.addEvents({
			'mouseover': function(){ 
				var tthis = this.getElement('span')
				//var tthisMask = this.getElement('img').tween('opacity', 1)
				tthis.set('styles', {
					'color': '#000000',
					'background-position': '8px 3px'
				})
			},
			'mouseleave': function(){
				var tthis = this.getElement('span')
				//var tthisMask = this.getElement('img').tween('opacity', 0.6)
				tthis.set('styles', {
					'color': '#666666',
					'background-position': '6px 3px'
				})
			}
		})
	})
	
	
	

	var linkProd = $$('.maskProd .name')
	fx(linkProd, 300, 'tween')
	linkProd.addEvents({
		'mouseover': 	function(){ this.morph('.linkProdIn')  },
		'mouseleave': 	function(){ this.morph('.linkProdOut') }
	})
	
	
	
	var boxNews = $$('#newsHome .boxNews')
	fx(boxNews, 280, 'morph')
	boxNews.addEvents({
		'mouseover': function(){
			this.set('style', 'cursor: pointer')
			this.getElement('a').morph('.lnkIn')
			//this.morph('.lnkIn')
		},
		'mouseleave': function(){
			this.getElement('a').morph('.lnkOut')
			//this.morph('.lnkOut')
		},
		'click': function(){
			var tagA = this.getElement('a')
			var lnk = tagA.getProperty('href')
			window.location=lnk
		}
	})
	

}
window.addEvent('domready', marchio)
