//------------------------------------------
// i-Tab
// © 2006 Kim & Dean - All Rights Reserved
//
// Created:        Aug. 2nd, 2006
// Last Modified:  Aug. 3rd, 2006
// Written By:     Dean
//------------------------------------------

var itab_img_array  = new Array();
var itab_img_delay  = 5;
var itab_img_index  = -1;
var itab_img_curop  = 0;
var itab_img_fading = 10;

function itab_img_rotate_start(io, so)
{
	if (itab_img_array.length <= 0)
	{
		return false;
	}

	itab_img_index = 0;
	itab_img_rotate_go_go(io, so, true);
}

function itab_img_rotate_go_go(io, so, ld)
{
	var oi = document.getElementById(io) || document.all[io];
	var os = document.getElementById(so) || document.all[so];
	var op = oi.parentNode || os.parentNode;

	if ((!oi || typeof(oi) == 'undefined') || (!os || typeof(os) == 'undefined') || (!op || typeof(op) == 'undefined') )
	{
		return false;
	}

	ld = (ld == true) ? true : false;
	itab_img_index++;

	if (itab_img_index >= itab_img_array.length || itab_img_index < 0)
	{
		itab_img_index = 0;
	}

	if (ld == true)
	{
		var id       = itab_img_array[itab_img_index];
		oi.src       = id[0];
		os.innerHTML = id[1];
	}

	oi.style.display = '';
	os.style.display = '';

	setTimeout("itab_img_rotate_fancy_img('"+io+"', '"+so+"', "+ld+")", (ld == true) ? itab_img_fading : itab_img_delay*1000);
}

function itab_img_rotate_fancy_img(io, so, ld)
{
	var oi = document.getElementById(io) || document.all[io];
	var os = document.getElementById(so) || document.all[so];
	var op = oi.parentNode || os.parentNode;

	if ((!oi || typeof(oi) == 'undefined') || (!os || typeof(os) == 'undefined') || (!op || typeof(op) == 'undefined') )
	{
		return false;
	}

	if (ld)
	{
		itab_img_curop++;
		op.style.filter  = 'alpha(opacity='+itab_img_curop+')';
		op.style.opacity = Math.max(0.01, itab_img_curop/100);

		if (itab_ie7)
		{
			oi.style.filter = op.style.filter;
			os.style.filter = op.style.filter;
		}

		if (itab_img_curop < 100)
		{
			setTimeout("itab_img_rotate_fancy_img('"+io+"', '"+so+"', "+ld+")", itab_img_fading);
		}
		else
		{
			setTimeout("itab_img_rotate_go_go('"+io+"', '"+so+"', false)", itab_img_fading);
		}
	}
	else
	{
		itab_img_curop--;
		op.style.filter = 'alpha(opacity='+itab_img_curop+')';
		op.style.opacity = Math.max(0.01, itab_img_curop/100);

		if (itab_ie7)
		{
			oi.style.filter = op.style.filter;
			os.style.filter = op.style.filter;
		}

		if (itab_img_curop > 0)
		{
			setTimeout("itab_img_rotate_fancy_img('"+io+"', '"+so+"', "+ld+")", itab_img_fading);
		}
		else
		{
			setTimeout("itab_img_rotate_go_go('"+io+"', '"+so+"', true)", itab_img_fading);
		}
	}
}

function itab_img_rotate_add_img(i, t)
{
	if (typeof(itab_img_array) == 'undefined')
	{
		itab_img_array = new Array();
	}

	var x = itab_img_array.length;
	itab_img_array[x]    = new Array();
	itab_img_array[x][0] = i;
	itab_img_array[x][1] = t;
	itab_img_array[x][2] = new Image();
	itab_img_array[x][2].src = i;
}



	function createParentDivs(imageIndex)
	{
		if(imageIndex==slideshow2_imagesInGallery){			
			showGallery();
		}else{
			var imgObj = document.getElementById('galleryImage' + imageIndex);	
			if(Opera)imgObj.style.position = 'static';
			slideshow2_imageDivs[slideshow2_imageDivs.length] =  imgObj;
			imgObj.style.visibility = 'hidden';	
			imageIndex++;
			createParentDivs(imageIndex);	
		}		
	}
	
	function showGallery()
	{
		if(slideshow2_slideIndex==-1)slideshow2_slideIndex=0; else slideshow2_slideIndex++;	// Index of next image to show
		if(slideshow2_slideIndex==slideshow2_imageDivs.length)slideshow2_slideIndex=0;
		slideshow2_slideIndexNext = slideshow2_slideIndex+1;	// Index of the next next image
		if(slideshow2_slideIndexNext==slideshow2_imageDivs.length)slideshow2_slideIndexNext = 0;
		
		slideshow2_currentOpacity=100;	// Reset current opacity

		// Displaying image divs
		slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'visible';
		if(Opera)slideshow2_imageDivs[slideshow2_slideIndex].style.display = 'inline';
		if(navigator.userAgent.indexOf('Opera')<0){
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.visibility = 'visible';
		}
		
		if(document.all){	// IE rules
			slideshow2_imageDivs[slideshow2_slideIndex].style.filter = 'alpha(opacity=100)';
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.filter = 'alpha(opacity=1)';
		}else{
			slideshow2_imageDivs[slideshow2_slideIndex].style.opacity = 0.99;	// Can't use 1 and 0 because of screen flickering in FF
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.opacity = 0.01;
		}		
		

		setTimeout('revealImage()',slideshow2_timeBetweenSlides);		
	}
	
	function revealImage()
	{
		if(slideshow2_noFading){
			slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'hidden';
			if(Opera)slideshow2_imageDivs[slideshow2_slideIndex].style.display = 'none';
			showGallery();
			return;
		}
		slideshow2_currentOpacity--;
		if(document.all){
			slideshow2_imageDivs[slideshow2_slideIndex].style.filter = 'alpha(opacity='+slideshow2_currentOpacity+')';
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.filter = 'alpha(opacity='+(100-slideshow2_currentOpacity)+')';
		}else{
			slideshow2_imageDivs[slideshow2_slideIndex].style.opacity = Math.max(0.01,slideshow2_currentOpacity/100);	// Can't use 1 and 0 because of screen flickering in FF
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.opacity = Math.min(0.99,(1 - (slideshow2_currentOpacity/100)));
		}
		if(slideshow2_currentOpacity>0){
			setTimeout('revealImage()',slideshow2_fadingSpeed);
		}else{
			slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'hidden';	
			if(Opera)slideshow2_imageDivs[slideshow2_slideIndex].style.display = 'none';		
			showGallery();
		}
	}
	
	function initImageGallery()
	{
		slideshow2_galleryContainer = document.getElementById('imageSlideshowHolder');
		slideshow2_galleryWidth = slideshow2_galleryContainer.clientWidth;
		slideshow2_galleryHeight = slideshow2_galleryContainer.clientHeight;
		galleryImgArray = slideshow2_galleryContainer.getElementsByTagName('IMG');
		for(var no=0;no<galleryImgArray.length;no++){
			galleryImgArray[no].id = 'galleryImage' + no;
		}
		slideshow2_imagesInGallery = galleryImgArray.length;
		createParentDivs(0);		
		
	}
		