function init() {
	
  /* Note from seb : the 3 following lines have been commented since they don't seem to work */	
  //document.getElementById('nav-loading').style.display = "none";
  //document.getElementById('linkForward').style.display = "inline";
  //document.getElementById('nav-Preview').style.display = "block";
  winSize();
}


// -------------------------------------------------------------




function winSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	//window.alert( 'Width = ' + myWidth );
	//window.alert( 'Height = ' + myHeight );
	var returnArray = new Array(myWidth, myHeight);
	//return returnArray;
	
	IMG = document.getElementById('magImg');

	
	if (myWidth > myHeight) {
		winner = "width";
		newWidth = myWidth;
		newHeight = (myWidth*728)/1092;
	} else {
		winner = "height";
		newHeight = myHeight;
		newWidth = (myHeight*1092)/728;
	}
	
	IMG.width = newWidth;
	IMG.height = newHeight;
	
	hDiff = IMG.height-myHeight;
	wDiff = IMG.width-myWidth;
	
	magDiv = document.getElementById('magazineHolder');

	var magW = magDiv.style.width;
	var magH = magDiv.style.height;
	
	
	if (hDiff>=0) {
		newT = 0-(hDiff/2);
	} else {
		//hd = Math.abs(hDiff);
		//newT = 0+(hd/2);
		IMG.height = myHeight;
		IMG.width = (myHeight*1092)/728;
		newT = 0;
	}
	if (wDiff>=0) {
		newL = 0-(wDiff/2);
	} else {
		//wd = Math.abs(wDiff);
		//newL = 0+(wd/2);
		IMG.width = myWidth;
		IMG.height = (myWidth*782)/1092;
		newL = 0;
	}
	
	magDiv.style.top = newT+"px";
	magDiv.style.left = newL+"px";
	
	
	var magT = magDiv.style.top;
	var magL = magDiv.style.left;
	
	
	
	var str = "w: "+myWidth+" <br /> h: "+myHeight+" <br />"+winner+"<br /> ";
	str = str+"<br /> hDiff: "+hDiff+" wDiff: "+wDiff;
	str = str+" <br /><br /> IMG w: "+IMG.width+" <br />IMG h: "+IMG.height;
	str = str+" <br /><br /> div t: "+magT+" <br />div l: "+magL;
	
	objDiv = document.getElementById('sizeDisplay');	
	objDiv.innerHTML=str;
	
	magDiv.style.display = "block";
	
	
	
}




// -----------------------------------------------------------------------------







function goHome() {
	if (currentStop>0) {
		/*
		document.getElementById('tocTXT').style.display = "none";
		document.getElementById('tocTXT').innerHTML = "";
		toggleNav();
		currentStop = 0;
		setFlips('b');
		*/
		
		str = "";
		document.getElementById('tocTXT').style.display = "none";
		document.getElementById('tocTXT').innerHTML = "";
		toggleNav();
		currentImage = 200;
		for (n=0;n<4;n=n+1) {
			t = rate*n;
			window.setTimeout("flipForward();", t);
		}
			t = rate*5;
			window.setTimeout("finishGoHome();", t);
	}
}

function finishGoHome() {
	IMG = document.getElementById('magImg');
	currentStop = 0;
	currentImage = 1;
	IMG.src = "magazine/"+currentImage+".jpg";
	
	document.getElementById('tocTXT').className = "intro";
	document.getElementById('linkBack').style.display = "none";
	str = "American Craft celebrates the modern makers who shape the world around us. Presenting unknown innovators and artistic stalwarts, American Craft connects the disparate worlds of art, industry, fashion, architecture and design, giving an entirely new voice to the craft community.";
	showtxt();
	document.getElementById('nav-Preview').style.display = "block";
}






// -----------------------------------------------------------------------------










function flipper(direction) {
	document.getElementById('nav-Preview').style.display = "none";
	document.getElementById('tocTXT').style.display = "none";
	document.getElementById('tocTXT').innerHTML = "";
	toggleNav();
	
	if (direction == 'f') {
		currentStop++;
	} else {
		currentStop--;
	}
	
	if (allLoaded < 2) {
		//preloadImages(76,208);
		//allLoaded++;
	}
	setFlips(direction);
	
}

function setFlips(direction) {
	rate = 400;
	lenght = Math.abs(stops[currentStop]-currentImage);
	//lenght = 4;
	
	for (n=0;n<lenght;n=n+1) {
		t = rate*n;
		if (direction == 'f') {
			if (t == 0) {
				flipForward();
			} else {
				window.setTimeout("flipForward();", t);
			}
		} else {
			if (t == 0) {
				flipBackward();
			} else {
				window.setTimeout("flipBackward();", t);
			}
		}
	}
	
	
	t = rate*(lenght+2);
	window.setTimeout("toggleNav();",t);
	window.setTimeout("chngTxt();",t);
}


function flipForward() {
	//alert(currentImage);
	IMG = document.getElementById('magImg');
	currentImage++;
	IMG.src = "magazine/"+currentImage+".jpg";
}

function flipBackward() {
	//alert(currentImage);
	IMG = document.getElementById('magImg');
	currentImage--;
	IMG.src = "magazine/"+currentImage+".jpg";
}






// -----------------------------------------------------------------------------








function quickClose() {
	str = "";
	showtxt();
	toggleNav();
	currentImage = 200;
	for (n=0;n<7;n=n+1) {
		t = rate*n;
		window.setTimeout("flipForward();", t);
	}
	//t = rate*7;
	//window.setTimeout("document.getElementById('contactInfo').style.display = 'block';",t);
}


function quickOpen() {
	for (n=0;n<6;n=n+1) {
		t = rate*n;
		window.setTimeout("flipBackward();", t);
	}
	t = rate*7;
	window.setTimeout("flipToHouse();", t);
}

function flipToHouse() {
	currentImage = 1;
	currentStop = 0;
	IMG.src = "magazine/"+currentImage+".jpg";
	document.getElementById('tocTXT').className = "intro";
	document.getElementById('linkBack').style.display = "none";
	str = "American Craft Celebrates the modern makers who shape the world around us. Presenting unkown innovators and established masters, American Craft connects the worlds of art, industry, architecture, fashion and design, bringing a fresh, new voice to the craft community.";
	showtxt();
	toggleNav();
}

function toggleMag() {
	if (currentImage>199) {
		document.getElementById('contactInfo').style.display = "none";
		quickOpen();
	} else {
		quickClose();
	}
}





// -----------------------------------------------------------------------------








function chngTxt() {
	switch(stops[currentStop])	{
		case 1:
		  	document.getElementById('tocTXT').className = "intro";
		  	document.getElementById('linkBack').style.display = "none";
		  	document.getElementById('linkForward').style.display = "none";
		  	document.getElementById('nav-Preview').style.display = "block";
		  	str = "American Craft celebrates the modern makers who shape the world around us. Presenting unknown innovators and artistic stalwarts, American Craft connects the disparate worlds of art, industry, fashion, architecture and design, giving an entirely new voice to the craft community.";
		  	break    
		case 5:
			document.getElementById('nav').style.display = 'block';
			document.getElementById('nav-Preview').style.display = "none";
			document.getElementById('tocTXT').className = "norm";
			document.getElementById('linkForward').style.display = "inline";
			document.getElementById('linkBack').style.display = "inline";
		  	str = "<h4>A Brand New Concept</h4><p>It all begins here. Using a standard flap concept in a non-traditional manner, the new American Craft puts all cover lines&mdash;and our logo&mdash;on the flap made of heavy&ndash;weight cover stock, creating a hint of mystery that urges the reader to discover what&rsquo;s hiding underneath. Flip the flap to find out what our photography has in store for you. With nothing impeding the experience, the new American Craft announces right away that it&rsquo;s absolutely one of a kind. </p>";
		  	if (allLoaded <2) {
		  		preloadImages(69,75);
		  		allLoaded++;
		  	}
		  	break
		case 34:
			str = "<h3>022</h3><h4>Zoom</h4><p>An information-packed guide to museum and gallery exhibits, events, books, innovative products and emerging artists. In this issue: Matt Eskuche, Santa Fe Clay, Amaridian Gallery, Artecnica and much more.</p><p><a href=\"javascript:zoomtoggle();\">Hot Spots</a></p>";
			if (allLoaded <3) {
		  		preloadImages(76,81);
		  		allLoaded++;
		  	}
		  	break
		case 68:
			str = "<h3>052</h3><h4>Material Culture</h4><p>Laurie Manfra looks long and hard at the hand-molded furniture of Maarten Baas and finds that the industrial clay he uses lends itself quite nicely to tactile, playful and often wooze-inducing forms.</p><p><a href=\"javascript:articleTwo();\">Read Article</a></p>";
			if (allLoaded <4) {
		  		preloadImages(82,90);
		  		allLoaded++;
		  	}
			break
		case 71:
			str = "<h3>054</h3><h4>Outskirts</h4><p>Lily Kane observes furniture maker/designer David Trubridge&rsquo;s crossover from craft into industrial design and finds herself wondering, Can&rsquo;t we all just get along?</p>";
			if (allLoaded <5) {
		  		preloadImages(91,107);
		  		allLoaded++;
		  	}
			break
		case 75:
			str = "<h3>058</h3><h4>Reviewed</h4><p>Christine Temin tackles Pulp Function at the Fuller...</p>";
			if (allLoaded <6) {
		  		preloadImages(108,123);
		  		allLoaded++;
		  	}
			break
		case 81:
			str = "<h3>065</h3><h4>Reviewed</h4><p>...Jody Clowes takes on Sublime Spaces & Visionary Worlds at Kohler and...</p>";
			if (allLoaded <7) {
		  		preloadImages(124,135);
		  		allLoaded++;
		  	}
			break
		case 90:
			str = "<h3>073</h3><h4>Reviewed</h4><p>...Natalie Haddad views Hot House at Cranbrook.</p>";
			if (allLoaded <8) {
		  		preloadImages(136,147);
		  		allLoaded++;
		  	}
			break
		case 107:
			str = "<h3>090</h3><h4>Little But Loud</h4><p>Robert Sullivan takes the G train to Brooklyn to spend the day with artist and woodworker Richard Humann. Their wide-ranging conversation touches on beer, baseball, biennales and the obsessive nature of Humann&rsquo;s meticulously rendered, often macabre endeavors.</p><p><i>Photography by Chris Mottalini</i></p>";
			if (allLoaded <9) {
		  		preloadImages(148,158);
		  		allLoaded++;
		  	}
			break
		case 123:
			str = "<h3>100</h3><h4>House of the Handmade</h4><p>Photographer Peter Strube goes for a walk on the wild side through artist Nathalie L&eacute;t&eacute;&rsquo;s Paris home and workshop and enters an enchanting profusion of mediums and color in which more is definitely more.</p>";
			if (allLoaded <10) {
		  		preloadImages(158,165);
		  		allLoaded++;
		  	}
			break
		case 135:
			str = "<h3>110</h3><h4>The Phoenix Concept</h4><p>Karrie Jacobs heads to Biloxi, Mississippi, to talk to civic leader Jeremiah O&rsquo;Keefe, who believes that George E. Ohr, the town&rsquo;s famous Mad Potter, still matters and that Los Angeles architect Frank Gehry is the man to make the world listen.</p><p><i>Photography by Elena Dorfman</i></p><p><a href=\"javascript:articleOne();\">Read Article</a></p>";
			if (allLoaded <11) {
		  		preloadImages(166,171);
		  		allLoaded++;
		  	}
		  	break
		case 147:
			str = "<h3>121</h3><h4>Critic&rsquo;s Corner</h4><p>Paul Greenhalgh argues that for craft to take its rightful place in the project of modernity, we must first change the way its history is presented.</p>";
			if (allLoaded <12) {
		  		preloadImages(172,182);
		  		allLoaded++;
		  	}
		  	break
		case 158:
			str = "<h3>130</h3><h4>From the Stacks</h4><p>In April 1953, fiber artist Mariska Karasz delved deeply into filamental forms, reporting on her embroideries in &ldquo;Abstract Stitches&rdquo; for <i>Craft Horizons</i>.</p>";
			if (allLoaded <13) {
		  		preloadImages(183,189);
		  		allLoaded++;
		  	}
			break
		case 165:
			str = "<h3>136</h3><h4>Hunting & Gathering</h4><p>In the Arizona desert home of St&eacute;phane Janssen, Andrew Wagner finds an oasis filled with amazing, eclectic objects reflecting a lifetime of passionate collecting. </p>";
			break
		case 171:
			str = "<h3>142</h3><h4>The Wide World of Craft</h4><p>Shannon Sharpe escapes the doldrums of New York City for Down Under and discovers that Australia&rsquo;s craft scene is alive and doing oh so well.</p>";
			break
		case 182:
			document.getElementById('linkForward').style.display = "inline";
			str = "<h3>142</h3><h4>The Wide World of Craft</h4><p>Shannon Sharpe escapes the doldrums of New York City for Down Under and discovers that Australia&rsquo;s craft scene is alive and doing oh so well.</p>";
			break
		case 185:
			document.getElementById('linkForward').style.display = "none";
			str = "<h3>142</h3><h4>The Wide World of Craft</h4><p>Shannon Sharpe escapes the doldrums of New York City for Down Under and discovers that Australia&rsquo;s craft scene is alive and doing oh so well.</p>";
			break
	}
	showtxt();
}


function showtxt() {
	document.getElementById('tocTXT').innerHTML = str;
	document.getElementById('tocTXT').style.display = "block";
}



// -----------------------------------------------------------------------------





function toggleNav() {
	if (document.getElementById('nav').style.display == 'block') {
		linksActive = 0;
		document.getElementById('nav').style.display = 'none';
	} else {
		linksActive = 1;
		document.getElementById('nav').style.display = 'block';
	}
}






// -----------------------------------------------------------------------------






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];}}
}





// -----------------------------------------------------------------------------






function redArrow(x,imgid) {
	IMG = document.getElementById(imgid);
	if (x == 'r') {
		IMG.src = "imgs/arrowR2-roll.png";
	} else {
		IMG.src = "imgs/arrowR2.png";
	}
}

function bigredArrow(x,imgid) {
	IMG = document.getElementById(imgid);
	if (x == 'r') {
		IMG.src = "imgs/bigArrowR.png";
	} else {
		IMG.src = "imgs/bigArrowR2.png";
	}
}


function redArrowR(x,imgid) {
	IMG = document.getElementById(imgid);
	if (x == 'r') {
		IMG.src = "imgs/arrowR-roll.gif";
	} else {
		IMG.src = "imgs/arrowR.gif";
	}
}

function redArrowL(x,imgid) {
	IMG = document.getElementById(imgid);
	if (x == 'r') {
		IMG.src = "imgs/arrowL-roll.gif";
	} else {
		IMG.src = "imgs/arrowL.gif";
	}
}





// -----------------------------------------------------------------------------




function GetXmlHttpObject() { 
	var objXMLHttp=null
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}  


function preloadImages(a,b) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="images.php";
	url=url+"?a="+a+"&b="+b+"&qid="+Math.random();
	
	xmlHttp.onreadystatechange=stateChangedpreloadImages
	
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChangedpreloadImages() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById('loadextraimages').innerHTML = xmlHttp.responseText;
	}
}





// -----------------------------------------------------------------------------







function editorsLet() {
	if (document.getElementById('editorsLeter').style.display == 'block') {
		document.getElementById('editorsLeter').style.display = 'none';
	} else {
		document.getElementById('editorsLeter').style.display = 'block';
	}
}

function articleOne() {
	if (document.getElementById('article1').style.display == 'block') {
		document.getElementById('article1').style.display = 'none';
	} else {
		document.getElementById('article1').style.display = 'block';
	}
}

function articleTwo() {
	if (document.getElementById('article2').style.display == 'block') {
		document.getElementById('article2').style.display = 'none';
	} else {
		document.getElementById('article2').style.display = 'block';
	}
}

function contactInfoT() {
	if (document.getElementById('contactInfo').style.display == 'block') {
		document.getElementById('contactInfo').style.display = 'none';
	} else {
		document.getElementById('contactInfo').style.display = 'block';
	}
}

function zoomtoggle() {
	if (document.getElementById('zoom').style.display == 'block') {
		document.getElementById('zoom').style.display = 'none';
	} else {
		document.getElementById('zoom').style.display = 'block';
	}
}
   
// JavaScript Document