
$(document).ready(function() {
	
	$(document).pngFix(); 
	
	$.embedquicktime();
	
	$('.fancybox').fancybox();
	

	if ($('#thumbnails') !== null) {
		
		$('.jCarouselLite').jCarouselLite({
			btnNext: '.forward',
			btnPrev: '.back',
			scroll: 5,
			visible: 5,
			speed: 500
		});
		
		
		$('.jCarouselLite ul a').hover(
			function () {
				$('img', this).stop().animate({ opacity: 1 }, 250);
			}, 
			function () {
				$('img', this).stop().animate({ opacity: 0.5 }, 250);
			}
		);
		
		
		// pre-load images //
		$('#thumbnails').find('img').each(function() {
			var filename = $(this).attr('src').substr($(this).attr('src').lastIndexOf('/')+1);
			
			var m = new Image;
			var l = new Image;
			m.src = 'images/main/'+filename;
			l.src = 'images/'+filename;
		});
	
		
		 
		$('.carousel ul a').click(function() {
			var filename = $(this).children('img').attr('src').substr($(this).children('img').attr('src').lastIndexOf('/')+1);
			var caption = $(this).children('img').attr('title');
			
			if ($('.hvlog').is(':visible')) {
				$('#img1').attr('src', 'images/main/'+filename);
				$('#img1').parent('a').attr('href', 'images/'+filename);
				$('#img1').attr('title', caption);
				$('#img1').parent('a').attr('title', caption);
				$('#img1').fadeIn();
				$('.hvlog').fadeOut('normal', function() {
					$('.cliplink').show();								   
				});
			}
			
			if ($('#img1').attr('src').indexOf(filename) < 0) {	
				$('#img2').attr('src', 'images/main/'+filename);
				$('#img1').fadeOut();
				$('#img2').fadeIn('normal', function() {
					$('#img1').attr('src', $('#img2').attr('src')).show();
					$('#img1').parent('a').attr('href', 'images/'+filename);
					$('#img1').attr('title', caption);
					$('#img1').parent('a').attr('title', caption);
					$('#img2').hide();
				});
			}
			
			return false;
		});
		
		$('.cliplink').click(function() {
			if ($('.hvlog:not(:visible)')) {
				$('#img1').fadeOut();
				$('.hvlog').fadeIn('normal', function() {
					$('.cliplink').hide();								   
				});
			}
			
			return false;
		});
		
	}
});
