function myInit() {

	$("a[href^='http:']").not("[href*='alexcalinescu.com']").attr('target','_blank');
	
	$('#navigation ul li:has(li.selected)').addClass('selected');
	
	$('#navigation > ul > li:last').addClass('last');	
	$('#navigation > ul > li.last').prev().addClass('penultimate');
	
	$('#subNavigation ul li:has(li.selected)').addClass('selected');
	
	$('ul.archive > li > a').click( function() {		
		$('ul.archive > li').removeClass("selected");		
		$(this).parent().toggleClass("selected");		
		return false;
		});
	
	
	$('#photoSlideshow').cycle({ 
		speed: 500, 
		timeout: 4000, 
		nowrap: true,
		end: function() {              	
			var imgWidth = ( ( $('#photoSlideshow li:last img').attr('width') - 50 ) / 2 );
			$('#replay').css('left',imgWidth);
			$('#replay').fadeIn();
			}
		});


	}

function replay() {
	document.location.reload();
	}
function loadImage(workId) {
	
	if (!workId) {
		return;
		}
		
	
		$.ajax({
			type: "POST",
			url: "/loadImage.php",
			data: "workId="+workId,
			success: function(returned){	
				myData = returned.split("~");					
				$('#imageInfo').html(myData[0]).fadeIn(200);	
				}
			});			
		
	}

function unloadImage() {
	$('#imageInfo').fadeOut(50);
	return false;
	}


function galleryScrollLeft() {		
	if (scrollToInt > 0) {
		scrollToInt = parseInt(scrollToInt) - parseInt(scrollIncrement);
		scrollThumbnails(0);
		$('#galleryScrollLeft').fadeOut();
		$('#galleryScrollLeft').fadeOut(200, function () {		
			$('#galleryScrollRight').fadeIn();
			});		
		
		
		}
	}
function galleryScrollRight() {	
	if (scrollToInt < (maxWidth-paneWidth)) {
		scrollToInt = parseInt(scrollToInt) + parseInt(scrollIncrement);
		scrollThumbnails(scrollToInt);
		} 
	}

function scrollToImage(imageId) {
	
	containerOffset = $('#thumbnails').offset();	
	thumbOffset = $('#thumb_'+imageId).offset();	
	scrollPixel = thumbOffset.left - containerOffset.left;	
	scrollThumbnails(scrollPixel)
	
	}
	
function scrollThumbnails(scrollPixel) {	
	
	if (scrollPixel < 0) {
		scrollPixel = 0;
		}
		
	$('#thumbnails').scrollTo(  scrollPixel, { axis:'x', duration:1000 } );	
	scrollToInt = parseInt(scrollPixel);	
	if (scrollPixel >= (maxWidth-paneWidth)) {
		//$('#galleryScrollRight').addClass('disabled');
		$('#galleryScrollRight').fadeOut(200, function () {		
			$('#galleryScrollLeft').fadeIn();
			});		
		}
	if (scrollPixel > 0) {
		//$('#scrollUp').fadeIn('normal');
		$('#galleryScrollLeft').removeClass('disabled');
		}
	if (scrollPixel < (maxWidth-paneWidth)) {
		//$('#scrollDown').fadeIn('normal');
		$('#galleryScrollRight').removeClass('disabled');
		}
	if (scrollPixel == 0) {
		//$('#scrollUp').fadeOut('normal');
		$('#galleryScrollLeft').addClass('disabled');
		}
	}