// JavaScript Document
jQuery.fn.directorySlideshow=function(directory){
	

	var $this=$(this);
	$this.slideInfo=directory+"/photoList.js";
	
		$this.slideTrans='';
		$this.slideSpeed='';
		$this.slide_timeout='';
		$this.slideSync='';
		$this.slideRandom='';				   
	  	$.getJSON($this.slideInfo,function(data){
			
			var numslides=data.num_slides;
			$this.find(".image_count").text(numslides);
			var ht=parseInt(data.slide_ht);
			var W= parseInt(data.slide_width);
			$this.slideTrans=data.transition_type;
			$this.slideSpeed=data.trans_speed;
			$this.slide_timeout=parseInt(data.slide_timeout);
			$this.slideSync= parseInt(data.sync_slide);
			
			$this.find(".slideshow").css({height:ht, width:W});
			
			  var name;
			  for(name in data){ 
			  		
				var nameSplit1= name.slice(0,10);	
					
					if(nameSplit1=='image_name'){
						$this.slideSRC=data.slide_folder+"/"+data[name];
						$this.find(".slideshow").append('<img src="'+$this.slideSRC+'" width="' +data.slide_width +'" height="' + data.slide_ht +'" />');
					}
					if(nameSplit1=='image_text'){
						$this.find(".imageText_wrap").append('<p class="imageText">'+data[name]+'</p>'); 
					}
			}
			$this.find(".slideshow").cycle({
				fx: $this.slideTrans,
				speed: $this.slideSpeed,
				timeout: $this.slide_timeout,
				//pager: '.nav',
				prev: $this.find(".prev"),
				next: $this.find('.next'),
				//random:       slideRandom,
				//fastOnEvent:   1,
				sync: $this.slideSync,
				before: function(curr, next, opts){
					var idx=opts.nextSlide;
					$this.find(".imageText").hide(); 
					},
				after: function(curr, next, opts){
					var idx=opts.currSlide;
					$this.find(".image_num").text(idx+1);
					$this.find(".imageText").eq(idx).show();
					}
								  
								  
			});
		});
}// end plugin
