//	Copyright 2006 Artlogic Media Limited (http://www.artlogic.net/)

var viewArtworkWinW = 750;
var viewArtworkWinH = 550;

var theViewArtworkWins = new Array();

function openViewArtworkWin(id,url,w,h) {
	var l=(screen.availWidth-w)/2;
	var t=((screen.availHeight-h)/3)-40;
	if (!theViewArtworkWins[id]||theViewArtworkWins[id].closed) {
		theViewArtworkWins[id]=window.open(url,"",'width='+w+',height='+h+',top='+t+',left='+l+',scrollbars=no,menubar=no,status=no');
		try {
			theViewArtworkWins[id].focus();
		} catch(e) {
			//	do nothing
		}
	} else {
		try {
			theViewArtworkWins[id].focus();
		} catch(e) {
			//	do nothing
		}
	}
}


function viewArtwork(params) {
	/*
		A 'view artwork' link is constructed as follows:
			viewArtwork({slides: true, id: 1, artist: 'artist', skipvalue: 0, type: ''})
		...where...
			slides		-	is either true or false. If true, the window will play a slideshow and the 'id' and 'skipvalue' parameters will be ignored
			id			-	the ID of the record, if present. Not required unless 'slides' is false
			artist		-	the artist's name, URL encoded
			skipvalue	-	the skip value for the current record (when 'slides' is true). This is generally the skip value of
							the sending page, plus the record index, starting from zero (eg. the loop_count - 1)
			type		-	optional: a value which will allow you to set conditions on the view page, eg type: 'newAdditions'
			args		-	optional: any other args you wish to pass to the view artworks window, as a URL encoded string
	*/
	var params = (params) ? params : {};
	var slides = (params.slides) ? 1 : 0;
	var id = (params.id) ? params.id : '';
	var artist = (params.artist) ? params.artist : '';
	var skip = (params.skipvalue) ? parseInt(params.skipvalue) : 0;
	var type = (params.type) ? params.type : '';
	var args = (params.args) ? "&" + params.args : '';
	var url = "/viewartwork/?slides=" + slides + "&id=" + id + "&artist=" + artist + "&skip=" + skip + "&type=" + type + args;
	openViewArtworkWin("Artwork",url,viewArtworkWinW,viewArtworkWinH);
}

function viewAllWorksBy(artist) {
	if (opener) {
		try {
			opener.document.location = '/browse/?a=' + artist;
			window.close();
		} catch(e) {
		//	// do nothing, we tried
		}
	}
}


document.getElementsByClassName = function (className, parentElement) {
	if (document.getElementById(parentElement)) {
		var children = document.getElementById(parentElement).getElementsByTagName('*');
	} else {
		var children = document.body.getElementsByTagName('*');
	}
	var els = new Array();
	for (var i=0; i<children.length; i++) {
		var child = children[i];
		if (child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)"))) {
			els[els.length]=child;
		}
	}
	return els;
}

function createBoxedItems() {
	var above='<table cellspacing="0"><tr><td class="tl">\</td><td class="tm">';
	var below='\</td><td class="tr">\</td>\</tr><tr><td class="bl">\</td><td class="bm">\</td><td class="br">\</td>\</tr>\</table>';
	var html;
	var els=document.getElementsByClassName('boxedItem');
	for (var i=0; i<els.length; i++) {
		html=above+els[i].innerHTML+below;
		els[i].innerHTML=html;
		els[i].style.visibility="visible";
	}
}

function doOnLoad() {
	createBoxedItems();
}
