jQuery(function(){
/*
    $(".carousel").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".previous",
		visible: 4
    });

	$('.carousel a').click(function(){
		var $this = $(this).find('img');
		var src = $this.attr('data-src');
		var width = $this.attr('data-width');
		var height = $this.attr('data-height');
		var containerWidth = 715;
		var containerHeight = 550;
		var marginLeft = (containerWidth - width)/2;
		var marginTop = (containerHeight - height)/2;
		$('.gallery-main').css('visibility', 'hidden');
		$('#gallery-image-large').attr('src', src).attr('width', width).attr('height', height);
		$('.gallery-item').css('width', width + 'px').css('height', height + 'px').css('marginLeft', marginLeft + 'px').css('marginTop', marginTop + 'px');
		itemInfo = $(this).find('span.item-info').html();
		$('#item-info').html(itemInfo);
		$('.gallery-main').css('visibility', 'visible');
		return false;
	});

*/
if ($('body').hasClass('gallery-view'))	{
	var pageName = $('body').attr('id');
	var thumbCount = 6;
	if (pageName == 'drawings')	{thumbCount = 5};
	$.ajax({
        type: "GET",
		url: "js/sitedata.xml",
		dataType: "xml",
		success: function(xml) {
	 		//alert('got data');
			var imgData = '';
			var imgPreloadDataMain = '';
			var imgPreloadDataFull = '';
			var listData = '';
			$(xml).find(pageName + ' item').each(function(i){
				$this = $(this);
				var creationDate = $this.attr('creation-date');
				var name = $this.attr('name');
				var dimensionWidth = $this.attr('dimension-width');
				var dimensionHeight = $this.attr('dimension-height');
				var dimensions = '';
				if (dimensionWidth + dimensionHeight != '')	{
					dimensions = dimensionWidth + ' x ' + dimensionHeight + ' inches';
				}
				var mediumType = $this.attr('medium-type');
				var fullFilename = $this.attr('full-filename');
				var fullWidth = $this.attr('full-width');
				var fullHeight = $this.attr('full-height');
				var profileFilename = $this.attr('profile-filename');
				var profileWidth = $this.attr('profile-width');
				var profileHeight = $this.attr('profile-height');
				var thumbFilename = $this.attr('thumb-filename');
				var thumbWidth = $this.attr('thumb-width');
				var thumbHeight = $this.attr('thumb-height');
				var imagePath = 'images/' + pageName + '/';
				imgData = '<img src="' + imagePath + thumbFilename + '" width="' + thumbWidth + '" height="' + thumbHeight + '" data-src="' + imagePath + profileFilename + '" data-width="' + profileWidth + '" data-height="' + profileHeight + '" />';
				imgPreloadDataMain += '<img src="' + imagePath + profileFilename + '" width="1" height="1" />';
				//imgPreloadDataFull += '<img src="' + imagePath + fullFilename + '" width="1" height="1" />';
				listData += '<li><a href="#">' + imgData + '<span class="item-info"><span class="item-title">' + name + '</span><span class="item-type">' + mediumType + '</span><span class="item-size">' + dimensions + '</span></span></a></li>';
			});
			$('body').append('<div id="preload">' + imgPreloadDataMain + '</div>');
//			alert(imgData);
			$('.carousel ul').empty().append(listData);
			    $(".carousel").jCarouselLite({
			        btnNext: ".next",
			        btnPrev: ".previous",
					visible: thumbCount
			    });
			
				$('.carousel a').click(function(){
					var $this = $(this).find('img');
					var src = $this.attr('data-src');
					var width = $this.attr('data-width');
					var height = $this.attr('data-height');
					var containerWidth = 715;
					var containerHeight = 550;
					var marginLeft = (containerWidth - width)/2;
					var marginTop = (containerHeight - height)/2;
					$('.gallery-main').css('visibility', 'hidden');
					$('#gallery-image-large').attr('src', src).attr('width', width).attr('height', height);
					$('.gallery-item').css('width', width + 'px').css('height', height + 'px').css('marginLeft', marginLeft + 'px').css('marginTop', marginTop + 'px');
					itemInfo = $(this).find('span.item-info').html();
					$('#item-info').html(itemInfo);
					$('.gallery-main').css('visibility', 'visible');
					return false;
				});
			
//			$('#thumbnails').append(imgData);
		}
	});
	
}

if ($('body').hasClass('shows'))	{
	$(".tweet").tweet({
		username: "matthewolyphant",
		join_text: "auto",
		avatar_size: 64,
		count: 10,
		auto_join_text_default: "I said,", 
		auto_join_text_ed: "I",
		auto_join_text_ing: "I were",
		auto_join_text_reply: "I replied to",
		auto_join_text_url: "I was checking out",
		loading_text: "loading tweets..."
	});
}


/*
	$('#gallery-image-large').click(function(){
		viewportWidth =  $(window).width();
		viewportHeight =  $(window).height();
		imageWidth = $('#gallery-item').outerWidth();
		imageHeight = $('#gallery-item').outerHeight();
		console.log('viewportWidth: ' + viewportWidth);
		console.log('viewportHeight: ' + viewportHeight);
		console.log('imageWidth: ' + imageWidth);
		console.log('imageHeight: ' + imageHeight);

		

		$('body').append('<div id="modal-overlay"></div>').append('<div id="modal-overlay-content"></div>');
		$('#gallery-item').clone().appendTo('#modal-overlay-content');
		return false;
	});	


	$('#gallery-image-large').click(function(){
		$('#gallery-image-zoom').empty();
		$('#gallery-item').clone().css('margin', '0px').appendTo('#gallery-image-zoom');
		$('#gallery-image-zoom').dialog('open');
		$('#gallery-image-zoom').show("scale", {}, 1000);
		console.log('clicked');
		return false;
	});	
$('#gallery-image-zoom').dialog({
	modal:true,
	autoOpen:false
});


jQuery.preloadImages = function()	{
	preloadElement = '';
  for(var i = 0; i<arguments.length; i++)	{
    preloadElement += '<img src="' + arguments[i] + '" />';
  }
  $('.container').append('<div id="preload">' + preloadElement + '</div>');
}
$.preloadImages("images/artwork/featured/Black-SilverJapaneseCharacter.jpg", "images/artwork/featured/Black-YellowSkyscraper.jpg", "images/artwork/featured/BlackWritingonWhite.jpg", "images/artwork/featured/blessed.jpg", "images/artwork/featured/blue.jpg", "images/artwork/featured/bluecat.jpg", "images/artwork/featured/Chima.jpg", "images/artwork/featured/city2.jpg", "images/artwork/featured/city3.jpg", "images/artwork/featured/city4.jpg", "images/artwork/featured/city5.jpg", "images/artwork/featured/city6.jpg", "images/artwork/featured/City7.jpg", "images/artwork/featured/Figure1.jpg", "images/artwork/featured/Figure2.jpg", "images/artwork/featured/Figure3.jpg", "images/artwork/featured/hook1.jpg", "images/artwork/featured/hook2.jpg", "images/artwork/featured/Martini2.jpg", "images/artwork/featured/redsun.jpg", "images/artwork/featured/redwine.jpg", "images/artwork/featured/SFPainting.jpg", "images/artwork/featured/shine.jpg", "images/artwork/featured/Valentine.jpg", "images/artwork/featured/YellowJapaneseCharacter.jpg");
*/
});