Array.prototype.has = function( value ) {
	for ( var i=0; i<this.length; i++ ) {
		if ( value === this[ i ] ) return true;
	}

	return false;
};

function initImages( ) {
	aImages = [ "images/phdarts01.gif",
				"images/phdarts02.gif",
				"images/phdarts03.gif",
				"images/phdarts04.gif",
				"images/phdarts05.gif",
				"images/phdarts06.gif",
				"images/phdarts07.gif",
				"images/phdarts08.gif",
				"images/phdarts09.gif",
				"images/phdarts10.gif",
				"images/phdarts11.gif",
				"images/phdarts12.gif",
				"images/phdarts13.gif",
				"images/phdarts14.gif",		
				"images/phdarts15.gif",
				"images/phdarts16.gif",
				"images/phdarts17.gif",
				"images/phdarts18.gif",
				"images/phdarts19.gif",
				"images/phdarts20.gif",
				"images/phdarts21.gif",
				"images/phdarts22.gif",
				"images/phdarts23.gif" ];
}

function initTagLines( ) {
	aTagLines = [ { line:"What do you want to question?", tags:"open-ended;what;question;desire" },
				  { line:"Can art be demonstrated?", tags:"close-ended;art;perception;communication" },
				  { line:"Where do we start?", tags:"open-ended;where;beginning" },
				  { line:"Is there anything to be questioned?", tags:"closed-ended;question;reflection" },
				  { line:"How redundant is the answer?", tags:"open-ended;how;answer;redundancy" },
				  { line:"What makes you think?", tags:"open-ended;what;thought;stimulus" },
				  { line:"Is the question the answer?", tags:"closed-ended;question;answer;word pair" },
				  { line:"What are you looking for?", tags:"open-ended;what;perception" },
				  { line:"What is the method?", tags:"open-ended;what;method;process" },
				  { line:"How long does it take before you start again?", tags:"open-ended;how;repetition;beginning;end;word pair;time lapse" },
				  { line:"Does research produce art?", tags:"art;research" },
				  { line:"Is perception a cognitive process?", tags:"closed-ended;cognition;perception;process" },
				  { line:"What is crucial?", tags:"open-ended;what;necessity" },
				  { line:"Does love fuel our actions?", tags:"closed-ended;love;action;stimulus" },
				  { line:"What propels innovation?", tags:"open-ended;what;innovation;stimulus" },
				  { line:"Do we want criticism?", tags:"closed-ended;criticism;desire" },
				  { line:"How do we continue?", tags:"open-ended;how;progression" },
				  { line:"What about being a perfectionist?", tags:"open-ended;what;perfection;skill" },
				  { line:"Where do art and science meet?", tags:"open-ended;where;art;science" },
				  { line:"Does art mirror society or even shape it?", tags:"closed-ended;art;society;form" },
				  { line:"Is art trivial?", tags:"closed-ended;art;triviality" },
				  { line:"What do we perceive?", tags:"open-ended;what;perception" },
				  { line:"Are thoughts public property?", tags:"closed-ended;thought;public" },
				  { line:"Can we trust in our intuition?", tags:"closed-ended;intuition;belief" },
				  { line:"Can we believe in what we feel?", tags:"closed-ended;feeling;belief" },
				  { line:"Is it dry inside when it is raining outside?", tags:"closed-ended;inside;outside;word pair" },
				  { line:"How much proof can an artwork bare?", tags:"open-ended;how;art;proof" },
				  { line:"How long does an art work last?", tags:"open-ended;how;art;time lapse" },
				  { line:"Do we need inspiration?", tags:"closed-ended;inspiration;necessity" },
				  { line:"How much do we need to know before we understand?", tags:"open-ended;how;knowledge;time lapse;repetition;cognition" },
				  { line:"Should I be more concerned about the world?", tags:"closed-ended;concern;world;responsibility" },
				  { line:"Should I dedicate myself to research?", tags:"closed-ended;research" },
				  { line:"Why is it so quiet out there?", tags:"open-ended;why;world;perception" },
				  { line:"Is the world there when I&rsquo;m not?", tags:"closed-ended;world;time lapse" },
				  { line:"Did I say anything inappropriate?", tags:"closed-ended;conversation" },
				  { line:"Do things look back at me?", tags:"closed-ended;reflection;perception" },
				  { line:"Why am I always in charge?", tags:"open-ended;why;responsibility" },
				  { line:"How do I make myself understood?", tags:"open-ended;how;expression;conversation" },
				  { line:"Is the world full of unread messages?", tags:"closed-ended;world;message" }, 
				  { line:"Has everything been considered yet?", tags:"closed-ended;reflection;time lapse" },
				  { line:"What do I know?", tags:"open-ended;what;knowledge" },
				  { line:"Is knowledge endless?", tags:"closed-ended;knowledge;limit" },
				  { line:"What is the limit?", tags:"open-ended;what;limit" },
				  { line:"Can we measure reflection?", tags:"closed-ended;reflection;limit" },
				  { line:"Is silence made of thoughts?", tags:"closed-ended;silence;thought" },
				  { line:"Does the cosmos suffocate on my thoughts?", tags:"closed-ended;world;thought" },
				  { line:"What do you have to tell?", tags:"open-ended;what;conversation;necessity" },
				  { line:"Who borrows my consciousness when I am asleep?", tags:"open-ended;who;consciousness" },
				  { line:"The bigger the idea, the heavier the burden I have to carry?", tags:"closed-ended;idea;responsibility;word pair" },
				  { line:"Why do I have to do everything myself?", tags:"open-ended;why;responsibility" },
				  { line:"Are questions really any help?", tags:"closed-ended;question;help" },
				  { line:"Will this wall never stop to rebound my thoughts?", tags:"closed-ended;wall;reflection;thought" },
				  { line:"What is time?", tags:"open-ended;what;time;time lapse" },
				  { line:"Is this a choice or a feeling?", tags:"closed-ended;choice;feeling" },
				  { line:"How does the system work?", tags:"open-ended;how;system;method" },
				  { line:"Are you passionate?", tags:"closed-ended;passion;stimulus" },
				  { line:"How much desire stimulates you?", tags:"open-ended;how;desire;stimulus" },
				  { line:"Will you listen when I whisper?", tags:"closed-ended;conversation;communication" },
				  { line:"Do you master the art of communication?", tags:"closed-ended;art;communication;skill" },
				  { line:"What&rsquo;s on your mind?", tags:"open-ended;what;reflection;thought" },
				  { line:"Can we argue about art?", tags:"closed-ended;art;conversation;criticism" },
				  { line:"Does art imitate reality or does it intervene in reality?", tags:"closed-ended;art;perception;reality;intervention" },
				  { line:"Can you describe the specific kind of pleasure you take in art?", tags:"closed-ended;art;feeling" },
				  { line:"Does art&rsquo;s strength lie in its weakness?", tags:"closed-ended;art;stimulus" },
				  { line:"Can you give &lsquo;style&rsquo; to your character?", tags:"closed-ended;style" },
				  { line:"How important is distance for art?", tags:"open-ended;how;art;relevance;perception" },
				  { line:"Does art have a special home in the dream-world?", tags:"closed-ended;art;reality;dream;world;society" },
				  { line:"Are artworks still possible in our fully mediatised world?", tags:"closed-ended;art;media;world" },
				  { line:"Do we have to believe it for it to be art?", tags:"closed-ended;art;belief" },
				  { line:"Does art point towards its own unreality?", tags:"closed-ended;art;reality;limit" },
				  { line:"Does the unreality of artworks mean we cannot believe in them?", tags:"closed-ended;art;reality;belief" },
				  { line:"Does art lie?", tags:"closed-ended;art;reality" },
				  { line:"What kind of a &lsquo;thing&rsquo; is an artwork?", tags:"open-ended;what;art;commodity" },
				  { line:"Can the artwork be anything but a commodity?", tags:"closed-ended;art;commodity" },
				  { line:"Why do you always come back to the artworks you love?", tags:"open-ended;why;art;repetition;feeling" },
				  { line:"Are artists also important thinkers?", tags:"closed-ended;art;thought;relevance" } ];
}

function getTagIds( aTags, iTagId ) {
	var aLinkedTags = new Array( );

	for ( var i=0; i<aTags.length; i++ ) {
		if ( aTags[ i ] != "closed-ended" && aTags[ i ] != "open-ended" ) {
			for ( var n=0; n<aTagLines.length; n++ ) {
				var iIndex = aTagLines[ n ].tags.indexOf( aTags[ i ] );
				if ( iIndex != - 1 && !aLinkedTags.has( n ) && iTagId != n ) aLinkedTags.push( n );
			}
		}
	}

	return aLinkedTags;
}

function setTagLine( sTagLine ) {

	var iTagIndex = -1;
	var sImageURL = -1;

	switch ( sTagLine ) {
		case "the_artist_as_researcher":
			iTagIndex = 1;
			sImageURL = "images/the artist as researcher.gif";

			break;
	}

	if ( iTagIndex == -1 ) iTagIndex = Math.random( ) * aTagLines.length;
	if ( sImageURL == -1 ) sImageURL = aImages[ Math.random( ) * aImages.length ];

	document.getElementById( 'title' ).innerHTML = '<a href="#" onClick="getTagLine(\'' + aTagLines[ iTagIndex ].tags + '\', ' + iTagIndex + ');">' + aTagLines[ iTagIndex ].line + '</a>';
	document.getElementById( "background" ).style.backgroundImage = "url('" + sImageURL + "')";

	resizeContent( );
}

function getTagLine( sTags, iTagIndex ) {
	if ( sTags == undefined ) {
		if ( iTagIndex != undefined ) var iIndex = iTagIndex;
		else var iIndex = Math.floor(  Math.random( ) * aTagLines.length );
	} else {
		var aLinkedIds = getTagIds( sTags.split( ";" ), iTagIndex );
		var iIndex = aLinkedIds[ Math.floor( Math.random( ) * aLinkedIds.length ) ];
	}

	var sOutputLine = '<a href="#" onClick="getTagLine(\'' + aTagLines[ iIndex ].tags + '\', ' + iIndex + ');">' + aTagLines[ iIndex ].line + '</a>';
	document.getElementById( 'title' ).innerHTML = sOutputLine;

	if ( iIndex == 0 && iTagIndex == 0 ) {
		var sImageURL = aImages[ 0 ];
	} else {
		var sImageURL = aImages[ 1 + Math.floor( Math.random( ) * ( aImages.length - 1 ) ) ];
	}

	document.getElementById( "background" ).style.backgroundImage = "url('" + sImageURL + "')";

	resizeContent( );
}

initImages( );
initTagLines( );
