//initialize.js
///* 20111122 jun fujimura */
///* top display content */

$(function(){
	$('#contents .display-control').append('<div class="target-frame"></div>');
	$('#contents .display-control ul.display li:not(:first-child)').css( { zIndex:1, opacity:0 } );

	if(ie6()) {
		DD_belatedPNG.fix('#contents .display-control .target-frame');
	}

	var point = {
			1 : '6px' ,
			2 : '68px' ,
			3 : '130px'
		},
		tm = null,
		$d = $('#contents .display-control ul.control .display a'),
		$c = $('#contents .display-control ul.control .control a'),
		$t = $('#contents .display-control .target-frame');



	/* mv */
	function IntervalModel(){}
	IntervalModel.prototype = {
		timeid           : null,
		interval         : 5000,
		resetartInterval : 8000
	};

	function IntervalView(){}
	IntervalView.prototype = { 
		current: 1,
		stop   : function(MODEL){
					clearInterval( tm.timeid );
					MODEL.timeid = null;
				},
		start  : function(MODEL){
					this.stop(MODEL);
					if( MODEL.timeid !== null ) return;
					MODEL.timeid = setInterval( this.next, MODEL.interval );
				},
		next  : function(){
					this.current++;
					if( point[current] === undefined ) current = 1;
					change( $d , $c , current);
				}
	};

	tm = new IntervalModel();
	tv = new IntervalView();
	tv.start(tm);

	$('#contents .display-control ul.control li a').click(function(){
		var li = $($(this).get(0).parentNode);
		current = li.index()+1;
		tv.stop(tm);
		tm.timeid = setTimeout( function(){ tv.start(tm); }, tm.resetartInterval - tm.interval );
		change( $d , $c , current);
		return false;
	});


	/* c */
	function change( $d , $c , t ) {
		$t.stop().animate( { left:point[t] }, 600, "easeOutQuart" );
		$('#contents .display-control ul.display li:not(:nth-child(' + t + '))').stop().css( { zIndex:1 } ).animate( { opacity:0 } , 600, "easeOutQuart" );
		$('#contents .display-control ul.display li:nth-child(' + t + ')').stop().css( { zIndex:2 } ).animate( { opacity:1 } , 600, "easeOutQuart" );
	}

	function ie6() {
		if(this.ie6 !== undefined) return this.ie6;
		if(!jQuery.support.opacity){
			if(!jQuery.support.style){
				if (typeof document.documentElement.style.maxHeight == "undefined") {
					this.ie6 = true;
					return true;
				}
			}
		}
		this.ie6 = false;
		return false;
	}
});

