
var xmlHttp;
var tim;
function createXMLHttpRequest() {
	
	if (window.ActiveXObject) {
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest;
	}	

}


function click_aff(who) {clearTimeout(tim);
	startRequestAffina(who);
	$('el_affinamenti').appear({ duration: 0.5 });
	
}

function hide_af()  {
	$('el_affinamenti').hide();
}
function hide_aff() {
	tim = setTimeout("hide_af()",300);
}
function show_aff() {
	clearTimeout(tim);
	$('el_affinamenti').show();
}
function show_af() {
	$('el_affinamenti').show();
}

function startRequestAffina(who){
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChangeAffina;
	switch (who) {
		case 'collection':
			xmlHttp.open("GET", "/biasia/inc/collections.xml", true);
			break;
		case 'style':
			xmlHttp.open("GET", "inc/styles.xml", true);
			break;
		case 'color':
			xmlHttp.open("GET", "inc/colors.xml", true);
			break;
	}
	xmlHttp.send(null);
}
function handleStateChangeAffina() {
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200) {
			listAllAffinamenti();
		}
	}
}

function listAllAffinamenti() {
	var xmlDoc = xmlHttp.responseXML;
	var allAffinamenti = xmlDoc.getElementsByTagName("elemento");
	outputLista(allAffinamenti);
}
 
function outputLista(affinamenti) {
	
	var out='';
	var currentAff = null;
	for( i = 0; i < affinamenti.length; i++) {
		currentAff = affinamenti[i];
		switch ((i+1)%10) {
			case 0:
				out = out + "<li>&raquo; " + currentAff.childNodes[0].nodeValue + "</li></ul>";	
				break;
			case 1:
				out = out + "<ul onmouseover=\"$('el_affinamenti').show();\"><li>&raquo; " + currentAff.childNodes[0].nodeValue + "</li>";	
				break;
			default:
				out = out + "<li>&raquo; " + currentAff.childNodes[0].nodeValue + "</li>";		
				break;
		}		
	}
	out += '</ul>';
	document.getElementById('el_affinamenti').innerHTML = out;
}

