window.log = function(){
	log.history = log.history || [];  
	log.history.push(arguments);
	arguments.callee = arguments.callee.caller;  
	if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
(function(b){
	function c(){}
	for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c
		})(window.console=window.console||{});


(function( $ ){		

	var pager_click = function(event)
	{
		if( ! jQuery(this).parent().hasClass('actived'))
		{
			show_image(jQuery(this).parent().index());
		}

		event.preventDefault();
		return;
	};
	
	var show_image = function(index)
	{
		images.find('.actived').fadeOut('normal', function(){
			jQuery(this).removeClass('actived')
		});
		
		images.find('li:eq(' + index + ')').fadeIn('normal', function(){
			jQuery(this).addClass('actived')
		});

		pager.find('.actived').removeClass('actived');
		pager.find('li:eq(' + index + ')').addClass('actived');
	};

	var methods = {
		init : function( element, options ) {
			
			if( ! element.data('bannerInitialized') )
			{				
				images = element.find('.images');
				images.hover(function(){ $(this).addClass('hover')}, function(){$(this).removeClass('hover')});
				pager = element.find('.pager');
				pager.find('a').click(pager_click);
				element.data('bannerInitialized',  '1');
				
				setTimeout('$("#' + element.attr('id') + '").banner("play")', element.settings.time);
			}
			
			return element;
		},
		
		next : function(element) {
			var idx = element.find('.images .actived').index();
			var num_imgs = element.find('.images li').length;
			
			idx = ((idx +1 ) < num_imgs) ? idx +1 : 0;
			show_image(idx);
			
			return element;
		},
		
		prev : function(element) {
			var idx = element.find('.images .actived').index();
			var num_imgs = element.find('.images li').length;
			
			idx = ( idx == 0 ) ? ( num_imgs -1 ) :  idx - 1;
			show_image(idx);
			
			return element;
		},
		
		play: function(element) {
			if( ! element.find('.hover').length )
			{
				methods.next(element);
			}
			setTimeout('$("#' + element.attr('id') + '").banner("play")', element.settings.time);
		}
	};

	$.fn.banner = function( method ) {
		var pager;
		var images;
		var $element = $(this);
		
		this.settings = {
			time : 4000
		};

		$.extend(this.settings, method);
		
		
		// Method calling logic
		if ( methods[method] ) 
		{
			return methods[ method ]( this, Array.prototype.slice.call( arguments, 1 ));
		} 
		else if ( typeof method === 'object' || ! method ) 
		{
			return methods.init( this, method);
		} 
		else 
		{
			$.error( 'Method ' +  method + ' does not exist on jQuery.banner' );
		}    
		
		return this;
	};
})( jQuery );


(function($) {
	$.fn.watermark = function(css, text) {
		return this.each(function() {
			var i = $(this), w = 1;
			(i.val() == text) && i.val('');
			i.focus(function() {
				(i.val() == text) && w && !(w = 0) && i.removeClass(css).data('w', 0).val('');
			})
			.blur(function() {
				(i.val() == '') && (w = 1) && i.addClass(css).data('w', 1).val(text);
			})
			.closest('form').submit(function() {
				(i.val() == text) && w && i.val('');
			});
			i.data('w_text', text);
			i.trigger('blur');
		});
	};
	$.fn.removeWatermark = function() {
		return this.each(function() {
			var i = $(this);
			i.removeData('w') || ((i.val() == i.data('w_text')) && i.val('')) || i.removeData('w_text');
		});
	};
})(jQuery);

