//
jQuery.fn.extend({
	zoomIn:function(){
		return $(this).each(function(){
			var i = $(this).data('index');
			$(this).css({zIndex:1}).stop().animate({width:'250px',height:'100px', left:(210 * i - 25)+'px', top:'0px'}, 300).children('img').stop().animate({width:'250px',height:'100px'}, 300);
			$('#navigation-indicator li:nth-child('+(i+1)+')').addClass('hovered');
		});
	},
	zoomOut:function(){
		return $(this).each(function(){
			var i = $(this).data('index');
			$(this).css({zIndex:0}).stop().animate({width:'200px',height:'80px', left:(210 * i)+'px', top:'10px'}, 300).children('img').stop().animate({width:'200px',height:'80px'}, 300);
			$('#navigation-indicator li:nth-child('+(i+1)+')').removeClass('hovered');
			});
	}
});
(function(){
	var hncs = 0, hncw = 0, hncx = 0, dx = 0, scrt = null, bs = 10;
	var scrollNavi = function(){
		var thread = function(){
			hncx += dx;
			if (hncx > 25) {
				hncx = 25;
				clearInterval(scrt);
				scrt = null;
			}
			else if (hncx < 8850 - hncw * 10) {
				hncx = 8850 - hncw * 10;
				clearInterval(scrt);
				scrt = null;
			}
			var st = parseInt(-hncx / 2100 + 0.5);
			$('#navigation-indicator li').removeClass('shown').slice(st, st+4).addClass('shown')
			$('#navigation-contents').css({left:hncx / 10})
		};
		scrt = setInterval(thread, 20)
	};
	var scrollHandler = function(e){
		if ($('#navigation-contents').is(':animated')) {
			$('#navigation-contents').stop();
			hncx = $('#navigation-contents').position().left * 10;
		}
		dx = -(e.clientX - $(this).offset().left - 450) / bs;
		if (scrt === null) { 
			scrollNavi();
		}
	};
	jQuery(function($){
		if (!($('body').is('.editable-mode') || $('body').is('.action-post'))) {
			if ($.browser.msie && $.browser.version <= 8) {
				bs = 3;
				var wpr = $('#wrapper');
				wpr.before('<span id="shadow"/>');
				$('#shadow').width(wpr.width()).height(wpr.height()).css({
					zIndex:-1,
					position:'absolute',
					top:'-6px',
					left:(wpr.offset().left - 6)+'px',
					backgroundColor:'#4c4c4c',
					filter:"progid:DXImageTransform.Microsoft.blur(pixelradius='6', makeShadow=false)",
					filter:"progid:DXImageTransform.Microsoft.blur(pixelradius='6', makeShadow=false)"
				})
			}
			hncs = $('#navigation-contents .cw-editable-link').length;
			hncw = 210 * hncs;
			hncx = (450 - hncw / 2) * 10;
			$('#navigation-contents .cw-editable-link').each(function(i){
				$(this).css({
					position:'absolute',
					top:'10px',
					left:(210 * i)+'px',
					margin:0
				}).data('index', i);
				$('#navigation-indicator').append('<li id="indicator-'+i+'"><a href="#"></a></li>');
			}).hover(function(){
				$(this).zoomIn()
			}, function(){
				$(this).zoomOut()
			}).filter(':last').css({
				marginRight:0
			});
			$('#navigation-indicator li a').live('click', function(){
				return false;
			});
			$('#navigation-contents').width(hncw).css({top:0, left:(hncx / 10)+'px'});
			$(window).load(function(){
				$('#navigation-contents').animate({left:'25px'}, 2000, 'easeOutQuart', function(){
					hncx = $(this).position().left * 10;
				});
			});
			$('#horizontal-navigation').mousemove(scrollHandler).mouseover(scrollHandler);
		}
	});
})(jQuery);
