var all_pics = new Array();
		
var g_body_height = 0;
var g_body_width = 0;

var g_opacity = 0;

var act_effect = 0;

var current_pic = 0;

var slideshow_status;

var current_div = 0;

var show_divs = new Array();

var img_texte = new Array();

show_divs[0] = "gallery_body";
show_divs[1] = "gallery_body2";

function set_img_text(which, text){
	img_texte[which] = text;
}

function first(){
	current_pic = 0;
	
	show_img(0, all_pics[current_pic],img_texte[current_pic]);
}

function last(){
	current_pic = all_pics.length - 1;
	
	show_img(current_pic, all_pics[current_pic],img_texte[current_pic]);
}

function add_pic(key, value, text){
	all_pics[key] = value;
	img_texte[key] = text;
}

function set_slideshow_status(status){
	
	if(slideshow_status != status){
		slideshow_status = status;
		
		if(status == 1)
			slideshow();
	}
}

function slideshow(){

	if(slideshow_status == 1){
		
		if(current_pic == undefined || current_pic.NaN)
			current_pic = 0;
	
		show_img(current_pic, all_pics[current_pic],img_texte[current_pic]);
	
		current_pic += 1;
		
		if(current_pic > all_pics.length - 1)
			current_pic = 0;
		
			
		window.setTimeout("slideshow()", 10000);
	}
}

function show_img(key, img, text){

	current_pic = key;
	
	document.getElementById(show_divs[current_div]).style.zIndex = 1;
	
	if(current_div == 0){
		current_div = 1;	
	}else{
		current_div = 0;
	}
	
	document.getElementById(show_divs[current_div]).style.zIndex = 8;
	
	
	show_pic = current_pic + 1;
	
	document.getElementById('counter').innerHTML = show_pic + "/" + all_pics.length;

	image = "<div align=\"center\" class=\"lauftext\"><img src='" + img + "'></div>";

	document.getElementById(show_divs[current_div]).innerHTML = image;
	
	if(text != ""){
		document.getElementById(show_divs[current_div]).innerHTML += "<p class=\"lauftext\">" + text + "</p>";
	}
	
	if(act_effect == 0){
		document.getElementById(show_divs[current_div]).style.height = "0px";
		document.getElementById(show_divs[current_div]).style.display = "none";
		g_body_height = 0;
		window.setTimeout("slide()", 1000);
		act_effect = 1;
	}else if(act_effect == 1){
		document.getElementById(show_divs[current_div]).style.filter = "alpha(opacity=0";
		document.getElementById(show_divs[current_div]).style['-moz-opacity'] = ".0";
		document.getElementById(show_divs[current_div]).style.opacity = ".0";
		
		g_opacity = 0;
		act_effect = 0;
		window.setTimeout("opa()", 1000);
	}else if(act_effect == 2){
		/*
		
		Looks not good at this time - leave it out...
		
		document.getElementById(show_divs[current_div]).style.width = "0px";
		document.getElementById(show_divs[current_div]).style.display = "none";
		g_body_height = 0;
		window.setTimeout("slide_x()", 1000);
		act_effect = 0;
		*/
	}
}

function opa()
{
	if(g_opacity < 100){
	
		var perc_opacity = g_opacity/10;
	
		document.getElementById(show_divs[current_div]).style.filter = "alpha(opacity=" + g_opacity;
		document.getElementById(show_divs[current_div]).style['-moz-opacity'] = "." + perc_opacity;
		document.getElementById(show_divs[current_div]).style.opacity = "." + perc_opacity;
		
		g_opacity += 5;
		
		window.setTimeout("opa()", 20);

	}else{
		document.getElementById(show_divs[current_div]).style.filter = "alpha(opacity=100" + g_opacity;
		document.getElementById(show_divs[current_div]).style['-moz-opacity'] = "1";
		document.getElementById(show_divs[current_div]).style.opacity = "1";
	}
}

function slide(){

	document.getElementById(show_divs[current_div]).style.display = "";
	
	if(g_body_height < 500){

		g_body_height += 10;
	
		document.getElementById(show_divs[current_div]).style.height = g_body_height + "px";
		window.setTimeout("slide()", 10);
	}else{
		document.getElementById(show_divs[current_div]).style.height = "490px";
	}
}


function slide_x(){

	document.getElementById(show_divs[current_div]).style.display = "";

	if(g_body_width < 500){

		g_body_width += 10;
	
		document.getElementById(show_divs[current_div]).style.width = g_body_width + "px";
		window.setTimeout("slide_x()", 10);
	}else{
		document.getElementById(show_divs[current_div]).style.width = "490px";
		g_body_width = 0;
	}
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function g_head(){
	window.alert(findPos('gallery_header'));
}

var show_mouse = 0;
var move_it = false;
var mousePos = null;
var winSize = null;

var border_left;
var border_right;

var start_x = 0;

function reset_start(){
	start_x = 0;
	set_slideshow_status(0);
}

// Set events to catch mouse position and window size
//document.onmousemove = mouseMove;

window.onresize = windowResize;
// The mouseMove and mouseCoords function track the mouse position for us

function move_slider(pos){
	var w = parseInt(document.getElementById('slider').style.width);
	var max_right = 0 - (w - 490);
	
	var diff = max_scroll - min_scroll;
	
	var mr = max_right * -1;
	
	var step = (mr + (total_images * 0.4)) / diff;
	
	if(step < 1)
		step = 1;
	
	var mins = min_scroll * -1;
	var maxs = max_scroll * 2;
	
	if(pos == min_scroll)
		document.getElementById('slider').style.left = "0px";
	
	if(pos > min_scroll && pos < max_scroll){
		if(pos < 0){
			act_pos = (min_scroll - pos) * -1;
		}else{
			act_pos = (pos - min_scroll);
		}
		
		p_left = act_pos * step;
		
		if(p_left > max_right){
			
			document.getElementById('slider').style.left = -p_left + "px";
		}
	}
}

function move(direction, action){
	
	var x = parseInt(document.getElementById('scrollbar').style.left);
	
	if(direction == "right" && action != null){
		scroll_btn_right = action;
	}
	
	if(direction == "left" && action != null){
		scroll_btn_left = action;
	}
	
	if(scroll_btn_right == true){
		if(direction == "right" && x < max_scroll){
			x += 1;
			document.getElementById('scrollbar').style.left = x + "px";
			move_slider(x);
			window.setTimeout("move('right', null)", 50);
		}
	}
	
	if(scroll_btn_left == true){
		if(direction == "left" && x > min_scroll){
			x -= 1;
			document.getElementById('scrollbar').style.left = x + "px";
			move_slider(x);
			window.setTimeout("move('left', null)", 50);
		}
	}
	
}



function mouseMove(ev)
{
  ev = ev || window.event;
 	//if(show_mouse == 1){
		mousePos = mouseCoords(ev);
		
		var left = winSize.x / 2 - 490/2;
		var right = left + 490;
		var mp = mousePos.x - left;
		
		border_left = left;
		border_right = right;
}

function mouseCoords(ev)
{
  if(ev.pageX || ev.pageY){
    return {x:ev.pageX, y:ev.pageY};
  }
  return {
    x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
    y:ev.clientY + document.body.scrollTop  - document.body.clientTop
  };
}

function show_mousepos(state){
	show_mouse = state;
	if(state == 1)
		move("left");
}

function windowResize( )
{
  winSize = {
    x: ( document.body.clientWidth ) ?
       document.body.clientWidth : window.innerWidth ,
    y: ( document.body.clientHeight ) ?
       document.body.clientHeight : window.innerHeight
  }
}