/*
Inspirated by YouTube random movies presentation
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 
*/

var IE=(navigator.appName=='Microsoft Internet Explorer')?true:false;
var rollover=false;

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;
	$getE(where).appendChild(newdiv);
}

function giveMe(param, from){
	if(param=='opa'){
		if(IE){
			var response = $getE(from).style.filter;
			var value=response.substring(14,response.length-1);
		}else{
			var response = $getE(from).style.opacity;
			var value = response;
		}
	}else{
		var response = eval('$getE(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++;
		$getE(id).style.top = top+'px';
		if(IE){
			opa=(opa<=90)?opa+10:opa;
			if($getE(id.substring(0,7)+'_txt')!=null){$getE(id.substring(0,7)+'_txt').style.filter = 'alpha(opacity='+opa+')';}
			$getE(id).style.filter = 'alpha(opacity='+opa+')';
		}else{
			opa=(opa<=0.9)?opa+0.1:opa;
			if($getE(id.substring(0,7)+'_txt')!=null){$getE(id.substring(0,7)+'_txt').style.opacity = opa;}
			$getE(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 decalbottom(id, decal, opa, interval){
	var top = giveMe('top', id);
	if(decal!=0){
		top--;
		$getE(id).style.top = top+'px';
		if(IE){
			opa=(opa>50)?opa-10:opa;
			if($getE(id.substring(0,7)+'_txt')!=null){$getE(id.substring(0,7)+'_txt').style.filter = 'alpha(opacity='+opa+')';}
			$getE(id).style.filter = 'alpha(opacity='+opa+')';
		}else{
			opa=(opa>0.6)?opa-0.1:opa;
			if($getE(id.substring(0,7)+'_txt')!=null){$getE(id.substring(0,7)+'_txt').style.opacity = opa;}
			
			$getE(id).style.opacity = opa;
		}
		decal--;
		setTimeout("decalbottom('"+id+"', '"+decal+"', '"+opa+"')", interval);
	}
}

function zoomOut(id, decal, time, settimeout){
	var interval = time/decal;
	var top = giveMe('top', id);
	if(decal>0 && (rollover || settimeout)){
		rollover=false;
		if(top>0){
			var opa = (IE)?100:1.0;
			decalbottom(id, decal, opa, interval);
		}
	}
}

function screenshot_viewer(container, div, width, height, img, decal, time, desc, widthbig, heightbig){
	createObj('div', div, '', 'width:'+width+'px; height:'+parseInt(height+decal,10)+'px; float:left;', container);
	if(IE){
		var dir = 'http://www.sarbacane.com/'+img.substring(0,img.length-4)+'big.gif';
		createObj('div', div+'_img', '<a OnClick="open_window(\''+dir+'\', \'\', '+widthbig+', '+heightbig+');" title="'+desc+'"><img src="'+img+'" style="cursor:pointer;"></a>', 'position:relative; top:0px; left:0px; height:'+height+'px; filter:Alpha(opacity=50);', div);
		createObj('div', div+'_txt', desc, 'filter:Alpha(opacity=50); padding:4 0 0 0; text-align:center;', div);
		//$getE(div+'_img').setAttribute("onclick", function(){open_window(dir, desc, widthbig, heightbig)});
		$getE(div).setAttribute("onmouseover", function(){zoom(div+"_img", decal, time)});
		$getE(div).setAttribute("onmouseout", function(){zoomOut(div+"_img", decal, time)});
	}else{
		createObj('div', div+'_img', '<img src="'+img+'" style="cursor:pointer;">', 'position:relative; top:0px; left:0px; height:'+height+'px; opacity:0.5;', div);
		createObj('div', div+'_txt', desc, 'padding:4 0 0 0; text-align:center; opacity:0.5;', div);
		$getE(div).setAttribute("onclick", 'open_window(\'./'+img.substring(0,img.length-4)+'big.gif\',\''+desc+'\','+widthbig+','+heightbig+')');
		$getE(div).setAttribute("onmouseover", 'zoom(\''+div+'_img\','+decal+','+time+')');
		$getE(div).setAttribute("onmouseout", 'zoomOut(\''+div+'_img\','+decal+','+time+')');
	}
}

function next(div, decal, time){
	var opacity=(IE)?'filter:Alpha(opacity=50);':'opacity:0.5;';
	createObj('div', 'next', '', 'height:123px;', div);
	createObj('div', 'nextone', '<a href="http://www.sarbacane.com/routage_emailing.asp" title="En savoir plus"><img src="http://www.sarbacane.com/img/icon/next.gif"></a>', 'position:relative; top:0px; left:0px; float:left; '+opacity, 'next');
	if(IE){
		$getE('next').setAttribute("onmouseover", function(){zoom("nextone", decal, time)});
		$getE('next').setAttribute("onmouseout", function(){zoomOut("nextone", decal, time)});
	}else{
		$getE('next').setAttribute("onmouseover", 'zoom(\'nextone\','+decal+','+time+')');
		$getE('next').setAttribute("onmouseout", 'zoomOut(\'nextone\','+decal+','+time+')');
	}
}
