/*
 * cerea banca 1.0
 * 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 cerea() {	
	
	// Funione transizioni
	function fx(el, tmp, type) {el.set(type, {duration: tmp, transition: Fx.Transitions.linear})}	


	// Slideshow
		var slide 	= $('slide')
		//var alt 	= ['L\'agricoltura','L\'ambiente','La cultura','L\'impresa']
		var i 		= 0			//start image
		var t1 		= 1000		//time fadein
		var t2 		= 6000		//time image
		
		if(slide) href.each(function(item, index){iAll = index})
		if (slideShow) loadimage()
	
		function loadimage() {
			new Asset.image(href[i], {onload: transition})
		}
		
		function transition() {
			//var img = new Element('img', {'src': href[i], 'alt': alt[i]}).set('opacity', 0).inject(slide)
			var img = new Element('img', {'src': href[i]}).set('opacity', 0).inject(slide)
			fx(img, t1, 'tween')		
			img.tween('opacity', 0 , 1)
			if(i<iAll) {i++} else {i=0}
			deleteimage.delay(t1+t2+100)
			ddelay()
		}
		
		function ddelay() {
			loadimage.delay(t2)
		}
		
		function deleteimage() {
			var primo = slide.getFirst()
			primo.destroy()
		}

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

	// Effetti rollover switch immagine
	/*var swc = $$('.btOnline a', '.btPDF a')
	swc.removeProperty('title')
	swc.each(function(item, index){
		fx(item, 250, 'tween')
		item.addEvents({
			'mouseover': 	function(){ this.tween('opacity', 0) },
			'mouseleave': 	function(){ this.tween('opacity', 1) }
		})
	})*/
	
	// Effetti rollover switch immagine
	var btLog = $$('.btLog')
	btLog.each(function(item, index){
		fx(item, 250, 'tween')
		item.addEvents({
			'mouseover': 	function(){ 
				var span = this.getElement('span.img')
				span.tween('opacity', 0.1) },
			'mouseleave': 	function(){ 
				var span = this.getElement('span.img')				
				span.tween('opacity', 1) }
		})
	})	

	// Effetti menu di secondo livello
	var mnII = $$('#mnII a')
	mnII.removeProperty('title')
	mnII.each(function(item, index){
		var i = index
		if (i==mnActiveII) {
			item.addClass('active')
			//item.addEvent('click', $lambda(false))
		}
		else if (item.hasClass('active')) {
			//item.addEvent('click', $lambda(false))
		} 
		else {
			fx(item, 200, 'morph')
			item.addEvents({
				'mouseover': 	function(){ this.morph('.mnIIover') },
				'mouseleave': 	function(){ this.morph('.mnIIout') }
			})
		}
	})
	

	// Rollover link testuali icone home page
	function icoRollover(clas) {
		var icoLnk = $$(clas+' a')
		var ico = $$(clas+' .roll')
		//icoLnk.removeProperty('title')
		icoLnk.each(function(item, index){
			fx(item, 200, 'morph')
			fx(item, 200, 'tween')
			item.addEvents({
				'mouseover': 	function(){
					this.morph(clas+'Over')
					ico.tween('opacity', 0.1)
				},
				'mouseleave': 	function(){
					this.morph(clas+'Out')
					ico.tween('opacity', 1)
				}
			})
		})
	}
	icoRollover('.privati')
	icoRollover('.aziende')
	icoRollover('.giovani')
	icoRollover('.informazioni')
	icoRollover('.risparmio')
	icoRollover('.finanziamenti')
	icoRollover('.investimenti')
	icoRollover('.assicurazioni')
	icoRollover('.servizi')

	// Rollover generico
	var lnk = $$('.lnk')
	var opc = 0.6
	lnk.each(function(item, index){
		fx(item, 250, 'tween')
		item.set('opacity', opc)
		item.addEvents({
			'mouseover': 	function(){ this.tween('opacity', 1) },
			'mouseleave': 	function(){ this.tween('opacity', opc) }
		})
	})


    // Effetti rollover td
    var div = $$('.elProd tr')
    //var td  = $$('.elProd')
	fx(div, 280, 'morph')
	div.addEvents({
		'mouseover': function(){
			this.morph('.bgIn')
		},
		'mouseleave': function(){
			this.morph('.bgOut')
		},
		'click': function(){
			var tagA = this.getElement('a')
			var lnk = tagA.getProperty('href')
			//window.location=lnk
			window.open(lnk)
		}
	})

	// Rollover pulsanti invio-cancella
	// Rollover loghi piede pagine
	var bt	= $$('#sendMail .bt', '#foot .loghi a')
	fx(bt, 300, 'tween')
	bt.set('opacity', 0.5)
	bt.addEvents({
		'mouseover': 	function(){ this.tween('opacity', 1) },
		'mouseleave': 	function(){ this.tween('opacity', 0.5) }
	})

}
window.addEvent('domready', cerea)
