var tmp_img = new Image();
var galery_imgage = null;
af=Math.floor;
b=new Array(99);
s=new Array("null","web","images","groups","news","froogle","local","scholar","video","maps","labs","more");
ab=10;
t=0;
u=0;
n=0;
o=new Date();
zoomSteps=1;
zoomSpeed=8;
m=385;
imgId=0;
p=0;
x=false;
w=x;

var title;
var firstHoverOccurred=w;

imgHeight = 120;
imgHeightHover = 130;

var scroll_timer = null;
var scroll_timer_ms = 10;
var scroll_step = 3;
var scroll_e = document.getElementById("gallery_slider");
var scroll_w = scroll_e.scrollWidth;
var image_num = 0;
image_interval = window.setInterval( 'switch_image()', 2000);
imgInit();//bubbles :)

function um_changeimg(i)
{
	if ( i.src.indexOf('_a.gif') > 0 )
		{
			i.src = i.src.replace(/_a\.gif/i, '.gif');
		}
	else
		{
			i.src = i.src.replace(/\.gif/i, "_a.gif");
		}
}

function change_anchor(anc)
{

	if ( anc.getElementsByTagName )
	{
		var i = anc.getElementsByTagName("IMG").item(0);
		if ( i ) um_changeimg(i);
	}
}
/*Clemens hat das toll gemacht*/
function click_image(e,media,w) {
	var big_image = document.getElementById("big_image");
	//document.getElementById("big_image_title").innerHTML = e.title;
	if (big_image) {
		tmp_img.src = '/(cms)/media/resize/size='+w+'x0/'+media;		
		tmp_img.onload = change;
		tmp_img.title = e.title;
		tmp_img.alt = e.alt;
	}
}

function change() {
	var hint = document.getElementById("galery_title");
	if (hint) {
		hint.innerHTML = "<h1>"+tmp_img.title+"</h1>"+tmp_img.alt;
	}
	var big_image = document.getElementById("big_image");
	//tmp_img.width = tmp_img.width * 0.5; 
	//tmp_img.height = tmp_img.height * 0.5;
	tmp_img.id = "big_image";
	big_image.parentNode.insertBefore(tmp_img,big_image);
	big_image.parentNode.removeChild(big_image);
	tmp_img = new Image();
	// sifr aufruf f�r die �berschriften;
	if (typeof sIFR=="function") {
		sIFR.replaceElement(named({sSelector:"div#galery_title h1", sFlashSrc:"/static/swf/sifr.swf", sColor:"#D58C0F", sLinkColor:"#D58C0F", sBgColor:"#FFFFFF", sHoverColor:"#D58C0F", nPaddingTop:0, nPaddingBottom:0, sWmode:"transparent", sFlashVars:"padding-bottom:1px;offsetTop=0"}));
	}
}


function change_image() {

	var big_image;
	if (big_image = document.getElementById("big_image")) {
		big_image.title = galery_imgage.title;
		big_image.src = galery_imgage.src;
	}
}

function scroll_stop(){ window.clearTimeout(scroll_timer); };

function scroll_left(){
	if(scroll_e.scrollLeft > 0) {
		scroll_e.scrollLeft -= scroll_step;
		scroll_timer = setTimeout("scroll_left();", scroll_timer_ms);
	}
}

function scroll_right(){
	if(true) {
		scroll_e.scrollLeft += scroll_step;
		scroll_timer = setTimeout("scroll_right();", scroll_timer_ms);
	}
}

function imgZoomIn( elementId ){
	imgId = elementId;
	o=new Date();
	setTimeout("gidle()",zoomSpeed);
}
function imgZoomOut( elementId ){
	imgId = 0;
	w=x;
	o=new Date();
	setTimeout("gidle()",zoomSpeed);
}
function imgInit(){
	for(var j=1;j<b.length;j++){
		b[j]=imgHeight
	}
	setTimeout("gidle()",zoomSpeed);
}
function gidle(){
	var l=0;
	// auszoomen..
	for(var i=1;i<b.length;i++){
		var imagename="gallery_img_"+i;
		var imageElem=document.getElementById(imagename);
		if(imgId!=i){
			if(b[i]>imgHeight){
				b[i]-=zoomSteps;
				if(b[i]<=imgHeight){
					b[i]=imgHeight;
//					imageElem.src=s[i]+"-sm.gif"
				}
				// imageElem.width=b[i];
				imageElem.height=b[i];
				if(imgId==0){
					var g=af(255-255*(b[i]-35)/35);
				/*
					//title.style.color="rgb("+g+","+g+","+g+")"
				*/
				}
				p=1
			}
			l+=b[i]
		}
	}
	// einzoomen...
	if(imgId!=0 && b[imgId]<imgHeightHover ){
		imagename="gallery_img_"+imgId;
		imageElem=document.getElementById(imagename);
		if(w==x){
			w=true;
			if(imgId<6){
				var y=360-(imgId-1)*imgHeightHover;
				//title.innerHTML=document.getElementById(imagename).alt+'<img src="cleardot.gif" width="'+y+'" height="1"/>'
			}else{
				var y=(imgId-7)*imgHeightHover+imgHeightHover;
				//title.innerHTML='<img src="cleardot.gif" width="'+y+'" height="1"/>'+document.getElementById(imagename).alt
			}
		}
		b[imgId]+=zoomSteps;
		p=1;
		if(b[imgId]>imgHeightHover){
			b[imgId]=imgHeightHover
		}
		l+=b[imgId];
		if(l<m){
			b[imgId]+=m-l;
			if(b[imgId]>imgHeightHover) {
				b[imgId]=imgHeightHover
			}
			l=m
		}
		var g=af(255-255*(b[imgId]-imgHeight)/imgHeight);
		/*
		title.style.color="rgb("+g+","+g+","+g+")";
		document.getElementById(imagename).src=s[imgId]+".gif"
		*/
		imageElem.height=b[imgId];
		//imageElem.width=b[imgId];
	}
	m=l;
	var ad=new Date();
	ab=ad.getTime()-o.getTime();
	o=ad;
	t+=ab;
	u++;
	n=t/u;
	if(u>5){
		if(n>30){
			zoomSteps=11
		}
		if(n>60){
			zoomSteps=10
		}
		if(n>90){
			zoomSteps=5
		}
	}
	if(p){
		setTimeout("gidle()",zoomSpeed);
		p=0
	}
}


function switch_image( ) {
	if ( image_num >= gallery_images.length ) {
		image_num = 0;
	}
	img = gallery_images[image_num];
	image_num++;
	click_image(img.info,img.media,411,true);
}
