﻿/**
 * jquery.floatbox.run.js
 * @vertion - 19:13 2009/02/24
 */

(function() {
	
	// Windows 2000
	var ua = navigator.userAgent;
	if (ua.match(/Win(dows )?(NT 5\.0|2000)/) && $.browser.msie) return;
	
	$(document).ready(function(){
		
		var a = $('ul#searchResult a');
		var index, href;
		var length = a.length;
		
		Kaas.loadJavaScript('ie6hideSelects');
		
		function init(e) {
			
			$.floatbox({
				
				boxConfig: {
					position: ($.browser.msie) ? 'absolute': 'fixed',
					top: '50%',
					left: '50%',
					// backgroundColor: '#fff',
					zIndex: 9,
					width: '980px',
					height: '500px',
					margin: '-250px 0 0 -490px',
					display: 'none'
				},
				
				ajax: {
					url: href, // request url
					params: 'index=' + index, //post parameters
					before: '<p id="preloader">Loading content</p>', //loading message while the request is being processed
					// extend
					onComplete: function() {
						createPager(index, length);
						changeImage();
						// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2009/02/24 追記・修正 1 Start
						$('thumbnails img').ready(function() {
							Kaas.arrangeImages(Kaas.$('thumbnails'));
						});
						// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2009/02/24 追記・修正 1 End
					}
				},
				
				fade: true
				
			});
			
			if (Kaas.isIEVer('6.0')) Kaas.ie6hideSelects.hide();
			
			return e;
			
		}
		
		a.click(function(e) {
			
			index = a.index(this);
			href = this;
			init(this);
			
			return false;
			
		});
		
		function createPager(i, l) {
			
			var next = (i < l - 1)? $('ul#thumbnails').after('<span id="next">next</span>') : null;
			var prev = (i > 0)? $('ul#thumbnails').after('<span id="prev">prev</span>') : null;
			
			$('#next').css({ 'cursor': 'pointer' }).bind('click', function(e) {
				
				$('#floatbox-box').fadeOut(200, function() {
					$('#floatbox-box').remove();
					index++;
					href = a[index].href;
					init(this);
				});
				
				return false;
				
			});
			
			$('#prev').css({ 'cursor': 'pointer' }).bind('click', function(e) {
				
				$('#floatbox-box').fadeOut(200, function() {
					$('#floatbox-box').remove();
					index--;
					href = a[index].href;
					init(this);
				});
				
				return false;
				
			});
			
		}
		
		function changeImage() {
			
			var mainImage = document.getElementById('floatboxContainer').getElementsByTagName('h1')[0].getElementsByTagName('img')[0];
			var shared = mainImage.src;
			var shared2 = mainImage.src;
			
			shared2 = shared2.substr(shared2.lastIndexOf("/",shared2.length) + 1,14);
			
			$.each($('ul#thumbnails li'), function(i, n) {
				n.id = i;
			}).css({ 'cursor': 'pointer' })

			.bind('mouseenter', function(e) {
			
			// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2009/02/24 追記・修正 2 Start
			    var num = parseInt(this.id) + 2; 			    
				$('#floatboxContainer h1 img').attr('src', '../pic/' + shared2 + '_' + num + '.jpg');
				$('#floatboxContainer h1 img').load(function() {
					if (parseInt(this.width) > parseInt(this.height)) this.className = 'horizontal';
				});
				
			}).bind('mouseleave', function(e) {
			
				mainImage.src = shared;
				Kaas.removeClass(mainImage, 'horizontal');
				
			});
			
			// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2009/02/24 追記・修正 2 End
			
		}
		
	});
	
})();

