var CurrentPub='';
function LoadPublication(PubID) {
	if (CurrentPub!=PubID) {
		document.getElementById('PubView').firstChild.src='http://issuu.com/odetoart/docs/'+PubID+'?mode=embed&layout=http%3A%2F%2Fskin.issuu.com%2Fv%2F'+'color%2Flayout.xml&backgroundColor=FFFFFF'+'&showFlipBtn=true';
		CurrentPub=PubID;
		window.scrollTo(0, 800);
	};
//color%2Flayout.xml&backgroundColor=FFFFFF
//softlight%2Flayout.xml
//light%2Flayout.xml
//dark%2Flayout.xml
};

var Publications=new Array(); ShowMax=3;
var PubsDisplayDIV;
function InitPubGallery() {
	PubsDisplayDIV=document.getElementById('PubsDisplay');
	for (var i=0; i<3; i++) {
		eval('TMArtwork'+i+'=TM.AddOBJ(PubsDisplayDIV.childNodes[1+i]);');
	};
	MaxPage=Math.ceil(Publications.length/ShowMax);
};
function ChangePage(RelativePage, NewPage) {
	if (RelativePage!=null && NewPage==undefined) {
		CurrentPage+=RelativePage;
		if (CurrentPage<1) {
			CurrentPage=1;
			return;
		} else if (CurrentPage>MaxPage) {
			CurrentPage=MaxPage;
			return;
		};
	} else if (NewPage!=undefined) {
		CurrentPage=NewPage;
	};
//	document.getElementById('CurrentPage').innerHTML=CurrentPage;
	var iStart=(CurrentPage-1)*ShowMax;
	for (var i=0; i<ShowMax; i++) {
		eval('var thisTM=TMArtwork'+i+';');
		thisTM.StartFade(0, 0.1);
		if ((iStart+i)<Publications.length) {
			RemoveClassFromElement(thisTM.OBJ, 'Hidden');
			setTimeout('DisplayPublication('+i+', '+(iStart+i)+');', 150);
		} else
			AddClassToElement(thisTM.OBJ, 'Hidden');
	};
	if (CurrentPage>1) {
		PubsDisplayDIV.firstChild.innerHTML='<a href="/publications.php/page,'+(CurrentPage-1)+'" onclick="ChangePage(-1); return false;"><img src="/images/arrow_left.jpg" /></a>';
	} else if (CurrentPage==1) {
		PubsDisplayDIV.firstChild.innerHTML='';
	};
	if (CurrentPage<MaxPage) {
		PubsDisplayDIV.lastChild.innerHTML='<a href="/publications.php/page,'+(CurrentPage+1)+'" onclick="ChangePage(1); return false;"><img src="/images/arrow_right.jpg" /></a>';
	} else if (CurrentPage==MaxPage) {
		PubsDisplayDIV.lastChild.innerHTML='';
	};
};
function DisplayPublication(Position, PubIndex) {
	eval('var thisTM=TMArtwork'+Position+';');
	var ArtistNames=''; var ArtistLinks='';
	for (i=0; i<Publications[PubIndex].artists.length; i++) {
		ArtistNames+=', '+Publications[PubIndex].artists[i].name;
		ArtistLinks+=', <a href="/artist.php/'+Publications[PubIndex].artists[i].ID+','+Publications[PubIndex].artists[i].name+'">'+Publications[PubIndex].artists[i].name+'</a>';
	};
	thisTM.OBJ.innerHTML='<img src="/images/publications/'+Publications[PubIndex].pubid+'.jpg" title="Ode To Art Publication - '+Publications[PubIndex].title+', '+ArtistNames.substr(2)+'" /><h3>'+Publications[PubIndex].title+'</h3>'+ArtistLinks.substr(2)+'<br /><br />'+Publications[PubIndex].excerpt.replace(/\n/, '<br/>')+'<br /><br /><a href="/publication_view.php/p,'+Publications[PubIndex].pubid+'" target="OTACatalogue" onclick="ShowPublication(\''+Publications[PubIndex].pubid+'\'); return false;">View Publication</a><br /><a href="/downloads/publications/'+Publications[PubIndex].pubid+'.pdf">Download Publication</a>';
	thisTM.StartFade(1, 0.3);
};

var WidthOffset=50; var HeightOffset=20;
function ShowPublication(PubID) {
	if (PubID=='madonna_nude1' && !confirm('The content may not be appropriate and may be offensive to some people.\nYou must be above 18 to view this publication.\nContinue?')) {
		return;
	}
	TMOverlay.Show();
	TMBGOverlay.StartFade(0.6, 0.3);
	TMImgOverlay.StartFade(1, 0.5);
	var ScrollTop=window.pageYOffset?window.pageYOffset:(document.body.parentElement?document.body.parentElement.scrollTop:0);
	ImgOverlay.lastChild.innerHTML='<div class="Image" style="width:'+(WindowWidth-WidthOffset)+'px;height:'+(WindowHeight-HeightOffset)+'px;margin-top:'+(ScrollTop+10)+'px;margin-left:10px;" onclick="event.cancelBubble=true;"><div id="Close" onclick="HideOverlay();"><img src="/images/close.png" /></div><iframe src="/publication_view.php/p,'+PubID+'"></iframe></div>';
	TMImg=TM.AddOBJ(ImgOverlay.lastChild.firstChild.childNodes[1]);
	TMImgOverlay.StartFade(1, 0.3);
	ChosenImage=1;
};

function WindowResized() {
	UpdateDimensions();
	if (ChosenImage!=-1) {
		Width=WindowWidth-WidthOffset; Height=WindowHeight-HeightOffset;
		TMImg.OBJ.style.height=Height+'px';
		TMImg.OBJ.style.width=Width+'px';
		ImgOverlay.lastChild.firstChild.style.width=Width+'px';
		ImgOverlay.lastChild.firstChild.style.height=Height+'px';
		var ScrollTop=window.pageYOffset?window.pageYOffset:(document.body.parentElement?document.body.parentElement.scrollTop:0);
		ImgOverlay.lastChild.firstChild.style.marginTop=(ScrollTop+10)+'px';
//		ImgOverlay.lastChild.firstChild.style.marginLeft='10px';
	};
};

