jQuery(function(){

	if(jQuery('#clickPlay > li').length > 1){

		var initItem = jQuery('#clickPlay > li').eq(0);			

		var clickI = 0;

		jQuery('#clickPlay').after('<div id="fullImg"><img src="' + initItem.children('a').attr('href') +'" alt="" class="on" /></div>');

		initItem.addClass('on');

		jQuery('#clickPlay > li').click(function(){

			changeImg(jQuery(this));

			return false;

		});

		// anto play ------------------ 

		var _autoPlay = 0;

		var itemI = jQuery('#clickPlay > li.on').index();

		var itemL = jQuery('#clickPlay > li').length - 1;

		_autoPlay = setInterval(function(){ itemI = itemI === itemL ? 0 : itemI+1; autoPlay(itemI);}, 6000);

		

		jQuery('#clickPlay').parent().hover(function(){

			clearInterval(_autoPlay);

		}, function(){

			itemI = jQuery('#clickPlay > li.on').index();

			_autoPlay = setInterval(function(){ itemI = itemI === itemL ? 0 : itemI+1; autoPlay(itemI);}, 6000);

		})

	}

	function changeImg($this){

		var fullImgUrl = $this.children('a').attr('href');

		$this.addClass('on').siblings().removeClass('on');

		

		if(clickI === 0){

			jQuery('#fullImg > img').after('<img src="'+fullImgUrl+'" style="display:none;" />');

		};

		jQuery('#fullImg > img').eq(clickI%2).stop(false,true).fadeOut(600)

			.siblings('img').attr('src', fullImgUrl).stop(false,true).fadeIn(800);

		clickI++;

/*			jQuery('<img />').load(function(){

			$thisImg = jQuery(this);

			$thisImg.css('zIndex', 0);

			jQuery('#fullImg > img.on').fadeOut(500, function(){

				jQuery(this).removeClass('on').remove();

				$thisImg.addClass('on');

				jQuery('#fullImg > p').html(getText($this)).slideDown(200);

			});

		}).css('zIndex', 1).attr('src', fullImgUrl).prependTo('#fullImg');

*/

	}

	function autoPlay(i){

		changeImg(jQuery('#clickPlay > li').eq(i));			

	}		

	function getText($this){

		var theText = '<strong>' + $this.children('a').attr('title') + '</strong>';

		if(jQuery('span', $this).length){

			theText += '<span>' + jQuery('span', $this).text() + '</span>';

		}

		return theText;

	}

})
