// JavaScript Document


(function() {  
		
	jQuery.fn.galleryType1 = function(config){

		config = jQuery.extend({
				currentClass: 'current',
				panelWidth: '',
				panelHeight: '',
				thumWidth: 80,
				thumHeight: 60
			},config);


		var objId = $(this).attr('id');
		var targetImgs = $(this).find('img');
		var descriptions = $(this).find('.description');

		//  初期化（イメージをサムネールに変更）
		targetImgs.css({'width': config.thumWidth + 'px', 'height': config.thumHeight + 'px'});
		targetImgs.addClass('zoom');
		$j(targetImgs[0]).parent().addClass('current');
		$(this).find('.description').css({'display': 'none'});


		// 初期化（イメージパネル）
		var panelHtml = '<div class="panel"><img src="' + targetImgs[0].src + '" width="' + config.panelWidth + '" height="' + config.panelHeight + '" /></div>';
		this.prepend(panelHtml);
		var discHtml ='<div class="desc">' + $j(descriptions[0]).html() + '</div>';
		$j('#' + objId + ' .panel').append(discHtml);
		

		// 
		targetImgs.click(function() {
			$j('#' + objId + ' .panel img').attr('src', this.src);
			$j('#' + objId + ' .desc').html($j(this).next().html());
			current(this);
		});

		function current(click_obj) {
			$j.each(targetImgs, function(idx, obj) {
				if(obj == click_obj) {
					$j(obj).parent().addClass('current');
				}
				else {
					$j(obj).parent().removeAttr('class');
				}
			});
			
		}

	};
})(jQuery);
