/*
Developped by Arnaud SING (FR)
For GOTO Software company - http://www.goto.fr/
© All rights reserved
Contact the company for personal or commercial use
Compatible Firefox 2.0.0.9 and Internet Explorer 7.0, 8.0
No bug
*/

/* ----------------------------------------------- */
// COPY THIS PART OF CODE IN YOUR CALLER WEB PAGE

// Array of elements to display
// No DOM element auto insertion because of too much possibilities for the user (you) to display things ( images, text, movie, swf, etc.. with link, JS function, etc..)
// Who says i'm sluggard xD
/*
var galist=new Array(
		'<a href="#a"><img src="cadredesktopproDE.gif"></a>',
		'<a href="#b"><img src="cadredesktopproUK.gif"></a>',
		'<a href="#c"><img src="avatar.jpg"></a>'
	);
var gacurs=0; // Element by default, pay attention, it's starts with the first element at 0
*/

/* ----------------------------------------------- */

var gaIE=(navigator.appName=='Microsoft Internet Explorer')?true:false;
var garollover=false;
var ganot_paused=true;

function ga$(id){return document.getElementById(id);}

function gaopen_window(page,titre,width,height){
	var largeur = (gaIE)?document.body.scrollWidth:document.body.offsetWidth;
    var left=parseInt(((largeur-width)/2), 10);
    window.open(page,titre,'top=150,left='+left+',width='+parseInt(width+40,10)+',height='+parseInt(height+40,10)+',menubar=no,scroll=yes,location=no,padding=0,margin=0');
}

function gacreateObj(type, id, content, style, where){
	var newdiv = document.createElement(type);
	newdiv.setAttribute('id', id);
	newdiv.setAttribute('name', id);
	if(gaIE){
		newdiv.style.setAttribute('cssText', style);
	}else{
		newdiv.setAttribute('style', style);
	}
	newdiv.innerHTML = content;
	ga$(where).appendChild(newdiv);
}

function gagiveMe(param, from){
	if(param=='opa'){
		if(gaIE){
			var response = ga$(from).style.filter;
			var value=response.substring(14,response.length-1);
		}else{
			var value = ga$(from).style.opacity;
		}
	}else{
		var response = eval('ga$(from).style.'+param);
		var value = response.substring(0,response.indexOf('px'));
	}
	return value;
}

function gadecaltop(id, decal, opa, interval){
	var top = gagiveMe('top', id);
	if(decal!=0){
		top++;
		ga$(id).style.top = top+'px';
		if(gaIE){
			opa=(opa<=90)?opa+10:opa;
			if(ga$(id.substring(0,7)+'_txt')!=null){ga$(id.substring(0,7)+'_txt').style.filter = 'alpha(opacity='+opa+')';}
			ga$(id).style.filter = 'alpha(opacity='+opa+')';
		}else{
			opa=(opa<=0.9)?opa+0.1:opa;
			if(ga$(id.substring(0,7)+'_txt')!=null){ga$(id.substring(0,7)+'_txt').style.opacity = opa;}
			ga$(id).style.opacity = opa;
		}
		decal--;
		setTimeout("gadecaltop('"+id+"', '"+decal+"', '"+opa+"')", interval);
	}
}

function gazoom(id, decal, time){
	var interval = time/decal;
	var top = gagiveMe('top', id);
	if(decal>0 && !garollover){
		garollover=true;
		if(top<decal){
			var opa = (gaIE)?100:1.0;
			gadecaltop(id, decal, opa, interval);
		}
	}
}

function gatronquer(what,howmuch) {
	what = ''+what;
	if (what.indexOf('.') == -1) return what;
	var pos = parseInt(what.indexOf('.')+howmuch+1,10);
	return what.slice(0,pos);
}

function gadecalbottom(id, decal, opa, interval){
	var top = gagiveMe('top', id);
	if(decal!=0){
		top--;
		ga$(id).style.top = top+'px';
		if(gaIE){
			opa=(opa>=10)?opa-10:opa;
			if(ga$(id.substring(0,7)+'_txt')!=null){ga$(id.substring(0,7)+'_txt').style.filter = 'alpha(opacity='+opa+')';}
			ga$(id).style.filter = 'alpha(opacity='+opa+')';
		}else{
			opa=(opa>=0.1)?gatronquer(opa-0.1,1):opa;
			if(ga$(id.substring(0,7)+'_txt')!=null){ga$(id.substring(0,7)+'_txt').style.opacity = opa;}
			ga$(id).style.opacity = opa;
		}
		decal--;
		setTimeout("gadecalbottom('"+id+"', '"+decal+"', '"+opa+"')", interval);
	}
}

function gazoomOut(id, decal, time){
	var interval = time/decal;
	var top = gagiveMe('top', id);
	if(decal>0 && garollover){
		garollover=false;
		if(top>0){
			var opa = (gaIE)?100:1.0;
			gadecalbottom(id, decal, opa, interval);
		}
	}
}

function gamove(id, ind, decal, time){
	if(id.substring(id.length-4)=='_img'){id=id.substring(0, id.length-4);}
	if(ind!=0){gazoomOut(id+'_img', decal, time);}
	gacurs=(ind==-1 && gacurs==0)?galist.length-1:parseInt(gacurs+ind,10)%galist.length;
	if(gagiveMe('opa', id+'_img')!=0){
		setTimeout(function(){gamove(id+'_img', 0, decal, time);}, 100);
	}else{
		ga$(id+'_img').innerHTML=galist[gacurs];
		//gacreateObj('div', id+'_text', '<br>'+parseInt(gacurs+1,10)+'/'+galist.length, 'display:block; color:#C7C7C7;', id+'_img');
		setTimeout(function(){gazoom(id+'_img', decal, time);}, 100);
	}
}

function gapause(b){
	ganot_paused = b;
}

function gaauto_move(div, decal, time){
	if(ganot_paused){
		gamove(div, 1, decal, time);
	}
	setTimeout(function(){gaauto_move(div, decal, time);}, 1800);
}

function gallery(container, div, width, height, decal, time, bg){
	if(bg!=''){var backgrd=(bg.indexOf('#')==0)?' background:url('+bg+') no-repeat center;':' background:'+bg;}
	else{var backgrd='';}
	gacreateObj('div', div, '', 'width:'+width+'px; height:'+parseInt(decal+height,10)+'px; float:left;'+backgrd, container);
	if(gaIE){
		gacreateObj('div', div+'_img', galist[gacurs], 'position:relative; top:0px; left:0px; width:'+width+'px; height:'+height+'px; filter:Alpha(opacity=0);', div);
		ga$(div)["onmouseover"] = new Function("gapause(false)");
		ga$(div)["onmouseout"] = new Function("gapause(true)");
	}else{
		gacreateObj('div', div+'_img', galist[gacurs], 'position:relative; top:0px; left:0px; width:'+width+'px; height:'+height+'px; opacity:0;', div);
		ga$(div).setAttribute("onmouseover", 'gapause(false)');
		ga$(div).setAttribute("onmouseout", 'gapause(true)');
	}
	//gacreateObj('div', div+'_text', '<br>'+parseInt(gacurs+1,10)+'/'+galist.length, 'color:#C7C7C7;', div+'_img');
	setTimeout(function(){gazoom(div+'_img', decal, time);}, 400);
	setTimeout(function(){gaauto_move(div, decal, time);}, parseInt(400+time+time,10));
}
