/*
 * Random homepage picture
 */
var randomnumber = 0;

var loadingGif = "<img src='greybox/indicator.gif' alt='indicator'/>";

var home = new Array();
/**home[0] = "know_the_soul_print",
home[1] = "be_in_the_moment_print",
home[2] = "practice_the_religion_print",
**/
home[0] = '<img src="art/images/know_the_soul_print.png" alt="home image1" /><img src="art/images/know_the_soul_print2.png" alt="home image2" />',
home[1] = '<img src="art/images/be_in_the_moment_print.png" alt="home image1" /><img src="art/images/be_in_the_moment_print2.png" alt="home image2" />',
home[2] = '<img src="art/images/practice_the_religion_print.png" alt="home image1" /><img src="art/images/practice_the_religion_print2.png" alt="home image2" />',

randomnumber=Math.floor(Math.random()*3)

/*
 * Imageset
 */
var image_set = [{'caption': 'practice the religion of fearlessness print', 'url': '../art/images/practice_the_religion_print_large.png'},
    {'caption': 'be in the moment, be in the infinite print', 'url': '../art/images/be_in_the_moment_print_large.png'},
	{'caption': 'know the soul that is your own print', 'url': '../art/images/know_the_soul_print_large.png'},
	{'caption': 'practice the religion of fearlessness', 'url': '../art/images/practice_the_religion_large.png'},
	{'caption': 'be in the moment, be in the infinite', 'url': '../art/images/be_in_the_moment_large.png'},
	{'caption': 'know the soul that is your own', 'url': '../art/images/know_the_soul_large.png'},
	{'caption': 'ten green bottles', 'url': '../art/images/ten_green_bottles_large.png'},
	{'caption': 'shaadi stripe', 'url': '../art/images/shaadi_stripe_large.png'},
	{'caption': 'lady in red', 'url': '../art/images/lady_in_red_large.png'},
	{'caption': 'bring me sunshine', 'url': '../art/images/bring_me_sunshine_large.png'},
	{'caption': 'paperchains', 'url': '../art/images/paperchains_large.png'},
	{'caption': 'bharti', 'url': '../art/images/bharti_large.png'},
	{'caption': 'black star', 'url': '../art/images/black_star_large.png'},
	{'caption': 'lovetank.co.uk', 'url': '../art/images/lovetank_large.png'},
	{'caption': 'golden raj', 'url': '../art/images/golden_raj_large.png'},
	{'caption': 'spin', 'url': '../art/images/spin_large.png'},
	{'caption': 'sunstar', 'url': '../art/images/sunstar_large.png'},
	{'caption': 'indian summer', 'url': '../art/images/indian_summer_large.png'}];
/*
 * Function to generate "open in new window" link as W3C compliant
 */

function externalLinks() {
if (!document.getElementsByTagName) return; 
var anchors = document.getElementsByTagName("a"); 
for (var i=0; i<anchors.length; i++) { 
var anchor = anchors[i]; 
if (anchor.getAttribute("href") && 
anchor.getAttribute("rel") == "external") 
anchor.target = "_blank";
} 
} 
window.onload = externalLinks;

var lastContentID = null;

function highlight(ID,buy){

	if (typeof buy == "undefined") {
    	buy = 0;
  	}
  	

  	
	/** If the lastID is the same as the one
		currently selected then ignore otherwise
		it will fade out then fade in again
	**/
	if(lastContentID == ID){return;}

	  	var el = document.getElementById(ID);
		var elDesc = (document.getElementById(ID) != null)?document.getElementById(ID+'_description') : null;
		
		var display = document.getElementById('displaycontent');
		var pagetitle = document.getElementById('pagetitle');
		var artdesc = document.getElementById('display_artdescription');
		//var thumb = document.getElementById(ID+' thumb');
		var thumb = (document.getElementById(ID+'_thumb') != null)?document.getElementById(ID+'_thumb') : null;
		var lastContentIDThumb = (document.getElementById(lastContentID+'_thumb') != null)?document.getElementById(lastContentID+'_thumb') : null;
		
		// Remove the word print from the ID if it exists
		var mod_ID = "";
		var regex = /_print/;
		orig_ID = mod_ID = ID.replace(regex, "");
		
		//alert("print: "+ mod_ID + " " + orig_ID);
		
		// Replace lt with &lt;
		var regex = /^lt_/;
		mod_ID = ID.replace(regex, "&lt; ");
		
		// Replace - with commas
		var regex = /-/;
		mod_ID = mod_ID.replace(regex, ", ");
		
		// Replace all white space with _
		var modTitle = "";
		regex = /_/g;
		modTitle = mod_ID.replace(regex, " ");
				
		// Display the content
		//display.innerHTML = "";
		//display.style.opacity = 0;
		//display.innerHTML = "<a href='art/images/"+modTitle+"_large.png' rel='lightbox' title='"+ID+"'>"+el.innerHTML+"</a>";
		
		display.innerHTML = el.innerHTML;
		//bytefx.fade(display, 0, 100, 8);		
		
		if(buy == 1){
			display.innerHTML += "<a href=\#\" rel=\"self\" onclick=\"highlight('buy',3);\" style=\"line-height:20px;\">Buy</a><br/><a href=\#\" rel=\"self\" onclick=\"highlight('"+orig_ID+"',2);\" style=\"line-height:20px;\">View Original Painting</a><br/><a href=\"#\" onclick=\"highlight('full_set_of_limited_edition_fine_art_PRINTS',3);\" style=\"line-height:20px;\">View Full Set of Limited Edition Prints Available</a><br/><span style=\"line-height:20px;color: #b3b3b3;\">Click on image to enlarge ></span>";
			//bytefx.fade(display, 0, 100, 8);
		}
		else if(buy == 2){
			display.innerHTML += "<a href=\"#\" onclick=\"highlight('"+orig_ID+"_print',1);\" style=\"line-height:20px;\">View Limited Edition Fine Art Print</a><br/><span style=\"line-height:20px;color: #b3b3b3;\">Click on image to enlarge ></span>";
			//bytefx.fade(display, 0, 100, 8);
		}
		else if(buy == 3){
			// Back button when in the Fullset page, only way to get there is from View Full Set of Limited Edition Prints Available link
			// Therefore lastContentID will always be a print
			display.innerHTML += "<a href=\"#\" onclick=\"highlight('"+lastContentID+"',1);\">Return to Print</a><br/>";
			//bytefx.fade(display, 0, 100, 8);
		}
		else if(buy == 4){
			//Homepage
			display.innerHTML += "";
		}
		else{
			//var sidebar = document.getElementById('sidebar');
			display.innerHTML += "<span style=\"line-height:20px;color: #b3b3b3; text-align: left;\">Click on image to enlarge ></span>";
			//"<span style=\"line-height:20px;color: #b3b3b3;\">Click on image to enlarge ></span>";
			//bytefx.fade(display, 0, 100, 8);
		}
		
		// Display the pagetitle
		// pagetitle.innerHTML = "<img src='art/titles/"+modTitle+".png' alt='"+modTitle+"'/>";
		pagetitle.style.opacity = 0;
		pagetitle.innerHTML = modTitle;
		bytefx.fade(pagetitle, 0, 100, 15);
		
		// Display the description if not an art piece
		// clear the description area
		if(elDesc){
			artdesc.style.opacity = 0;
			artdesc.innerHTML = elDesc.innerHTML;
			bytefx.fade(artdesc, 0, 100, 15);
		}else{
			artdesc.innerHTML = "";
		}

		// fade out the current selected thumbnail
		if(thumb){
			bytefx.fade(thumb, 100, 50, 8);
		}
		
		// highlight the previous thumbnail
		if(lastContentIDThumb){
			bytefx.fade(lastContentIDThumb, 50, 100, 8);
		}
		
		// Store the most recest viewed image
		lastContentID = ID;
		  	
}

