
function haeKuva(tyyppi,id,suunta){
  	var param = 'tyyppi=' + tyyppi + '&id=' + id + '&suunta=' + suunta;
  	
  	teeAjaxKutsu('ajax/haeKuva.php',param,handleHaeKuva);
}//end function


function handleHaeKuva(){
  	if (xmlhttp.readyState == 4) {
        /* If the data was retrieved successfully */
   	    if (xmlhttp.status == 200){
            var xmlDocument = xmlhttp.responseXML;
            var kuvat = xmlDocument.getElementsByTagName('kuva');

			if(kuvat.length>0){
			 	var tyyppi = kuvat[0].getAttribute('tyyppi');
			 	
			 	if(tyyppi=='uutinen'){
				 	var kohde  = kuvat[0].getAttribute('kohde');
				}//end if
				
			 	var img;
			 
			  	for(i=0; i<kuvat.length; i++){
			  	 	if(tyyppi=='uutinen'){
						img = document.getElementById('kuvapalsta_kuva' + kohde);
					}else{
					  	img = document.getElementById('kuvapalsta_kuva' + (i+1));
					}//end if
							  	
				  	img.setAttribute('src',kuvat[i].getAttribute('polku'));

					if(document.getElementById('galleria_kuva_teksti')){
					  	document.getElementById('galleria_kuva_teksti').innerHTML = kuvat.item(i).firstChild.data;
					}//end if
					
					if(document.getElementById('kuvapalsta_nyt')){
					  	asetaTeksti(document.getElementById('kuvapalsta_nyt'),kuvat[i].getAttribute('kuva_nyt'));
					}//end if
				}//end for
			}//end if
        }//end if
    }//end if
}//end function
	
	
function asetaTeksti(otus,arvo){
    if(IEselain){
        otus.innerText=arvo;
    }else{
        otus.textContent=arvo;
    }//end if
}//end if


function teeAjaxKutsu(ajaxFile,parametrit,handleFile){
	if (xmlhttp!=null && xmlhttp.readyState !=0 && xmlhttp.readyState !=4) {

	}else{
	    xmlhttp.open("POST", ajaxFile, true);

	    xmlhttp.onreadystatechange = handleFile;
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.send(parametrit);
 	} //end if
}//end function
	

