jQuery.fn.showcase = function(settings) {
    var settings = jQuery.extend({
        speed: 'slow'
    }, settings);
    return this.each(function(i) {
        aShowCase.init(settings, this);
    });
};

var aShowCase = {
	current: 0,
	interval: [],
	elements: [],
    init: function(s, e) {
	  current = 0;
	  elements = $(e).children('.element');
	  aShowCase.fill(e);
    $('.infoZone', e).slideDown('slow');
	  $('a.prev').click(aShowCase.prev);
	  $('a.next').click(aShowCase.next);
	  $('a.trig').toggle(aShowCase.pause, aShowCase.play);
	  aShowCase.play(e);
    },
    
	prev: function(e) {
	   $('.infoZone', e).slideUp('fast');
	   $(elements[current--]).fadeOut(1, function(){
		if(current < 0) {
			current = elements.length - 1;
		}
		aShowCase.fill(e);	
	   $(elements[current]).fadeIn(1, function(){
		 $('.infoZone', e).slideDown('slow');
	   });	   
	   
	   });
	   return false;
	},
	next: function(e) {
	   $('.infoZone', e).slideUp('fast');
	   $(elements[current++]).fadeOut(1, function(){
		   if(current > (elements.length - 1)) {
			 current = 0;
		   }
		   aShowCase.fill(e);
		   $(elements[current], e).fadeIn(1, function(){
 			 $('.infoZone').slideDown('slow'); 
		   });	   
	   });
	   return false;
	},
	fill: function(e) {
	  $('.infoZone h4', e).text($(elements[current]).attr('caption'));
	  $('.infoZone p', e).text($(elements[current]).attr('teaser'));
	   	  $('.infoZone p', e).append('<div style="position: relative; left: 320px; "><img src="http://www.sinchew-i.com/sites/all/modules/showcase/img/more.png">&nbsp;<a style=" position: relative; top: -2px; font-weight: bold; color: #FFF; font-size: 12px; text-decoration: none;" href="'+$(elements[current]).attr('node')+'">more...</a></div>');	
// 	  $('.infoZone p', e).append(' <a style="color: #FFF; font-size: 12px; text-decoration: none;" href="'+$(elements[current]).attr('node')+'"><img src="">《全文》</a>');	
	},
	play: function(e) {
		$('a.trig').empty().append('<a class="trig" href="javascript: void(0)"><img src="http://www.sinchew-i.com/sites/all/modules/showcase/img/pause.jpg" border="0" />');
	 interval = window.setInterval(aShowCase.next, 6000);		
	},
	pause: function(e) {
		$('a.trig').empty().append('<a class="trig" href="javascript: void(0)"><img src="http://www.sinchew-i.com/sites/all/modules/showcase/img/play.jpg" border="0" />');
	  clearInterval(interval);
	}
};