/*------------------------------------------------------*/
/*  init  */
/*------------------------------------------------------*/
			
	$(document).ready(function(){

		//setSelectBoxes();

		slide_shows = new Array();
		slide_delay = 10;
		slide_speed = 1000;
		slide_time = 3000;
		slide_time_slow = 1000;
		
		i = 0;
		$("#images").each(function(){

			numChilds = numChildren(this);
			if (numChilds > 1){
			
				slide_show = new Object();
				slide_show.target = this;
				slide_show.my_id = this.id;
				slide_show.current = 0;
				slide_show.num_slides = numChilds;

				if (slide_show.num_slides > 1){
					slide_show.timer = window.setTimeout('start_interVal('+i+')', slide_delay);			
				}else{
					//$("#"+this.id+"_nav").hide();
				}
				slide_shows.push(slide_show);
				i++;
			}

		});

	});
	

/*------------------------------------*/
/*  slideshow	*/
/*------------------------------------*/

	function numChildren(node){
		if (typeof node != 'undefined') {
		  if (typeof node.children == 'undefined') {
			var num = 0;
			for(elem in node.childNodes){
				if(node.childNodes[elem].nodeType == 1){
					num ++;
				};
			}
			return num;
		  }else{					
			return node.children.length;
		  }
		} 
	}


	function start_interVal(num){				

		SlideshowNext(num);
		slide_shows[num].timer = window.setInterval('SlideshowNext('+num+')', slide_time);
	}

	slideTimes = 0; 
	lastSlideFunction = "";
	function SlideshowNext(show_num){

		if (lastSlideFunction == "user"){
			clearTimeout(slide_shows[show_num].timer);
			slide_shows[show_num].timer = window.setInterval('SlideshowNext('+show_num+')', slide_time);
		}
		
		showInfo = slide_shows[show_num];

		if (showInfo.current >= showInfo.num_slides){
			showInfo.current = 0;
		}	

		tar_id = showInfo.target.id;
				
		
		$("#"+tar_id+" > img").css("z-index",1);				
		$("#"+tar_id+" :eq("+(showInfo.current-1)+")").css("z-index",14);
		if (slideTimes != 0){
			$("#"+tar_id+" :eq("+showInfo.current+")").hide();
		}
		$("#"+tar_id+" :eq("+showInfo.current+")").css("z-index",20);
		$("#"+tar_id+" :eq("+showInfo.current+")").fadeIn(slide_speed);


		//$(".image_num").css("background-color","#999999");
		//$("#image_num_"+showInfo.current).css("background-color","#000000");			

		showInfo.current ++;
		slideTimes ++;
		lastSlideFunction = "auto";
	}

	function slideShowNum(show_num,num){
		
		clearTimeout(slide_shows[show_num].timer);
		slide_shows[show_num].timer = window.setInterval('SlideshowNext('+show_num+')', slide_time_slow);
	
		showInfo = slide_shows[show_num];

		lastCurrent = showInfo.current-1;
		showInfo.current = num;

		tar_id = showInfo.target.id;
		
		$("#"+tar_id+" > img").css("z-index",1);				

		$("#"+tar_id+" :eq("+lastCurrent+")").css("z-index",50);
		$("#"+tar_id+" :eq("+showInfo.current+")").hide();
		$("#"+tar_id+" :eq("+showInfo.current+")").css("z-index",100);
		$("#"+tar_id+" :eq("+showInfo.current+")").fadeIn(slide_speed);


		//$(".image_num").css("background-color","#999999");
		//$("#image_num_"+showInfo.current).css("background-color","#000000");

		showInfo.current ++;
		lastSlideFunction = "user";

	}


