/*
######################################################################################
######                                                                        #######
######     PORTFOLIO SCRIPTS		                                         #######
######                                                                      #######
##################################################################################
*/

/********************************************************************************/
/***** CONTENT SUPPORT FUNCTIONS ***********************************************/
/******************************************************************************/
	
var active = 0;
var transition = 'off';

portfolioShifter = function(direction,number) {
	if(transition == 'off') {
		transition = 'on';
		var photoList 	= $('#container').find('div');
		var photoCount	= photoList.length;
		var pageList 	= $('#page_list').find('a');
		var photoId;
		
		if(direction != '') {
			if(direction == 'previous') {
				if(active == 0) {
					photoId = (photoCount - 1);
				} else {
					photoId = active - 1;
				}
			} else {
				if(active == (photoCount-1)) {
					photoId = 0;
				} else {
					photoId = active + 1;
				}
			}
		} else {
			photoId = number;
		}
		
		if($(photoList[photoId]).hasClass('original-photo')) {
			$('.click-message').show();
		} else {
			$('.click-message').hide();
		}
		if(dedication[photoId].text != '') {
			if(dedication[photoId].URL != '') {
				$('.dedication').html('Photo by \'<a href="'+dedication[photoId].URL+'" rel="external title="'+dedication[photoId].text+'">'+dedication[photoId].text+'</a>\'');
			} else {
				$('.dedication').html('Photo by \''+dedication[photoId].text+'\'');
			}
		} else {
			$('.dedication').html('');
		}

		$(pageList[active]).attr({'class':''});
		$(pageList[photoId]).attr({'class':'active'});

		$(photoList[active]).fadeOut(300).add(
			$(photoList[photoId]).fadeIn(300, function() {
				active = photoId;
				transition = 'off';
			})
		);
	}
}
	
photosRollover = function(action) {
	if(action == 'over') {
		$('#photo_' + active + '_0').fadeOut(300);
	} else {
		$('#photo_' + active + '_0').fadeIn(300)
	}
}

$(document).ready(function() {
	var count = $('#container').children();
	
	if(dedication[0].text != '') {
		if(dedication[0].URL != '') {
			$('.dedication').html('Photo by \'<a href="'+dedication[0].URL+'" target="_blank" title="'+dedication[0].text+'">'+dedication[0].text+'</a>\'');
		} else {
			$('.dedication').html('Photo by \''+dedication[0].text+'\'');
		}
	}
	
	if(count.length > 1) {
		$('#page_list').show();
		$('#lnk_previous').show().click(function(e) {
			portfolioShifter('previous','');
			e.preventDefault;
		});
		$('#lnk_next').show().click(function(e) {
			portfolioShifter('next','');
			e.preventDefault;
		});
		var pageList = $('#page_list a');
		$(pageList).each(function(i) {
			var pageLink = $(pageList[i]);
			$(pageLink).click(function(e) {
				portfolioShifter('',i);
				e.preventDefault;
			});
		});
	}
	

	var divList 	= $('#container div');
	$(divList).each(function(i) {
		var main		= $(divList[i]).find('.main-photo');
		var original	= $(divList[i]).find('.original-photo');
		var imageList	= $(divList[i]).find('img');
		
		if($(divList[0]).hasClass('original-photo')) {
			$('.click-message').show();
		}
		
		if($(divList[i]).hasClass('original-photo')) {
			var transition = 'off';
			$(main).click(function() {
				if(transition == 'off') {
					transition = 'on';
					$(main).fadeOut(750, function() {
						transition = 'open';
					});
				}
			});
			$(divList[i]).click(function() {
				if(transition == 'open') {
					transition = 'on';
					$(main).fadeIn(750, function() {
						transition = 'off';
					});
				}
			});
		}							  
	});
	
});












