/* general variables */

var fadeTarget;
var newPicture;

function writeText(){
	
	document.write('img/' + picture + '.jpg');
	
}

function changePicture(direction){
	
	if (direction == 'next'){

		if (picture == max){
			
			picture = 1;
			
		}else{
			
			picture++;
			
		}

	}else{

		if (picture == 1){
			
			picture = max;
			
		}else{
			
			picture--;
		
		}

	}

	var fadeTargetId = 'picture'; /* change this to the ID of the fadeable object */
	preInit(fadeTargetId);
	
}

/* functions */

function preInit(a) {
	/* an inspired kludge that - in most cases - manages to initially hide the image
	   befor`e even onload is triggered (at which point it's normally too late, and a nasty flash
	   occurs with non-cached images) */
	   
	var fadeTargetId = a;  
	fadeTarget = document.getElementById(fadeTargetId);

	fadeOut(100);

//	document.picture.src='img/2.jpg';
	
//	window.setTimeout("fadeIn(0)", 500);

}

function fadeIn(opacity) {
	
	if (fadeTarget) {
		
		if (opacity <= 100) {
			
			if (fadeTarget.style.MozOpacity!=null) {
				/* Mozilla's pre-CSS3 proprietary rule */
				fadeTarget.style.MozOpacity = (opacity/100)-.001;
				/* the .001 fixes a glitch in the opacity calculation which normally results in a flash when reaching 1 */
			} else if (fadeTarget.style.opacity!=null) {
				/* CSS3 compatible */
				fadeTarget.style.opacity = (opacity/100)-.001;
			} else if (fadeTarget.style.filter!=null) {
				/* IE's proprietary filter */
				fadeTarget.style.filter = "alpha(opacity="+opacity+")";
				/* worth noting: IE's opacity needs values in a range of 0-100, not 0.0 - 1.0 */ 
			}

			opacity += 10;
			window.setTimeout("fadeIn("+opacity+")", 30);
			
		}

	}

}

function fadeOut(opacity) {
	
	if (fadeTarget) {
		
		if (opacity >= 0) {
			
			if (fadeTarget.style.MozOpacity!=null) {
				/* Mozilla's pre-CSS3 proprietary rule */
				fadeTarget.style.MozOpacity = (opacity/100)-.001;
				/* the .001 fixes a glitch in the opacity calculation which normally results in a flash when reaching 1 */
			} else if (fadeTarget.style.opacity!=null) {
				/* CSS3 compatible */
				fadeTarget.style.opacity = (opacity/100)-.001;
			} else if (fadeTarget.style.filter!=null) {
				/* IE's proprietary filter */
				fadeTarget.style.filter = "alpha(opacity="+opacity+")";
				/* worth noting: IE's opacity needs values in a range of 0-100, not 0.0 - 1.0 */ 
			}

			opacity -= 10;
			window.setTimeout("fadeOut("+opacity+")", 30);
			
		}else{
			
			document.picture.src='img/' + picture + '.jpg';
			window.setTimeout("fadeIn(0)",1000);
			
		}

	}

}

/* initialise fader by hiding image object first 
addEvent (window,'load',fadeInit)

3rd party helper functions

addEvent handler for IE and other browsers

function addEvent(elm, evType, fn, useCapture) 
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
 if (elm.addEventListener){
   elm.addEventListener(evType, fn, useCapture);
   return true;
 } else if (elm.attachEvent){
   var r = elm.attachEvent("on"+evType, fn);
   return r;
 }
} 
*/
