function SlideControl() {
	var this1 = this;
	var debug	= true;
	var borderColorSaved = "#00CCFF";	// Original border Color before pause
	var consoleText = '';
	var consoleClass = '';
  var stopshow = true;
	
	this.id = "SlideControl"; // name of this object
	
	this.parms = null;
	
	this.pause 		 		= false;
	this.intervalVal 	= 6000;
	this.pause4error 	= false;
	this.consoleId 		= false;
	this.mapshown			= false;
	// properties for Menu
 
	/* 
	this callbacks should be defined in calling module
	*/
  this.cb_pauseOff = function() {}
  this.cb_pauseOn = function() {}
	this.cb_stoppit = function() {}	// stoppit is called when escape is pressed
	// onready overwrites SlideImage.onready - callback
  this.onready = function() {
		logit('onready_func:'+this.statuscd);
  	ready4next = true; // ajax finsihed timer free to do whatever he likes
		//RandMenu $("ul#sddm > li > a#menuheadRate").html("Rate Picture");
		this.triggerTimeout();
	}

  /* 
  this methods
  */

	/*
  var keyCallback = [];   // Callback array from slideControlKey
	this.addKeyCallback = function(cb) {
		keyCallback.push(cb); // add function to keypress callback array
	}
	// Callback the orders functions (ordered by addKeyCallback 
	for ( var i in keyCallback ) {
  	keyCallback[i]();
	}
  */
  this.slideControlKey = function(thisKey) {
  	//logit("slideControlKey id="+this.id);
		if (stopshow) return;
		
		var ltArrow = 37;
		var rtArrow = 39;
		var spacebar = 32;

		switch(thisKey) {
			case 107:  // plus-key
				this.def_fade_speed += 250;
				if (this.def_fade_speed > 2000) {this.def_fade_speed = 2000;}
				logit("new fade speed:"+this.def_fade_speed);
				break;
			case 109: // minus-key
				this.def_fade_speed -= 250;
				if (this.def_fade_speed < 0) {this.def_fade_speed = 0;}
				logit("new fade speed:"+this.def_fade_speed);
				break;
			case 27: // escape-key
				this.cb_stoppit();
				break;
			case ltArrow:
				this.triggerNow('prev');
				break;
			case rtArrow:
				this.triggerNow('next');
				break;
			case spacebar:
				logit("keydown space");
				if (this.pause) {
					this.pauseOff(true);
				} else {
					this.pauseOn();
				}
				return false; // avoids default browser action
			  break;			
		}
		return true; // yes do default browser key-press action
  }

  this.startShow = function(func) {
  	logit("startShow:"+func);
  	stopshow = false;
  	this1.pauseOff(false);
		this1.repeatPic(func);
  }
  this.stopShow = function() {
  	logit("stopShow");
  	this1.pauseOn();
  	stopshow = true;
  }
  /*----------------------------------------------------------------------------------------
  
   Local Variables
   
   -----------------------------------------------------------------------------------------*/
	var intervalID = 0; // for timer 
	var slideShow = true; // if speed > 0 then slideShow = on
	var ready4next = true; // not ready when triggered but no ready received
  /*----------------------------------------------------------------------------------------
  
   Local Function : triggerNow - immediatly trigger to get new image
   
   -----------------------------------------------------------------------------------------*/
	this.triggerNow = function(func) {
		//if (slideShow && !this1.mapshown) {
		//	this.pauseOff(false);
		//}
		logit("timmer clear 1:"+intervalID+"/func="+func);
		window.clearTimeout(intervalID);
		if (ready4next /* && !this1.mapshown */) {
			ready4next = false;
			this.repeatPic(func);
		}
	}
  /*----------------------------------------------------------------------------------------
  
   Local Function : triggerTimeout - after timeout trigger to get new image
   
   -----------------------------------------------------------------------------------------*/
	this.triggerTimeout = function() {
		//var this1 = this;
		//triggerTimeout:false/false/false/true/false
		logit("triggerTimeout:"+ready4next+'/'+this.pause4error+'/'+this.pause+'/'+slideShow+'/'+this.noimage);
		if (!ready4next || this.pause4error || this.pause || !slideShow || this.noimage) return;
		//RandMenu 
		if (!this1.mapshown) {
			this.pauseOff(false);
		}
		intervalID = window.setTimeout(function() {
			ready4next = false;
			this1.repeatPic('')
		},this1.intervalVal);
		logit("timmer set:"+intervalID);
	}
  /*----------------------------------------------------------------------------------------
  
   Local Function : pauseOn
   
   -----------------------------------------------------------------------------------------*/
	this.pauseOn = function() {
		logit("pauseOn:"+this.pause);
		if (this.pause) return;
		this.pause = true;
		window.clearTimeout(intervalID);
		logit("timmer clear 2:"+intervalID);
		// store current console status
		if (this.consoleId) {
			consoleText = $("ul#sddm > li > a#consoleText").html();
		
			if ($("ul#sddm > li > a#consoleText").hasClass("redBack")) {
				consoleClass = "redBack";
			} else {
				consoleClass = "greenBack";
			}
			logit('consoleText:'+consoleText+',Class:'+consoleClass);
			$("ul#sddm > li > a#consoleText").html("paused").removeClass().addClass("redBack");
		}

	 	if (this.displaySize == 'thumb') {
			logit("set border to pause on");
			borderColorSaved = $(".borderThumb").css("border-color");
			$(".borderThumb").css("border-color","#FF0000");
		}
	 	if (this.displaySize == 'popupslide') {
			logit("set border to pause on");
			borderColorSaved = $(".borderPopupslide").css("border-color");
			$(".borderPopupslide").css("border-color","#FF0000");
		}
		this.cb_pauseOn();
	}
  /*----------------------------------------------------------------------------------------
  
   Local Function : pauseOff
   
   -----------------------------------------------------------------------------------------*/
	this.pauseOff = function(newtimeout) {
		logit('pauseOff:'+stopshow+"/"+slideShow+"/"+this.pause);
		if (stopshow) return;
		if (slideShow && !this1.mapshown) {   // when slidshow active
			if (this.pause) {
				this.pause = false;
				if (this.consoleId) {
					logit("============================consoleClass="+consoleClass+'/consoleText='+consoleText);
					$("ul#sddm > li > a#consoleText").html(consoleText).removeClass().addClass(consoleClass);
				}
			}
			if (newtimeout) {
				this.triggerTimeout();
			}
		 	if (this.displaySize == 'thumb') {
				logit("set border to pause off");
				$(".borderThumb").css("border-color",borderColorSaved);
			}
		 	if (this.displaySize == 'popupslide') {
				logit("set border to pause off");
				$(".borderPopupslide").css("border-color",borderColorSaved);
			}
		 	if (this.displaySize == 'big') {
				logit("set border to pause off");
				$(".borderThumb").css("border-color",borderColorSaved);
			}
			this.cb_pauseOff();
		}
	}
  /*----------------------------------------------------------------------------------------
  
   Local Function : keypress
   
   -----------------------------------------------------------------------------------------*/
	function keypress(evt) {
		//logit('keypress');
			
		var thisKey;
		if (evt) {
			thisKey = evt.which;
		}
		else {
			thisKey = window.event.keyCode;
		}
		// logit("Key Pressed:"+thisKey);	
		return this1.slideControlKey(thisKey); // may return false to avoid default browser key-action.
	}
  /*----------------------------------------------------------------------------------------
  
   Local Function : RandMenuInit
   
   -----------------------------------------------------------------------------------------*/
	this.repeatPic = function(func) {
		logit("repeatPic="+this.pause+'/'+func);
		//if (this1.mapshown) {return;}
	  this.getfunc 		= func;
		this.getPic();
	}

	this.initSlideControl = function() {
		logit("initSlideControl this.id="+this.id);
		this1 = this;
		
		stopshow = true;
		
		this.initSlideImage();
		
		if (typeof(Shadowbox) != 'undefined') {
		 	Shadowbox.init({
				onClose: function(currentElement) {
					this1.pauseOff();
					this1.onready();
					//onpauseoff_func();
				},
				onOpen: function(currentElement) {
					this1.pauseOn();
					//onpauseon_func();
		    }
		 	});
		}

		//document.onkeydown = keypress; // ie6 & ie7 has trouble with other keydown methods
		$(document).bind("keydown",keypress);		
		//this.repeatPic('last');
	}
	function logit(text) {
		logitAll("SlideControl-"+text);
	}
}
logit("extend SlideImage to SlideControl");
SlideControl.prototype = new SlideImage();
SlideControl.prototype.constructor = SlideControl;
//Extend(SlideControl,SlideImage);
//Extend(SlideImage,SlideControl);


