 

var box;

inps = {
	
	backgroundFix: function() {
		// background fix
		$('#outer').css("background-position", $('#container').width() + $('#container').position().left + "px 0px");
		$("#outer").addClass("ready");
	 
	},

	backgroundIcone: function() {
		return  ; //SM
		if(inps.tipo == 'homepage') {
			var t2 = $('#scopriinps h2').position().left;
			$('#scopriinps .claim').css({'background-position' : t2 + 2 + 'px -51px'});
			var t3 = $('#utentiprofessionali h2').position().left;
			$('#utentiprofessionali .claim').css({'background-position' : t3 + 2 + 'px -51px'});
		}
		else if(inps.tipo == 'scopriinps') {
			var t2 = $('#scopriinps span').position().left;
			$('.claim').css({'background-position' : t2 - 1 + 'px -51px'});
		}
		else if(inps.tipo == 'utentiprofessionali') {
			var t2 = $('#utentiprofessionali span').position().left;
			$('.claim').css({'background-position' : t2 - 1 + 'px -51px'});
		}
	},

	correggiNews: function() {
		var h = $('.selected .tabContent').height();
		var dh = h - this.originalHeight + 11;
		if(inps.isIE6()) dh = dh + 4;
		$('#news').css({'margin-top' : dh + 'px'});
	},

	correggiNews1: function() {
		var h = $('.selected .tabContent').height();
		var dh = h - this.originalHeight + 11;
		if(inps.isIE6()) dh = dh + 4;
		$('#news').css({'margin-top' : dh + 'px'});
	},

	correggiAltezzaH2: function() {
		$('.selected .tabContent').css({'margin-top' : $('.selected h2').height() -1 + 'px'});
	},

	isIE6: function() {
		if ((jQuery.browser.msie)&&(parseInt(jQuery.browser.version) == 6)) {return true} else {return false};
	},


	cropTagCloud: function() {
		var ti = $("#tagcloud .cloud a");
		var nmax = 0;
		var nmin = 100;
		var ultimo;

		ti.each(function(index, item){
			var a = item.title.split(' ')[1];
			if(parseInt(a) < nmin) {
				nmin = a;
				ultimo = item;
			}
			else if(a > nmax) {
				nmax = a;
			};
		});

		var diff = (nmax-nmin)/5;
		ti.each(function(index, item){
			var a = item.title.split(' ')[1];
			var p = 0;
			if(!diff) diff = 1;
			for(i=nmin;i<=nmax;i=parseFloat(i)+diff) {
				if(a < i) {
					item.className = 'peso_'+p;
					break;
				}
				p++;
			}
		});


		for(i=0;i<=ti.length-1;i++) {
			if($("#tagcloud .cloud").height() < 70) {
				break;
			}
			else {
				ultimo.parentNode.removeChild(ultimo);
				this.cropTagCloud();
			};
		}

		$("#tagcloud").addClass("ready");
	},

	onTabClick: function() {
		this.correggiAltezzaH2();
		this.correggiNews();

		// correzione bordo bianco finale della tab
		var s = $('.panel.selected')[0];
		if(s.id=='utentiprofessionali') {
			$('#canali').addClass('up');
		}
		else {
			$('#canali').removeClass('up');
		}
	},

	linkEsterni: function() {
		$('a.esterno').bind("click keypress", function(event) {
			if(event.type == 'keypress') {
				if((event.which == '13')||(event.which == '32')) {
					window.open(event.target.href,"_blank","")
				}
				if(event.which == '0') {
//					console.log(event.which);
				}
			} else {
				window.open(event.target.href,"_blank","")
			};
			return false;
		});
	},

	stabilizzaTab: function() {
/*
		var h = $('#dialogo').height();
		if(h>50) {
			$('ul#canali li.selected')[0].style.height = '72px !important';
		}
*/
	},

	stabilizzaCanali: function() {
		if(inps.tipo == 'homepage') {
			var claimH = $('.selected .claim').height();
			var contentH = $('.selected .content').height();
			var d = ($.browser.msie)? 12 : 21;
			var sH = claimH + contentH + d;
			var dH = $('#tagcloud').height();
			$('.selected .bottom').css({'margin-top' : (dH - sH) + 'px'});
		}
	}
}



$(document).ready(function(){

		    base_url = document.location.href.substring(0, document.location.href.indexOf('default.aspx'), 0);
		    
			$(".lightbox").lightbox({
			    fitToScreen: true,
			    imageClickClose: false
		    });
			
			$(".lightbox-2").lightbox({
			    fitToScreen: true
		    });	
		    
	inps.backgroundFix();
	inps.originalHeight = $('.selected .tabContent').height();
//	inps.contentHeight = $('.selected .tabContent .content').height() + $('.selected .claim').height();

	// individua la tipologia di pagina
	var c = document.getElementsByTagName('body')[0].className.split(' ');
	var a = (c.length > 1)? c[1] : c[0];
	inps.tipo = a;

	setTimeout('inps.backgroundIcone()',500);
//	inps.stabilizzaTab();

	// inizializza tab in home page
		return ;//SM 
	if (inps.tipo == 'homepage')  {  
		inps.cropTagCloud();
		box = new Tabbox("canali", { header: "h2", autosize: true })
		if(!inps.isIE6()) inps.stabilizzaCanali();
		inps.correggiNews();
/*
		if(!$('body').hasClass("new")) {
			inps.cropTagCloud();
		}
*/

		if($(document).getUrlParam('tab')) {
			box.selectTab($(document).getUrlParam('tab'));
		}
	}
	inps.linkEsterni();
	sign();
 
});

$(window).resize(function(){
	inps.backgroundFix();
	inps.backgroundIcone();
//	inps.stabilizzaTab();
return ; //SM
	if(inps.tipo == 'homepage') {
//		console.log('bb');
		box.adjustFootprint();
		inps.stabilizzaCanali();
		inps.correggiNews();
	}
/*
*/
//	box.adjustFootprint(); // corregge l'altezza dei canali in home


});

$(document).bind("fontresize", function (event, data) {
	
	if(inps.tipo == 'homepage') {
		inps.backgroundFix();
		return ; //SM
		inps.correggiAltezzaH2();
		inps.stabilizzaCanali();
		box.adjustFootprint(); // corregge l'altezza dei canali in home
		inps.correggiNews();
		
	}
});
var percorso = (opzioni.basePath)? opzioni.basePath : '';
document.write('<link rel="stylesheet" type="text/css" href="' + percorso + 'include/jsenabled.css" media="screen" />');

/*
document.onkeyup = KeyCheck;       

function KeyCheck(e) {
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	switch(KeyID) {
		case 37:
		console.log('sinistra');
	//	document.Form1.KeyName.value = "Arrow Left";
		break;

		case 39:
		console.log('destra');
	//	document.Form1.KeyName.value = "Arrow Right";
		break;
	}
}
*/




function autoIframe(frameId){
	try {
		frame = document.getElementById(frameId);
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		objToResize = (frame.style) ? frame.style : frame;
		objToResize.height = innerDoc.body.scrollHeight + 10;
	}
	catch(err){
		window.status = err.message;
	}
}

function sign() {
	$('body').append('<div id="hcard-andrea-martines" class="vcard nodisplay"><a class="url fn" href="http://www.linkedin.com/in/andreamartines">Andrea Martines</a><span class="org">Elsag Datamat</span><span class="title">Front-End e Accessibilit&agrave;</span></div>');
}


function getTopPos(obj) {
	var top = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			top += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj.y) top += obj.y;
	return top;
}

