// load selected html snippet
function displayCycle(results,where){
	where = where || $("#pic_div");
	$(where).load(results);
}
//display clicked item, stop fade cycle
function display(results){
	go=false;
	//$("#pic_div2").hide("slow");
	$("#pic_div").hide();
	$("#pic_div").load(results);
	$("#pic_div").fadeIn("slow");
}
// load initial snippet
$(document).ready(function(){
	//displayCycle('pic1.html');
	//displayUrl = 'xmlshow.php?galleryIndex=' + jQuery.url.param("galleryIndex");  //'xmlshow.php?galleryIndex=1'
	//displayCycle(displayUrl);
});

  var i=2;
  var go=true;
  $(document).ready(function(){
  	$.cycleDivs = function (t) {
		if(go) {
		t = t || $("#rotator > div:first-child");
		$.fadeIt(t);
		};
	};
	
	$.fadeIt = function (t) {
      	t.wait(4000).fadeOut(1000, function () {
		if(go) {
		t = t.next();
		if (t.is(":last-child")) {
			displayCycle("pic"+i+".html");
			t = $("#rotator > div:first-child");
		};
		t.fadeIn(1000);
		displayCycle("pic"+i+".html",'#pic_div2');
		if(i>19) { i=1; } else { i=i+1; }
		$.cycleDivs(t);	
		};//if go
      });
	};
	//timerT = setTimeout("$.cycleDivs()",3000); 
  });
	
    $.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };
