jQuery(document).ready(function(){
	// setup styles
	$('div').removeClass('style-reset');
	$('.gallery li').addClass('gallery-image');
	
	// add contact link
	$('a[@href="#contact"]').attr("href", "mailto:michael@mstevenson.net")
	
	// add a visual box containing the content
	$('#content')
		.wrap('<div id="box" class="resize"></div>')
		.wrap('<div id="content-wrap" class="resize"></div>')
		.parent().after('<div id="box-top"></div><div id="box-center"></div><div id="box-bottom"></div>')
	;
	
	// resize the content box relative to the page we're on
	
	
	// create an image slider
	images = $('.gallery img');
	if(images.length > 1) {
		// create navigation
		nav = '<ul id="gallery-nav">';
		for(i=0; i < images.length; i++) {
			nav += '<li'+(i == 0 ? ' class="active"' : '')+'><a href="#">'+ (i + 1) +'</a></li>';
		}
		nav += '</ul>';
		$('.gallery').parent().after(nav);
	
		// assign slider functions
		active = 0;
		width = $('.gallery-container').width();
		sliding = false;
		$('#gallery-nav li a').each(function(i){
			// assign position reference
			$(this).attr('number',i);
			$(this).click(function(){
				if(sliding) { return false; } // don't do anything if we're already on the move
				number = $(this).attr('number'); // grab position reference
			
				if(active == number) { return false; } // if the active button is clicked, do nothing
				sliding = true; // enter sliding mode
			
				if(active < number) { // move to the right
					distance = ((active * width) - (number * width));
				}
				else { // move to the left
					distance = ((active * width) - (number * width));
				}
				$('.gallery').animate({"left":'+='+distance},'slow','swing'); // slide...
				// switch active link styles
				$('#gallery-nav a[number="' + active +'"]').parent('li').removeClass('active');
				$(this).parent('li').addClass('active');
			
				active = number; // set new active
				sliding = false; // exit sliding mode
				return false; // return false so link doesn't activate
			});
		});
		if ($.browser.msie) {
			// If IE, we need to move the gallery navigation within the DOM so as to avoid a z-index bug
			$('#box-bottom').append( $('#gallery-nav') );
			// Darken the link text since IE doesn't support CSS opacity
			//$('#gallery-nav li a').css("color", "#b0ccdd")
		}
	} // end image slider	
});