/**
 * vb 2006-12-07
 * <vb [dog] php [dot] ru>
 */
var Picture = new Array();

var SlideShowSpeed = 3000;
var CrossFadeDuration = 3;
var jss = 1;
var pss;
var teller = new Array();
var aantal;
var preLoad = new Array();
var tss;

//obj is 'input' with type 'text'
//http_ajax_php is http address for php-file (backend)
Hash = function (obj, http_ajax_php){
	
	var object = this;


	this.regenerate = function (query,slide){
		
		var req = new Subsys_JsHttpRequest_Js();
		req.onreadystatechange = function() {       
			if (req.readyState == 4) {
				if (req.responseJS) {
					//Presumed php returned obly variable `result`
					/*
						Example:
							JS:
								var a = req.responseJS.a;
								var b = req.responseJS.b;
								var c = req.responseJS.c;
							PHP:
								$_RESULT = array ( 'a' => $a, 'b' => $b, 'c' => $c);
					*/

		
					object.title	=	req.responseJS.title;
					object.info = req.responseJS.info;
					object.source = req.responseJS.source;
					object.bar = req.responseJS.bar;


					document.getElementById('ajax_title').innerHTML = 	object.title;
					document.getElementById('ajax_info').innerHTML = 	object.info;
					document.getElementById('ajax_bar').innerHTML =		object.bar;


					if(tss) {	 clearTimeout(tss); }
	
					if(slide == 1) {

							for(var i in object.source)	{
							Picture[i] = object.source[i];
						}

						start();
					}
					else {
						document.getElementById('ajax_show').innerHTML = object.source;
					}
					
				}
				if (document.getElementById('debug')) //this string not mandatory - i insert this string for example
				{
					document.getElementById('debug').innerHTML += req.responseText;
				}
			}
		}
		req.caching = false;
		req.open('POST', http_ajax_php, true);
		req.send({ query: query, slide: slide }) /*first `query` - name for var, last `query` - value var. 
									Example: req.send({ query: query, action: 'test', id: selected_id }) */
	}
	
	
	
	
	
		this.aflash = function (flash){
		var req = new Subsys_JsHttpRequest_Js();
		req.onreadystatechange = function() {       
			if (req.readyState == 4) {
				if (req.responseJS) {
		
					object.flash	=	req.responseJS.flash;

					document.getElementById('ajaxflash').innerHTML = 	object.flash;

				
				}
				if (document.getElementById('debug')) //this string not mandatory - i insert this string for example
				{
					document.getElementById('debug').innerHTML += req.responseText;
				}
			}
		}
		req.caching = false;
		req.open('POST', http_ajax_php, true);
		req.send({ flash: flash }) /*first `query` - name for var, last `query` - value var. 
									Example: req.send({ query: query, action: 'test', id: selected_id }) */
	}
	
}


function setvars() {

pss = Picture.length-1;
var k = 1;    
for (i in Picture) { 
    teller[k] = Picture[i];     k++;    
}        
aantal = (k-1);        
for (iss = 1; iss < pss+1; iss++){    preLoad[iss] = new Image();    preLoad[iss].src = teller[iss];	 }
}


function runSlideShow(){
    if (document.all){    
			document.images.PictureBox.style.filter="blendTrans(duration=2)";
			document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)";   
			document.images.PictureBox.filters.blendTrans.Apply();
		}    
	document.images.PictureBox.src = preLoad[jss].src;
	
	if (document.all) document.images.PictureBox.filters.blendTrans.Play();    
	jss = jss + 1;    
	if (jss > (aantal)) jss=1;    
	tss = setTimeout('runSlideShow()', SlideShowSpeed);    
}
function start()	{
	setvars();
	document.getElementById("ajax_show").innerHTML = ('<img name="PictureBox" src="'+preLoad[1].src+'" border=0 width=208 height=155>'); 
	runSlideShow();
}



