/* Copyright (c) 2008 Andreas Timm | symmetrics gmbh (http://symmetrics.de)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $CreateDate: 18.11.2008$
 * $LastChangedDate: 18.11.2008$
 *
 * Version: 0.2 mod random
 *
 * Requires: jQuery 1.2.6+
 */
(function($)
{
	var params = new Object ;
	var last_image = null ;

	$.fn.extend ({

		/**
		 * contAccordion
		 *
		 * @param	Object		v:
		 *				String		id:
		 *				String		images:
		 **/
		SimplSlideShow: function( v )
		{
			if ( v.images === undefined )
				v = { images: v } ;

			v.images = v.images.split(",") ;

			if ( v.id === undefined )
				v.id = "sss1" ;

			params[v.id] = { z: 0, images: v.images, dom: $(this) } ;

			$(this).html("<div class='simpl_slide_show_0'></div><div class='simpl_slide_show_1'></div>");

			$(".simpl_slide_show_0,.simpl_slide_show_1").css({
				position: "absolute",
				width: "100%",
				height: "182px",
				display: "none"
			});

			get_next ( v.id ) ;
		}
	});


	/**
	 * get_next
	 *
	 * @param	String		id:
	 **/
	function get_next ( id )
	{
		var last_dom = params[id].dom.children(".simpl_slide_show_"+params[id].z) ;
		params[id].z = params[id].z == 0 ? 1 : 0 ;
		var next_dom = params[id].dom.children(".simpl_slide_show_"+params[id].z) ;

		last_dom.css({zIndex:1});
		next_dom.css({
			zIndex:2,
			background: "url(" + params[id].images[ get_random ( id ) ] + ")"
		}).fadeIn(2000,function(){
			last_dom.css({display:"none"});
			setTimeout ( function (){  get_next(id) }, 4000 );
		});
	} ;


	/**
	 * get random
	 *
	 * @param	String		v:
	 * @return	Number
	 **/
	function get_random ( id )
	{
		var image = null ;
		do
			image = Math.round ( Math.random() * ( params[id].images.length - 1 ) ) ;
		while ( last_image == image ) ;
		last_image = image ;
		return image ;
	} ;


})(jQuery);