/*
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
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 list=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 curs=0; // Element by default, pay attention, it's starts with the first element at 0
*/

/* ----------------------------------------------- */

var IE=(navigator.appName=='Microsoft Internet Explorer')?true:false;
var rollover=false;
var not_paused=true;

function $(id){return document.getElementById(id);}

function open_window(page,titre,width,height){
	var largeur = (IE)?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 createObj(type, id, content, style, where){
	var newdiv = document.createElement(type);
	newdiv.setAttribute('id', id);
	newdiv.setAttribute('name', id);
	if(IE){
		newdiv.style.setAttribute('cssText', style);
	}else{
		newdiv.setAttribute('style', style);
	}
	newdiv.innerHTML = content;
	$(where).appendChild(newdiv);
}

function giveMe(param, from){
	if(param=='opa'){
		if(IE){
			var response = $(from).style.filter;
			var value=response.substring(14,response.length-1);
		}else{
			var value = $(from).style.opacity;
		}
	}else{
		var response = eval('$(from).style.'+param);
		var value = response.substring(0,response.indexOf('px'));
	}
	return value;
}

function decaltop(id, decal, opa, interval){
	var top = giveMe('top', id);
	if(decal!=0){
		top++;
		$(id).style.top = top+'px';
		if(IE){
			opa=(opa<=90)?opa+10:opa;
			if($(id.substring(0,7)+'_txt')!=null){$(id.substring(0,7)+'_txt').style.filter = 'alpha(opacity='+opa+')';}
			$(id).style.filter = 'alpha(opacity='+opa+')';
		}else{
			opa=(opa<=0.9)?opa+0.1:opa;
			if($(id.substring(0,7)+'_txt')!=null){$(id.substring(0,7)+'_txt').style.opacity = opa;}
			$(id).style.opacity = opa;
		}
		decal--;
		setTimeout("decaltop('"+id+"', '"+decal+"', '"+opa+"')", interval);
	}
}

function zoom(id, decal, time){
	var interval = time/decal;
	var top = giveMe('top', id);
	if(decal>0 && !rollover){
		rollover=true;
		if(top<decal){
			var opa = (IE)?100:1.0;
			decaltop(id, decal, opa, interval);
		}
	}
}

function tronquer(what,howmuch) {
	what = ''+what;
	if (what.indexOf('.') == -1) return what;
	var pos = parseInt(what.indexOf('.')+howmuch+1,10);
	return what.slice(0,pos);
}

function decalbottom(id, decal, opa, interval){
	var top = giveMe('top', id);
	if(decal!=0){
		top--;
		$(id).style.top = top+'px';
		if(IE){
			opa=(opa>=10)?opa-10:opa;
			if($(id.substring(0,7)+'_txt')!=null){$(id.substring(0,7)+'_txt').style.filter = 'alpha(opacity='+opa+')';}
			$(id).style.filter = 'alpha(opacity='+opa+')';
		}else{
			opa=(opa>=0.1)?tronquer(opa-0.1,1):opa;
			if($(id.substring(0,7)+'_txt')!=null){$(id.substring(0,7)+'_txt').style.opacity = opa;}
			$(id).style.opacity = opa;
		}
		decal--;
		setTimeout("decalbottom('"+id+"', '"+decal+"', '"+opa+"')", interval);
	}
}

function zoomOut(id, decal, time){
	var interval = time/decal;
	var top = giveMe('top', id);
	if(decal>0 && rollover){
		rollover=false;
		if(top>0){
			var opa = (IE)?100:1.0;
			decalbottom(id, decal, opa, interval);
		}
	}
}

function move(id, ind, decal, time){
	if(id.substring(id.length-4)=='_img'){id=id.substring(0, id.length-4);}
	if(ind!=0){zoomOut(id+'_img', decal, time);}
	curs=(ind==-1 && curs==0)?list.length-1:parseInt(curs+ind,10)%list.length;
	if(giveMe('opa', id+'_img')!=0){
		setTimeout(function(){move(id+'_img', 0, decal, time);}, 100);
	}else{
		$(id+'_img').innerHTML=list[curs];
		//createObj('div', id+'_text', '<br>'+parseInt(curs+1,10)+'/'+list.length, 'display:block; color:#C7C7C7;', id+'_img');
		setTimeout(function(){zoom(id+'_img', decal, time);}, 100);
	}
}

function pause(b){
	not_paused = b;
}

function auto_move(div, decal, time){
	if(not_paused){
		move(div, 1, decal, time);
	}
	setTimeout(function(){auto_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='';}
	createObj('div', div, '', 'width:'+width+'px; height:'+parseInt(decal+height,10)+'px; float:left;'+backgrd, container);
	if(IE){
		createObj('div', div+'_img', list[curs], 'position:relative; top:0px; left:0px; width:'+width+'px; height:'+height+'px; filter:Alpha(opacity=0);', div);
		$(div).setAttribute("onmouseover", function(){pause(false)});
		$(div).setAttribute("onmouseout", function(){pause(true)});
	}else{
		createObj('div', div+'_img', list[curs], 'position:relative; top:0px; left:0px; width:'+width+'px; height:'+height+'px; opacity:0;', div);
		$(div).setAttribute("onmouseover", 'pause(false)');
		$(div).setAttribute("onmouseout", 'pause(true)');
	}
	//createObj('div', div+'_text', '<br>'+parseInt(curs+1,10)+'/'+list.length, 'color:#C7C7C7;', div+'_img');
	setTimeout(function(){zoom(div+'_img', decal, time);}, 400);
	setTimeout(function(){auto_move(div, decal, time);}, parseInt(400+time+time,10));
}