/* Made by Ben, www.ai-development.com, 2007 */
/* 
	<script src="bloom.js" type="text/javascript"></script>
	<link href='CSSGallery.css' rel='stylesheet' type='text/css' />
	<img src="gallery/thumbs/pic.jpg" name="" alt="" onclick="gallery.bloom(this.src, asSet, container, this.name)" />
*/


if (window.addEventListener) {		// W3C
	window.addEventListener("load",initGallery,false);
} else if (window.attachEvent) {	// Explorer
	window.attachEvent("onload",initGallery);
} else {							// Old skool
	window.onload = function(){initGallery();}
}

window.onunload = function(){gallery = null;}

function initGallery()
{	
	document.getElementById('gallery').style.display = 'block';
	myGallery = new Gallery();
}

function Gallery()
{
	/*--- Config ---*/
	this.strafTime = 0;//interval to move the div
	this.straf = new straf();
	
	this.divPrev = 0;
	this.currentDiv = 0;//displayed div
	this.divNext = 0;
	this.testiNum = 0;//Number of the current testimonial
	
	this.testiTab = new Array(); //all testimonials in the page.
	this.intElements = 0; //nb Pictures in container;
	/*@cc_on
		/*@if (@_jscript)
			this.ie = (document.all && !window.opera) ? true : false;
		/*@else @*/
			this.ie = false;
		/*@end
	@*/
	this.ie7 = (this.ie && window.XMLHttpRequest);
	//add gallery divs at the end of the body
	this.setUp();
}

Gallery.prototype.setUp = function()
{
	this.populate();

	var objMain = document.getElementById("gallery");
	
	var objPrevImg = document.createElement("img");
		objPrevImg.setAttribute('src', 'gallery/prevBtn.jpg');
		objPrevImg.setAttribute('id', 'prev');
		objPrevImg.setAttribute('alt', '');
		objPrevImg.onclick = function(){myGallery.previous()};
		objMain.appendChild(objPrevImg);			
	
	var objNextImg = document.createElement("img");
		objNextImg.setAttribute('src', 'gallery/nextBtn.jpg');
		objNextImg.setAttribute('id', 'next');
		objNextImg.setAttribute('alt', '');
		objNextImg.onclick = function(){myGallery.next()};
		objMain.appendChild(objNextImg);									
	
	var objCount = document.createElement("div");
		objCount.setAttribute('id', 'imgNumber');
		objMain.appendChild(objCount);
	
	var objBloom = document.createElement("div");
		objBloom.setAttribute('id','bloom');
		objMain.appendChild(objBloom);
		
	var objDiv1 = document.createElement("div");
		objDiv1.setAttribute('id','div1');
		this.ie ? objDiv1.className = 'holders' : objDiv1.setAttribute('class','holders');
		objBloom.appendChild(objDiv1);
		
	var objDiv2 = document.createElement("div");
		objDiv2.setAttribute('id','div2');
		this.ie ? objDiv2.className = 'holders' : objDiv2.setAttribute('class','holders');
		objBloom.appendChild(objDiv2);
		
	var objDiv3 = document.createElement("div");
		objDiv3.setAttribute('id','div3');
		this.ie ? objDiv3.className = 'holders' : objDiv3.setAttribute('class','holders');
		objBloom.appendChild(objDiv3);
	
	
	this.setBloomDiv(1);

	//this.setBloomDiv();	
	
	delete this.setUp;
}

Gallery.prototype.populate = function()
{
	this.testiTab = document.getElementById('scriptTrue').getElementsByTagName('div');	
	this.intElements = this.testiTab.length;
}

//move to next picture in the gallery
Gallery.prototype.next = function()
{
	if(this.testiNum < this.intElements-1)
	{	
		this.testiNum++;
		this.setBloomDiv(2);
		this.straf.move(0);
	}
}

//move to previous picture in the gallery
Gallery.prototype.previous = function()
{
	if(this.testiNum > 0)
	{
		this.testiNum--;
		this.setBloomDiv(0);
		
		document.getElementById('bloom').removeChild(document.getElementById('bloom').lastChild);
		var objDiv1 = document.createElement("div");
		document.all ? objDiv1.className = 'holders' : objDiv1.setAttribute('class','holders');
		objDiv1.style.width = '0px';
		document.getElementById('bloom').insertBefore(objDiv1 , document.getElementById('bloom').firstChild);
		//this.pause(590);
		this.straf.move(590);
	}
}

//diplay gallery div
Gallery.prototype.setBloomDiv = function(i)
{	
	document.getElementById('imgNumber').innerHTML = (this.testiNum+1) + ' of ' + this.intElements;
	document.getElementById('bloom').getElementsByTagName('div').item(i).innerHTML = this.testiTab[this.testiNum].innerHTML;
}

Gallery.prototype.clearTimer = function()
{
	window.clearInterval(this.bloomTime);
}

//Class manager of the width; can change the width of an object until it reach the end value;
function straf()
{
	this.o = 590;//starting value of div width
	this.pos = 0;//end value of div width
	this.time = 0;//timer for position thread
}

straf.prototype.move = function (end)
{
	//this.id = id;
	this.end = end;
	this.end == 0 ? this.time = setInterval('myGallery.straf.moveItFwr('+this.end+')', 10) : this.time = setInterval('myGallery.straf.moveItBack('+this.end+')', 10);
}

straf.prototype.moveItFwr = function(end)
{
	if(this.o <= 0)
	{			
		this.clearTime();
		this.o = 590;
		document.getElementById('bloom').removeChild(document.getElementById('bloom').firstChild);
		var objDiv1 = document.createElement("div");
		document.all ? objDiv1.className = 'holders' : objDiv1.setAttribute('class','holders');
		document.getElementById('bloom').appendChild(objDiv1);
	}
	else
	{
		this.o -= 59;
		document.getElementById('bloom').firstChild.style.width= this.o+'px';
	}
}

straf.prototype.moveItBack = function(end)
{
	if(this.pos >= 590)
	{			
		this.clearTime();
		this.pos = 0;
	}
	else
	{
		this.pos += 59
		document.getElementById('bloom').firstChild.style.width = this.pos+'px';
	}
}


straf.prototype.clearTime = function()
{
	clearInterval(this.time);
}
	

/* Made by Ben, www.ai-development.com, 2007 */
