var xmlRatingNews=assegnaHTTPRequestNews();
var xmlVoteNews=assegnaHTTPRequestNews();
var xmlCommNews=assegnaHTTPRequestNews();
var ratingNews;
var ratingContentNews;
var controlloNews=0;
var casoXML1=0;
function assegnaHTTPRequestNews(){
	var xmlHttp=null;
	try
		{
		// Firefox, Opera 8.0+, Safari    
		xmlHttp=new XMLHttpRequest();
		casoXML1=1;
		}
		catch (e)
			{
			// Internet Explorer    
			try
				{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
				casoXML1=2;
				}
				catch (e)
						{
						try
							{
							xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
							casoXML1=3;
							}
							catch (e)
									{
									alert("Your browser does not support AJAX!");
									return false;
									}      
						}    
			}
		return xmlHttp;
	}
	
function createDivNews(divPadre, divFiglio, caso, idFoto, content, alte){
	ratingNews=document.getElementById(divFiglio);
	ratingContentNews=document.getElementById(content);
	var invL, invT, comL, comT, sendL, sendT
	if (alte<4){
		//alert(document.getElementById('rHead').style.background)
		ratingNews.style.overflow="visible"
		document.getElementById('rHead').style.background="url(images/boxsopra2.gif)"
		document.getElementById('rHead').style.position="relative"
		document.getElementById('rHead').style.left="-8px"
		document.getElementById('rHead2').style.background="url(images/mailAlto2.gif)"
		document.getElementById('rHead2').style.position="relative"
		document.getElementById('rHead2').style.left="-8px"
		invL=65;
		invT=50;
		comL=140;
		comT=50;
		sendL=170,
		sendT=50;
	}else{
		ratingNews.style.overflow="hidden"
		document.getElementById('rHead').style.background="url(images/boxsopra.gif)"
		document.getElementById('rHead').style.left="0px"
		document.getElementById('rHead2').style.background="url(images/mailAlto.gif)"
		document.getElementById('rHead2').style.left="0px"
		invL=-180;
		invT=50;
		comL=-300;
		comT=50;
		sendL=-240,
		sendT=50;
	}
	if (ratingNews.style.display!="none"){
		ratingNews.style.display="none"
	}
	var altezza=getPosY(document.getElementById(divPadre))
	var larghezza=getPosX(document.getElementById(divPadre))
	//alert(rating.style.display);
	var imgClass;
	switch (caso){
		case 'vota':
			//altezza+=70;
			larghezza+=invL;
			imgClass=""
			if (document.getElementById('ratingInvio').style.display!="none"){
				togliDiv('ratingInvio');
			}
			ratingContentNews.innerHTML="<img src=\"images/ajax-loader.gif\" alt=\"load\" class=\"imgLoad"+imgClass+"\"/>"
			new Effect.Appear(divFiglio, { duration: 0.4, afterFinish: vediVotiNews(idFoto) });
		break;
		case 'invio':
			//altezza+=70;
			larghezza+=sendL;
			imgClass="2"
			ratingContentNews.innerHTML="<iframe src=\"ajaxCall/inviaNews.aspx?idFoto="+idFoto+"\" frameborder=\"0\" height=\"450\" width=\"100%\"></iframe>"
			if (document.getElementById('rating').style.display!="none"){
				togliDiv('rating');
			}
			new Effect.Appear(divFiglio, { duration: 0.4 });
		break;
		case 'commento':
			ratingContentNews.innerHTML=""
			//altezza+=70;
			larghezza+=comL;
			imgClass="2"
			ratingContentNews.innerHTML="<iframe src=\"ajaxCall/commentoNews.aspx?idFoto="+idFoto+"\" frameborder=\"0\" height=\"250\" width=\"100%\"></iframe>"
			if (document.getElementById('rating').style.display!="none"){
				togliDiv('rating');
			}
			new Effect.Appear(divFiglio, { duration: 0.4 });
		break;
	}
	ratingNews.style.top=altezza+"px"
	ratingNews.style.left=larghezza+"px"
	//rating.style.display="block"
	
	//vediVoti(idFoto);
}

function vediVotiNews(idFoto){
	var c;
	c=Math.random()
	var url="ajaxCall/vediVotiNews.aspx?id="+idFoto+"&mat="+c
	xmlRatingNews.open("GET", url, true);
	xmlRatingNews.setRequestHeader("Cache-Control","no-cache");
	xmlRatingNews.setRequestHeader("Pragma","no-cache");
	xmlRatingNews.setRequestHeader("Cache-Control","no-store");
	if (casoXML1==1)
    	xmlRatingNews.setRequestHeader("Connection", "close");
	xmlRatingNews.onreadystatechange= function(){
		if(xmlRatingNews.readyState==4){
			ratingContentNews.innerHTML=xmlRatingNews.responseText;
		}
	}
	xmlRatingNews.send(null);	
}
function togliDiv(casoV){
	new Effect.Fade(casoV, { duration: 0.4 });
}
function vediStellaNews(lung){
	for (var a=1; a<6; a++){
		document.getElementById('linkR'+a).style.backgroundPosition="0px 0px"		
	}
	for (var i=1; i<(lung+1); i++){
		document.getElementById('linkR'+i).style.backgroundPosition="0px -20px"	
	}
}
function votaFotoNews(idFoto, voto){
	var v;
	v=Math.random
	var url="ajaxCall/vediVotiNews.aspx?id="+idFoto+"&voto="+voto+"&mat="+v
	document.getElementById('VV').innerHTML="<img src=\"images/ajax-loader.gif\" alt=\"loading\" class=\"imgLoad\"/>"
	xmlVoteNews.open("GET", url, true);
	xmlVoteNews.setRequestHeader("Cache-Control","no-cache");
	xmlVoteNews.setRequestHeader("Pragma","no-cache");
	xmlVoteNews.setRequestHeader("Cache-Control","no-store");
	if (casoXML1==1)
    	xmlVoteNews.setRequestHeader("Connection", "close");
	xmlVoteNews.onreadystatechange= function(){
		if(xmlVoteNews.readyState==4){
			ratingContentNews.innerHTML=xmlVoteNews.responseText;
		}
	}
	xmlVoteNews.send(null);	
}
function getPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }else if (obj.x){
        curleft += obj.x;
        controlla1=1;
    }
        //alert(curleft);
    return curleft;
}
function getPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }else if (obj.y){
        curtop += obj.y;
        controlla2=1;
        //alert(curtop);
    }
    return curtop;
}	
