var galleryThumbnails=new Array(
		/* 0 */ 'http://www.nmu.edu/images/hp_images/cycle12/12_chat_t.jpg',
		/* 1 */ 'http://www.nmu.edu/images/hp_images/cycle12/12_iceaxe_t.jpg',
		/* 2 */ 'http://www.nmu.edu/images/hp_images/cycle12/12_demo_t.jpg',
		/* 3 */ 'http://www.nmu.edu/images/hp_images/cycle12/12_dive_t.jpg',
		/* 4 */ 'http://www.nmu.edu/images/hp_images/cycle12/12_talk_t.jpg'
);
var galleryImages=new Array(		
		/* 0 */ 'http://www.nmu.edu/images/hp_images/cycle12/12_chat.jpg',
		/* 1 */ 'http://www.nmu.edu/images/hp_images/cycle12/12_iceaxe.jpg',
		/* 2 */ 'http://www.nmu.edu/images/hp_images/cycle12/12_demo.jpg',
		/* 3 */ 'http://www.nmu.edu/images/hp_images/cycle12/12_dive.jpg',
		/* 4 */ 'http://www.nmu.edu/images/hp_images/cycle12/12_talk.jpg'
);
var galleryTitles=new Array(
		/* 0 */ '',
		/* 1 */ '',
		/* 2 */ '',
		/* 3 */ '',
		/* 4 */ ''
);
var galleryAlts=new Array(
		/* 0 */ 'NMU President Les Wong talks with students about diversity issues during a "Let\'s Chat" session as one of Northern\'s Martin Luther King Week activities. <a href="http://www.thenorthwindonline.com/?p=3863285">Full story</a>',
		/* 1 */ 'NMU senior Frank King prepares for his first ice climb near Pictured Rocks National Lakeshore, where some of the best ice climbing in the nation is found not far from Northern\'s campus. <a href="https://www.google.com/search?hl=en&sugexp=pfwl&tok=gQFZP-DdH2PW5tMFUqhYvg&cp=15&gs_id=1m&xhr=t&q=michigan+ice+fest&safe=on&gs_sm=&gs_upl=&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&biw=1280&bih=800&um=1&ie=UTF-8&tbm=isch&source=og&sa=N&tab=wi&ei=WY8hT_mwIsTksQL828z-CA">Michigan Ice Fest Photos</a>',
		/* 2 */ 'Clayton Powell (left), Dave Pfeiffer (right) and Steve Jarvis (not shown) earned third place in the recent Intel-NMU Computer Continuum App Programming Contest for their mobile phone app design, which they presented virtually to judges at Intel headquarters in Oregon.',	
		/* 3 */ 'Freshman diver Sophia Garris prepares for the Great Lakes Intercollegiate Athletic Conference Championships on Feb. 8-11. NMU is co-hosting the event with the University of Indianapolis at the Jenison Aquatics Center in Jenison, Mich. <a href="http://webb.nmu.edu/SportsAthletics/Sports/WomensSwimmingAndDiving/">Swimming and Diving</a>',
		/* 4 */ 'Northern\'s winter semester is in full swing and these NMU students enjoy the campus\' fresh coat of snow as they walk through the academic mall to class. <a href="http://www.acs.nmu.edu/4.3.php">NMU webcams</a>'
);

var imageWidth='590';
var imageHeight='394';
var thumbWidth='110';
var thumbHeight='73';
 
$(document).ready(function() {
	$('#sub0').click(function(){ imageChange(0); });
	$('#sub1').click(function(){ imageChange(1); });
	$('#sub2').click(function(){ imageChange(2); });
	$('#sub3').click(function(){ imageChange(3); });
	$('#sub4').click(function(){ imageChange(4); });
 
	var defaultCaption = $('#image_caption').html(); /* store the default title and caption for use if one is not supplied */
	
	function imageChange(intOne){
		var alts = '<my>'+galleryAlts[intOne]+'</my>'; /* wrap a tag around this array info so jquery can easily see the text */
		var alts = $(alts).text(); /* strip out the html data for display in the alt text */
		var alts = alts.replace(/"/g, "" ); /* strip out double quotes from the alt text */
		$('.gallery_main_image').replaceWith('<div id="sub0'+intOne+'" class="gallery_main_image hidden"><img id="hp_main_image" class="image'+intOne+'" src="'+galleryImages[intOne]+'" title="'+galleryTitles[intOne]+'" alt="'+alts+'" width="'+imageWidth+'" height="'+imageHeight+'" /></div>'); 
		$(".gallery_main_image").fadeIn("slow");
		$('div').removeClass('selected_image');
		$('#sub'+intOne+'').addClass('selected_image');
		if(galleryTitles[intOne] != '' || galleryAlts[intOne] != '')
			$('#image_caption').replaceWith('<div id="image_caption"><h4>'+galleryTitles[intOne]+'</h4><p>'+galleryAlts[intOne]+'</p></div>');
		else
			$('#image_caption').replaceWith('<div id="image_caption">'+defaultCaption+'</div>');
	}
	
	function thumbnailPopulate(){
		for(var i=0; i<galleryThumbnails.length; i++){
			var alts = '<my>'+galleryAlts[i]+'</my>';
			var alts = $(alts).text();
			var alts = alts.replace(/"/g, "" );
			$('#sub'+i+'').append('<img class="image'+i+'" src="'+galleryThumbnails[i]+'" title="'+galleryTitles[i]+'" alt="'+alts+'" width="'+thumbWidth+'" height="'+thumbHeight+'" />');
			}
	}
	
	thumbnailPopulate(); /* write in the thumbnails */
	var randomnumber=Math.floor(Math.random()*4)
	imageChange(randomnumber); /* set the default image, highlight it and write out the title/caption */
	
	//this shoud work now that the width/height is being set by variables.  Make sure the variables are updated when the dimensions change and this will write in a different stylesheet to adjust the dispaly
	//var imageWidth=$("#gallery_main_images img").width(); /* check the image width and use the appropriate stylesheet */
	//alert(imageWidth);
	//if(imageWidth == 393)
		//$('head').append('<link rel="stylesheet" href="http://webb.nmu.edu/Webb/CSS/Redesign/Custom/nmu_homepage_alt.css" type="text/css" />');
});
