/*
 * mootools 1.2
 * 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 rima() {
	
	// Funione transizioni	
	var tran = Fx.Transitions.linear
	function fx(el, tmp, type, tran) {el.set(type, {duration: tmp, transition: tran})}	


	// Effetti menu Principale	
	var mn = $$('#tool .mn 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(mn, 180, 'tween', tran)
			item.addEvents({
				'mouseover': 	function(){ this.tween('opacity', 0.1)},
				'mouseleave': 	function(){ this.tween('opacity', 1) }
			})
		}
	})
	

	//Loader image toolbar
	var boxSx = $('imgSx')
	var boxMd = $('imgMd')
	var boxDx = $('imgDx')
	var boxMdClick = $('imgMdClick')
	var loader = $$('#tool .boxImg')
	
	var t1 = 600
	var t2 = 1300
	
	//window.onload=function(){
		preload()
	//}

	function preload() {
		new Asset.images([imgSx, imgMd, imgDx], {
			onComplete: function(){
				loader.setStyle('background-image', 'none')
				loadImgSx.delay(1200)
				loadImgMd.delay(800)
				loadImgRx.delay(400)
			}
		});
	}
	function loadImgSx() {
		var a = new Element('a', {'id': 'boxSxA', 'href': hrefSx}).set('opacity', 0).inject(boxSx)		
		var img = new Element('img', {'src': imgSx, 'alt':'', 'styles': {'behavior': 'url(iepngfix.htc)'}}).inject('boxSxA')
		fxMorph(a, img, t2, 120, 174, 120, 174)
		//fxMorph(a, img, t2, 183, 183, 183, 183)
	}
	function loadImgMd() {
		var a = new Element('a', {'id': 'boxSxB', 'href': hrefMd}).set('opacity', 0).inject(boxMd)
		var img = new Element('img', {'src': imgMd, 'alt':'', 'styles': {'behavior': 'url(iepngfix.htc)'}}).inject('boxSxB')		
		fxMorph(a, img, t2, 280, 303, 680, 709)
		//fxMorph(a, img, 1500, 321, 321, 729, 729)
		
		new Element('a', {'href': hrefMd}).inject(boxMdClick)
	}
	function loadImgRx() {
		var a = new Element('a', {'id': 'boxSxC', 'href': hrefDx}).set('opacity', 0).inject(boxDx)		
		var img = new Element('img', {'src': imgDx, 'alt':'', 'styles': {'behavior': 'url(iepngfix.htc)'}}).inject('boxSxC')		
		fxMorph(a, img, t2, 200, 237, 190, 237)
		//fxMorph(a, img, t2, 263, 263, 256, 256)
	}
	function fxMorph(a, el, tmp, xh, yh, xw, yw) {
		var tran = Fx.Transitions.linear
		fx(a, t1, 'tween', tran)
		a.tween('opacity', 1)
		var tran = Fx.Transitions.Elastic.easeOut
		var fxMorph = new Fx.Morph(el, {duration: tmp, transition: tran});
		fxMorph.start({
			'height': [xh, yh],
			'width': [xw, yw]
		});
	}
	
	
	//thumb news
	function mask(id) {
		var imgHome = $(id)
		var imgSrc = imgHome.getElement('img').getProperty('src')
		imgHome.getElement('img').dispose()
		var mask = new Element('img', {'src':'i/t/maskNewsHome.gif', 'styles': {'background': 'url('+imgSrc+') center right no-repeat'}}).inject(imgHome)
	}
	//imgHome.dispose()
	//new Element('img', {'src':'i/t/maskNewsHome.gif', 'styles': {'background': 'url('+imgSrc+') center right'}}).inject(imgHome)
	//if(newsHome) mask('imgNews1')
	//if(newsHome) mask('imgNews2')
	
	
	// Effetti link generico	
	var lnk = $$('a.lnk', '.lnk a')
	lnk.each(function(item, index){
		lnk.set('opacity', 1)
		fx(lnk, 180, 'tween', tran)
		item.addEvents({
			'mouseover': 	function(){ this.tween('opacity', 0.75)},
			'mouseleave': 	function(){ this.tween('opacity', 1) }
		})
	})


    // rollover e link slider home page
    var div = $$('.sliderHome .boxTh')
	fx(div, 180, 'tween', tran)
	var opc = 0.46
	div.addEvents({
		'mouseover': function(){
			div.tween('opacity', opc)
			this.tween('opacity', 1)
		},
		'mouseleave': function(){
			div.tween('opacity', 1)
			this.tween('opacity', 1)
		},
		'click': function(){
			var tagA = this.getElement('a')
			var lnk = tagA.getProperty('href')
			window.location=lnk
			//window.open(lnk)
		}
	})

    // rollover e link slider home page
    var boxNews = $$('.boxNewsHome', '.newsAbstract')
	fx(boxNews, 180, 'tween', tran)
	boxNews.addEvents({
		'mouseover': function(){
			this.tween('opacity', 0.75)
		},
		'mouseleave': function(){
			this.tween('opacity', 1)
		},
		'click': function(){
			var tagA = this.getElement('a')
			var lnk = tagA.getProperty('href')
			window.location=lnk
			//window.open(lnk)
		}
	})

	//target blank
	var lnk = $$('a.blank')
	//var txt = ''
	lnk.addEvent('click', $lambda(false))
	lnk.each(function(item, index){
		//var title = item.getProperty('title')
		//item.setProperty('title', title+' '+txt)
		item.addEvent('click', function(event){
			window.open(this)
		})
	})
	
}
window.addEvent('domready', rima)


