/** 
 *	Navigation
 *
 *	Set your previous and next arrows to display: none;
 *	If the script executes, it will display the arrows, if 
 *	javascript is disabled, then you don't have to deal 
 *	with the next and previous
 *
 *	Add this to your html page
 *	
 	<!-- InstanceBeginEditable name="head" -->
	<script src="js/jquery.js" type="text/javascript" language="javascript"></script>
	<script src="js/jquery.document.js" type="text/javascript" language="javascript"></script>
	<!-- InstanceEndEditable -->
 *	
 *	SET ID's for previous arrows and next arrows (A TAG)
 *		previous
 *		next
 *
 *	Note: If there is a next link, then the next arrow will show
 *	however, if you are on the last page the next arrow will
 *	not show. Same goes for previous.
 *
 */
$(document).ready(function(){
	
	if ($('div.people').length) {
		$('div.people img').hide();
		
		var seed = Math.floor(Math.random() * 4)+1;
		var _img = 'people_'+seed+'.jpg';
	
		$('div.people img').attr('src', 'images/People/'+_img);
		$('div.people img').show();
	}
	
	
	var files = new Array();
	var i = myposition = 0;
	var nexturl = '';
	var prevurl = '';
	var hostfile = window.location;
		hostfile = String(hostfile).split('/');
		hostfile = hostfile[hostfile.length-1];
		
	$('#mid_subnavi a').each(function(e) {	// load up all files in navigation
		var p = $(this).attr('href').split('/');
			files.push(p[p.length-1]);	i++;
			if (p[p.length-1] == hostfile) {	myposition = i;
				// APPLY CSS IF YOU LIKE: $(this).css('color', 'green');	
			}
	});
	
	if (myposition > 2) {
		$('#mid_subnavi a#previous').css('display', 'inline');
		$('#mid_subnavi a#previous').attr('href', files[myposition-2]);
	}
	
	if (myposition < (files.length)-1) {
		$('#mid_subnavi a#next').css('display', 'inline');
		$('#mid_subnavi a#next').attr('href', files[myposition]);
	}
	
	/**
	 *	Main portfolio page randomized medium sized image placement
	 */
	if ($('div.gallery_thumbs_row').length && $('#gallery_photo_thumbs').length) { // are we on the portfolio.html page
		var seed = Math.floor(Math.random() * $('#gallery_photo_thumbs div').children('a').length);
		$('#gallery_photo_rnd').attr('src', 
			$('div.gallery_thumbs_row img').eq(seed).attr('src').replace('thumb', 'med'));
	}
	
	
	if ($('#photo_container').length && $('#gallery_menu').length) {
		if ($('#gallery_menu li').length <= 1) { // if only 1 thumbnail, hide them
			$('#gallery_menu').hide();
		} else {
			$('#gallery_menu li img').eq(0).addClass('selected');
			$('#gallery_menu li img').each(function() { // attach thumbs to clickables
				$(this).css('cursor', 'pointer');
				$(this).click(function() {
					$('#gallery_menu li img').each(function() { 
						$(this).removeClass('selected'); });
					$(this).addClass('selected');
					$('img.gallery_photo').attr('src', $(this).attr('src').replace('thumb', 'med'));
				});
			});
		}
		
		$('#gallery_enlarge').css('cursor', 'pointer');
		$('#photo_container img').click(function() { 
			var p = $('img.gallery_photo').attr('src').split('/');
			var p = p[p.length-1].split('.');
				p[p.length-1] = '';
			var p = p.join('');
			var url = 'gallery/'+p+'.html';
			window.open(url, 1, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=600,height=600');
		});
	}
	
	
	if ($('#upper_nav').length) {
	
		var _local = document.location;
			_local = String(_local).split('/').pop();
			_local = String(_local).split('_').shift();
			_local = String(_local).split('.').shift();
		var _secondary = _local;
		
		switch (_local) {	// Needed for custom items
			case 'proc':
				_secondary = 'process';
				break;
				
			case 'prof':
				_secondary = 'proficiencies';
				break;
			
		}
		
		$('#upper_nav li a img').each(function() { 
			var _src = $(this).attr('src').split('/').pop();
				_src = String(_src).split('_').pop();
				_src = String(_src).split('-').pop();
				_src = String(_src).split('.').shift();
				
			if (_local == _src || _secondary == _src) { 
				$(this).removeClass('rollover');
				var _imgsrc = $(this).attr('src').split('.');
					_imgsrc[0] +='-down';
				$(this).attr('src', _imgsrc[0]+'.'+_imgsrc[1]);
			}
		
		});
		
		$('#lower_nav li a img').each(function() { 
			var _src = $(this).attr('src').split('/').pop();
				_src = String(_src).split('_').pop();
				_src = String(_src).split('-').pop();
				_src = String(_src).split('.').shift();
			
			if (_local == _src || _secondary == _src) { 
				$(this).removeClass('rollover');
				var _imgsrc = $(this).attr('src').split('.');
					_imgsrc[0] +='-down';
				$(this).attr('src', _imgsrc[0]+'.'+_imgsrc[1]);
			}
		
		});
		
		
	}
	
	// lower_nav
});