// MM's omni-present image-swapper
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



// MM preload images
function MM_preloadImages() { //v3.0 
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); 
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) 
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} 
}



// MM jump-menu
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}



// initiate button fades
function buttonOn(div) {
	fadeElementSetup(div, 100, 0, 6);
}

function buttonOff(div) {
	fadeElementSetup(div, 0, 100, 10);
}



// auto-resize posted images
function catflap_resize_image (imageref)
	{
		//alert(imageref.width);
    var widthofimage=imageref.width;              
	var winwidth = 0;
	
                  var size_available = 500; //to set 500 pixels as the max image width
	if (self.innerWidth) winwidth = self.innerWidth;
		else if (document.documentElement && document.documentElement.clientWidth) winwidth = document.documentElement.clientWidth;
		else if (document.body) winwidth = document.body.clientWidth;
	//size_available = winwidth - 600;
	if (widthofimage > size_available)
		{
			//alert("yes");
		var pc = Math.round (size_available / widthofimage * 10000) / 100;
		imageref.catflap_original_width=widthofimage;
		imageref.catflap_shrunk_width=size_available;
		imageref.catflap_shrunk_pc=pc;
		imageref.catflap_shrunk_status=1;
		imageref.style.width=size_available+'px';
		if (imageref.previousSibling)
			{
			imageref.previousSibling.style.width=size_available+'px';
			imageref.previousSibling.firstChild.nodeValue="image displayed at " + pc + "% of its original size; click here for original";
			//imageref.previousSibling.firstChild.nodeValue="resized image, click here for original";
			imageref.previousSibling.style.display = 'block';
			imageref.previousSibling.style.textAlign = 'center';
			imageref.previousSibling.style.paddingTop = '3px';
			imageref.previousSibling.style.paddingBottom = '3px';
			imageref.previousSibling.style.backgroundColor = '#F0F0F0';
			imageref.previousSibling.style.fontStyle = 'normal';
			imageref.previousSibling.style.color = '#003080';
			}
		}
		
                              if(widthofimage==0)
		{
                                     imageref.style.display='none';
		}
	}

function catflap_toggle_image_size (imageref)
	{
	if (imageref.nextSibling)
		{
		if (imageref.nextSibling.catflap_shrunk_status == 1)
			{
				imageref.firstChild.nodeValue="original size, click here to reduce";
			imageref.style.width=imageref.nextSibling.catflap_original_width+'px';
			imageref.nextSibling.style.width=imageref.nextSibling.catflap_original_width+'px';
			imageref.nextSibling.catflap_shrunk_status=0;
			imageref.style.display = 'block';
                                                      }
		 else
			{
			//imageref.firstChild.nodeValue="Immagine ridimensionata al " + imageref.nextSibling.catflap_shrunk_pc + "% delle sue dimensioni. Clicca qui per vederla nelle dimensioni originali.";
			imageref.firstChild.nodeValue="resized image, click here for original";
			imageref.style.width=imageref.nextSibling.catflap_shrunk_width+'px';
			imageref.nextSibling.style.width=imageref.nextSibling.catflap_shrunk_width+'px';
			imageref.nextSibling.catflap_shrunk_status=1;
			imageref.style.display = 'block';
                                                      }
		}
	}


function post_toggle_color(postid, checkid)
    {
	 id1=postid+1;
	 id2=postid+2;
	 id3=postid+3;
	 id4=postid+4;
	 id5=postid+5;
	 		
	if ((document.getElementById(id1).className!="post1") && (document.getElementById(checkid).checked))	
	      { 
		    document.getElementById(id1).className="post1";
			document.getElementById(id2).className="post2";
			document.getElementById(id3).className="post3";
			document.getElementById(id4).className="post3";
			document.getElementById(id5).className="post3";
		  }
	
	else
	      { 
		    document.getElementById(id1).className="pBitBdyCtr";
			document.getElementById(id2).className="pBitBdyGry";
			document.getElementById(id3).className="pBitPost";
			document.getElementById(id4).className="pBitPost";
			document.getElementById(id5).className="pBitPost";
		  }
		 
	}


function ImageLoadFailed() {
        window.event.srcElement.style.display = "None";
        return "$link";
       }
