﻿/*
	autor:		robert `smo´ schmoller
	company:	next e-marketing agentur gmbh
	date: 		2009-04-09
	version: 	1.0
*/
var text_elm_array = new Array();
var image_array = new Array();
var image_anz = 0;
var img_act = 0;
var nav_div;
var img_elm;
var autoplay = false;
var timeout_wait = 7;		//	angabe in ganzen sekunden! 	7 => 7 sekunden!
var timeout_id;


function showImage( id )
{
	stopSlideShow();
	loadImage(id);
}

function showNextImage ()
{
	var t = img_act+1;
	if( t>=image_array.length ){
		t = 0;
	}
	loadImage(t);
//	startTimeOut();
}

function startSlideShow ()
{
	autoplay = true;
	showNav(img_act);
	startTimeOut();
}

function stopSlideShow ()
{
	stopTimeOut();
	autoplay = false;
	showNav(img_act);
}

function startTimeOut ()
{
	timeout_id = setTimeout(showNextImage, timeout_wait*1000);
}

function stopTimeOut ()
{
	clearTimeout(timeout_id);
}

function buildImageNav ()
{
	nav_div = document.getElementById('paging');
	img_elm = document.getElementById('ProjectImage');
	image_array = image_list.split(',');
	image_anz = image_array.length;
	//
	if( image_anz>1 ){
		img_elm.onclick = function () { showNextImage(); };
		img_elm.style.cursor = 'pointer';
	}
	//
	text_elm_array = new Array();
	for( var i=1; i<=image_anz; i++ ){
		var t = document.getElementById('projectDescription_' + i );
		text_elm_array.push(t);
	}
	//
	showNav(0);
}

function loadImage ( id )
{
	img_act = id;
	img_elm.src = image_array[img_act];
	showNav(img_act);
	showText(img_act);
}

function showNav ( id )
{
	var t = '';
	for( var i in image_array){
		t += '<div>';
		if( i==id ){
			t += '<strong>' + (Number(i)+1) + '</strong>';
		} else {
			t += '<a href="#" onclick="showImage(' + i + '); return false;">' + (Number(i)+1) + '</a>';
		}
		t += '</div>'  + String.fromCharCode(13);
	}
/*	if( image_anz > 1 ){
		if( autoplay ){
			t += '&nbsp;&nbsp;<a href="#" onclick="stopSlideShow(); return false;">Diashow beenden</a>' + String.fromCharCode(13);
		} else {
			t += '&nbsp;&nbsp;<a href="#" onclick="startSlideShow(); return false;">Diashow starten</a>' + String.fromCharCode(13);
		}
	}
*/
	nav_div.innerHTML = t;
}

function showText ( id )
{
	for( var i in text_elm_array ){
		var t = text_elm_array[i];
		t.style.display = (i==id) ? 'block' : 'none';
	}
}