jQuery.noConflict();
var dom = {
	document	: document,
	functions	: new Array(),
	loaded 		: false,
	loadTimer	: '',
	interval	: 0,
	slider 		: {
		init : function(id,par,direction){
			if(typeof direction =='undefined' || direction==''){ direction = 'down'; }
			this.timeout = setTimeout('dom.slider.slide("'+id+'","'+par+'","'+direction+'")',5);
		},
		slide : function(id,par,direction){
			this.finished = false;
			factor = 5;
			if(direction!=this.direction){
				clearInterval(this.interval);
				this.interval = 0;
			}
			this.direction = direction;
			o = parent.getElement(id);
			h = parseFloat(parent.getStyle(o,'height'));
			t = parseFloat(parent.getStyle(o,'top'));
			if(direction=='down' && t == 0){ if(p = getElement(par)){ parent.setStyle(p,'display','block'); } }
			t = (direction=='down')?t+factor:t-factor;
			if((direction =='down' && t<=h) || (direction!='down' && t>=0)){
				parent.setStyle(o,'top',t+"px");
				if(this.interval==0){
					this.interval = setInterval('dom.slider.slide("'+id+'","'+par+'","'+direction+'")',25);
				}
			} else {
				this.finished = true;
				if(t<=0){ if(p = getElement(par)){ parent.setStyle(p,'display','none'); } }
				clearInterval(this.interval);
				this.interval = 0;
			}
		},
		stop : function (){
			if(this.direction!='down' || this.finished){
				clearInterval(this.interval);
				this.interval = 0;
			}
			clearTimeout(this.timeout);
			this.timeout = 0;
		}
	}
}

dom.addOnload = dom.addLoad = function(f){
	//dom.functions[dom.functions.length] = f;
	eval("Event.observe(window, 'load', function() {"+f+"});");
}

dom.onload = function(){
	this.loadTimer = '';
	if(dom.document.body!=null){
		this.loaded = true;
		for(i in this.functions){
			eval(this.functions[i]);
		}
	} else { if(this.loadTimer==''){ this.loadTimer = setTimeout("dom.onload()",300); } }
}

dom.getElement = function (elm){
	try {
		return document.getElementById(elm);
	} catch(e){
		try {
			return document.all(elm);
		} catch(e){ return false; }
	}
}

dom.setStyle = function(obj,property,value){
	if(obj!=null){
		try{
			eval('obj.style.'+property+' = "'+value+'"');
		} catch (e){
			eval('obj.'+property+' = "'+value+'"');
		}
	}
}

dom.getStyle = function(obj,property){
	if(obj!=null){
		try{ eval('ret = obj.style.'+property+';'); }
		catch (e){ eval('ret = obj.'+property+';'); }
		return ret;
	}
	return null;
}

dom.onload();

function createElement(elmName){
	if(arguments.length==1){
		return document.createElement(elmName);
	} else {
		if(document.all==undefined){
			ret = document.createElement(elmName);
			for(i=1;i<arguments.length;i++){
				eval("ret.setAttribute('"+arguments[i]+"','"+arguments[++i]+"')");
			}
		} else {
			props = "";
			for(i=1;i<arguments.length;i++){
				props += ' '+arguments[i]+'="'+arguments[++i]+'"';
			}
			eval("ret = document.createElement('<'+elmName+props+'>')");
		}
		return ret;
	}
}

function destroyElement(elmName){
	if(getElement(elmName)){
		document.body.removeChild(getElement(elmName));
	}
}

function getElement(elm){
	try {
		return document.getElementById(elm);
	} catch(e){
		try {
			return document.all(elm);
		} catch(e){ return false; }
	}
}

function setStyle(obj,property,value){
	if(obj!=null){
		try{
			eval('obj.style.'+property+' = "'+value+'"');
		} catch (e){
			eval('obj.'+property+' = "'+value+'"');
		}
	}
}

function getStyle(obj,property){
	if(obj!=null){
		try{ eval('ret = obj.style.'+property+';'); }
		catch (e){ eval('ret = obj.'+property+';'); }
		return ret;
	}
	return null;
}

function scrollTop(){
	if (document.documentElement && document.documentElement.scrollTop)
		theTop = document.documentElement.scrollTop;
	else if (document.body)
		theTop = document.body.scrollTop;
	return theTop;
}

function scrollLeft(){
	if (document.documentElement && document.documentElement.scrollLeft)
		theTop = document.documentElement.scrollLeft;
	else if (document.body)
		theTop = document.body.scrollLeft;
	return theTop;
}

function setAttribute(obj,attr,value){
	if(typeof eval("obj."+attr)!="undefined") {
		eval("obj."+attr+" = function(){ "+value+" }");
	} else if(obj.setAttribute){
		obj.setAttribute(attr,value);
	}
}

function checkFCK(item){
	if(typeof(FCKeditorAPI)!="undefined"){
		return ((FCKeditorAPI.GetInstance(item).GetXHTML() != '' && FCKeditorAPI.GetInstance(item).GetXHTML() != '<br>'))?1:0;
	} else {
		return ((document.forms['main'].elements[item].value != '' && document.forms['main'].elements[item].value != '<br>'))?1:0;
	}
}

function fetchFCK(item){
	return escape(((typeof(FCKeditorAPI)!="undefined")?FCKeditorAPI.GetInstance(item).GetXHTML():document.forms['main'].elements[item].value));
}

function offsetX(event){
	if(event.offsetX){
		return event.offsetX;
	} else if(event.layerX){
		return event.layerX;
	} else {
		return false;
	}
}

function offsetY(event){
	if(event.offsetY){
		return event.offsetY;
	} else if(event.layerY){
		return event.layerY;
	} else {
		return false;
	}
}

var tinyId;
tinyId = new Array();
function initEditor(id) {
	tinyId[tinyId.length] = id;
	tinyMCE.execCommand('mceAddControl', false, id);
}

function doLogout(){
	ajax.load('utenti.php','doLogout&sezione=utenti');
}

Array.in_array = function(arr,key){
	for(i in arr){
		if(arr[i]==key){ return i; }
	}
	return -1;
}

function in_array(arr,key){
	for(i in arr){
		if(arr[i]==key){ return i; }
	}
	return -1;
}


function getElement(div){
	try {
		return document.getElementById(div);
	} catch(e){
		try {
			return document.all(div);
		} catch(e){ return null; }
	}
}

function setStyle(obj,property,value){
	if(obj!=null){
		try{
			eval('obj.style.'+property+' = "'+value+'"');
		} catch (e){
			eval('obj.'+property+' = "'+value+'"');
		}
	}
}

function getStyle(obj,property){
	if(obj!=null){
		try{				eval('ret = obj.style.'+property+';'); }
		catch (e){	eval('ret = obj.'+property+';'); }
		return ret;
	} 
	return null;
}

function getPage(url){
	qs = '';
	if(oScroll.status && !isNaN(oScroll.y)){
		qs = '?y='+Math.abs(oScroll.y);
	}
	o = document.location;
	return ("http://"+o.hostname+(o.pathname.substr(0,o.pathname.lastIndexOf('/')+1))+url+qs);
}

function checkMail(field) {
	//utente >= 5
	//host >= 3
	//xxxxx@yyy.tld
	var goodEmail = field.match(/\b(^(\S{1,}@).{3,}((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,4}))$)\b/gi);
	if (goodEmail){
	   return true;
	} else {
	   return false;
   }
}

function getResponse(res){
	msg = res;
	if(msg["status"]==1){
		tb_show_tafaz('Newsletter',msg["msg"],null,null,null,closetxt);
	} else {
		tb_show_tafaz('Newsletter',msg["msg"],null,null,null,closetxt);
	}
}

function webcam(id){
	cont = jQuery('#webcam-sx-link');
	if(id==1){
		html = '<a href="javascript:;" onclick="tb_show_tafaz(\'Arabba\',\'&lt;img src=&quot;http://www.belledolomiti.it/res/webcam/original/arabba.jpg&quot; alt=&quot;&quot; width=&quot;640&quot; height=&quot;480&quot; title=&quot;Arabba&quot; />\',640,480,\'\',closetxt);"><img src="http://www.belledolomiti.it/res/webcam/original/arabba.jpg" alt="" width="210" height="150" title="Arabba" /></a>';
		cont.html('1 <a href="javascript:;" onclick="webcam(2);">2</a> <a href="javascript:;" onclick="webcam(3);">3</a>'); // <a href="javascript:;" onclick="webcam(4);">4</a> <a href="javascript:;" onclick="webcam(5);">5</a>
	} else if(id==2){
		html = '<a href="javascript:;" onclick="tb_show_tafaz(\'Marmolada - P.sso Padon\',\'&lt;img src=&quot;http://www.belledolomiti.it/res/webcam/original/marmolada.jpg&quot; alt=&quot;&quot; width=&quot;640&quot; height=&quot;480&quot; title=&quot;Marmolada - P.sso Padon&quot; />\',640,480,\'\',closetxt);"><img src="http://www.belledolomiti.it/res/webcam/original/marmolada.jpg" alt="" width="210" height="150" title="Marmolada - P.sso Padon" /></a>';
		cont.html('<a href="javascript:;" onclick="webcam(1);">1</a> 2 <a href="javascript:;" onclick="webcam(3);">3</a>');
	} else if(id==3){
		html = '<a href="javascript:;" onclick="tb_show_tafaz(\'Marmolada - Portavescovo\',\'&lt;img src=&quot;http://www.arpa.veneto.it/csvdi/svm/arpav/arp009.jpg&quot; alt=&quot;&quot; width=&quot;640&quot; height=&quot;480&quot; title=&quot;Marmolada - Portavescovo&quot; />\',640,480,\'\',closetxt);"><img src="http://www.arpa.veneto.it/csvdi/svm/arpav/arp009.jpg" alt="" width="210" height="150" title="Marmolada - Portavescovo" /></a>';
		cont.html('<a href="javascript:;" onclick="webcam(1);">1</a> <a href="javascript:;" onclick="webcam(2);">2</a> 3');
	}/* else if(id==4){
		html = '<a href="javascript:;" onclick="tb_show_tafaz(\'Col di Lana - Pelmo - Col di Varda\',\'&lt;img src=&quot;http://srv2.realcam.it/live/111/live.jpg&quot; alt=&quot;&quot; width=&quot;640&quot; height=&quot;480&quot; title=&quot;Col di Lana - Pelmo - Col di Varda&quot; />\',640,480,\'\',closetxt);"><img src="http://srv2.realcam.it/live/111/live.jpg" alt="" width="210" height="150" title="Col di Lana - Pelmo - Col di Varda" /></a>';
		cont.html('<a href="javascript:;" onclick="webcam(1);">1</a> <a href="javascript:;" onclick="webcam(2);">2</a> <a href="javascript:;" onclick="webcam(3);">3</a> 4 <a href="javascript:;" onclick="webcam(5);">5</a>');
	} else if(id==5){
		html = '<a href="javascript:;" onclick="tb_show_tafaz(\'Sella\',\'&lt;img src=&quot;http://srv2.realcam.it/live/110/live.jpg&quot; alt=&quot;&quot; width=&quot;640&quot; height=&quot;480&quot; title=&quot;Sella&quot; />\',640,480,\'\',closetxt);"><img src="http://srv2.realcam.it/live/110/live.jpg" alt="" width="210" height="150" title="Sella" /></a>';
		cont.html('<a href="javascript:;" onclick="webcam(1);">1</a> <a href="javascript:;" onclick="webcam(2);">2</a> <a href="javascript:;" onclick="webcam(3);">3</a> <a href="javascript:;" onclick="webcam(4);">4</a> 5');
	}*/
	jQuery('#webcam-sx-content').html(html);
}

function findAncestorDiv(descendantDiv){
	for (var parent = descendantDiv.parentNode; parent; parent = parent.parentNode){
		if (parent.nodeName.toLowerCase() !== "div")
			continue;
		return parent;
	}
	return null;
}
