var viewportwidth, viewportheight;

if ( typeof window.innerWidth != 'undefined' ) {
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	viewportwidth = window.innerWidth,
	viewportheight = window.innerHeight
} else if ( typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0 ) {
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	viewportwidth = document.documentElement.clientWidth,
	viewportheight = document.documentElement.clientHeight
} else {
	// older versions of IE
	viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	viewportheight = document.getElementsByTagName('body')[0].clientHeight
}

if ( viewportwidth > 1400 ) {
	document.write( '<link href="stylesheets/sasslarge.css" rel="stylesheet" type="text/css" />' );
}

if ( viewportwidth < 1150 ) {
	document.write( '<link href="stylesheets/sasssmall.css" rel="stylesheet" type="text/css" />' );
}

$(function() {
	if ( $( '#thumbnails div' ).length > 1 ) {
		$('<img src="images/b-next.gif" alt="" />').css({ position: 'relative', top: '-60px' }).appendTo( $('a.arrow-next') );
		$('a.arrow-next').hover( function(){ $(this).find('img').hide(); }, function(){ $(this).find('img').show(); } );
	}
	
	$( 'a.arrow-next,a.arrow-prev' ).mouseup(function(){
		this.blur();
		this.hideFocus = true;
		this.style.outline = 'none';
	});
	
	$( 'a#about-bio' ).click(function(e){
		e.preventDefault();

		if ( $( 'div#about-hire-text:visible' ).length == 1 ) {
			$( 'div#about-hire-text' ).hide( 'blind' );
			$( 'div#about-hire-text').queue( function() {			
				$( 'div#about-bio-text' ).show( 'blind' );
				$( this ).dequeue();
			});		
		} else if ( $( 'div#about-bio-text:hidden' ).length == 1 ) {
			$( 'div#about-bio-text' ).show( 'blind' );
		} else {
			$( 'div#about-bio-text' ).hide( 'blind' );		
		}
	});
	
	$( 'a#about-hire' ).click(function(e){
		e.preventDefault();

		if ( $( 'div#about-bio-text:visible' ).length == 1 ) {
			$( 'div#about-bio-text' ).hide( 'blind' );
			$( 'div#about-bio-text').queue( function() {			
				$( 'div#about-hire-text' ).show( 'blind' );
				$( this ).dequeue();
			});		
		} else if ( $( 'div#about-hire-text:hidden' ).length == 1 ) {
			$( 'div#about-hire-text' ).show( 'blind' );
		} else {
			$( 'div#about-hire-text' ).hide( 'blind' );		
		}
	});
	
	$( 'a.arrow-next' ).click(function(e){
		e.preventDefault();
		
		if ( $( '#thumbnails div' ).length > 1 ) {
			var current, next;
			current = $( '#thumbnails div:visible' );
			next    = current.next();
			
			if ( next.length ) {
				if ( next.next().length == 0 ) {
					 $(this).find('img').remove();
				}
				current.hide( 'slide' );
				next.show( 'slide', { direction: 'right' } );
				if ( $('a.arrow-prev').find('img').length == 0 ) {
					$('<img src="images/b-prev.gif" alt="" />').css({ position: 'relative', top: '-60px' }).appendTo( $('a.arrow-prev') );
					$('a.arrow-prev').hover( function(){ $(this).find('img').hide(); }, function(){ $(this).find('img').show(); } );		
				}
			}
		}
	});
	
	$( 'a.arrow-prev' ).click(function(e){
		e.preventDefault();
		
		if ( $( '#thumbnails div' ).length > 1 ) {
			var current, prev;
			current = $( '#thumbnails div:visible' );
			prev    = current.prev();
			
			if ( prev.length ) {
				if ( prev.prev().length == 0 ) {
					 $(this).find('img').remove();
				}
				current.hide( 'slide', { direction: 'right' } );
				prev.show( 'slide', { direction: 'left' } );
				if ( $('a.arrow-next').find('img').length == 0 ) {
					$('<img src="images/b-next.gif" alt="" />').css({ position: 'relative', top: '-60px' }).appendTo( $('a.arrow-next') );
					$('a.arrow-next').hover( function(){ $(this).find('img').hide(); }, function(){ $(this).find('img').show(); } );		
				}
			}
		}		
	});	
});