
/*** 
option :
sceneWidth : largeur du flash,
sceneHeight : hateur du flash,
cwidth : largeur du cube,
cheight : hauteur du cube,
cdepth : profondeur du cube
cpositionX, cpositionY, cpositionZ : position camera x, y et z
crotationX, crotationY, crotationZ : position camera x, y et z
objetFRONT, objetBACK, objetLEFT, objetRIGHT, objetTOP, objetBOTTOM : chemin de l'objet qui texture une face (gif, jpg ou flv)
linkFIRST, linkSECOND, linkTHIRD, linkFOURTH : lien de chaque face cliquable
dureePause : durée de pause entre deux mouvements du cube
dureeMvt : temps pour faire pivoter le cube
sensrotauto : sens de rotation du cube : LEFT, RIGHT, BOTTOM, TOP
anglevue : ecart de vue en degre (1 à 90), calcule en fonction du sens de rotation
*****/

var AutoRotation=true;
var AutoRotationTime = new Date().getTime();
var IsHover = false;
var CubeIsRot = false;
var udf = "undefined";
var Timer;

function cube3d(div, AutoRotationloc, option)
{
	versionplayerrequis = '10';
	AutoRotation = AutoRotationloc;
	IsHover = false;
	CubeIsRot = false;
	
	if (typeof option != udf)
	{
		for (i=0; i < option.length; i++)
		{
			var chaine;
			chaine = "" +option[i].split('=')[0]+ " = '"+option[i].split('=')[1];
			for (j=2; j < option[i].split('=').length; j++)
			{
				chaine += '=' + option[i].split('=')[j];
			}
			chaine +="';";
			eval(chaine);
		}
	}
	var version = deconcept.SWFObjectUtil.getPlayerVersion();	
	if (version['major'] >= versionplayerrequis)
	{
		var so = new SWFObject("/carte3d/swf/Flash3D.swf", "Flash3D", typeof sceneWidth!=udf?sceneWidth:300, typeof sceneHeight!=udf?sceneHeight:300, versionplayerrequis);
		so.addParam("wmode", "transparent");
		so.addParam("allowScriptAccess", "always");
		so.write(div);
		// initialisation
		setTimeout(function() {
			Swf('Flash3D').CubeSize(typeof cwidth!=udf?cwidth:5, typeof cheight!=udf?cheight:5, typeof cdepth!=udf?cdepth:5); // Taille du cube Largeur / Hauteur / profondeur
			Swf('Flash3D').CameraPosition(typeof cpositionX!=udf?cpositionX:0.1, typeof cpositionY!=udf?cpositionY:2.7, typeof cpositionZ!=udf?cpositionZ:-10); // Position camera gauche-droite / haut-bas / devans-deriere
			Swf('Flash3D').CameraRotation(typeof crotationX!=udf?crotationX:18, typeof crotationY!=udf?crotationY:0, typeof crotationZ!=udf?crotationZ:0); // Rotation camera
			//Swf('Flash3D').Rotation(typeof sensrotauto!=udf?sensrotauto:'LEFT', 1, typeof anglevue!=udf?anglevue:25); // rotation de depart 
			AttachObject('FRONT', typeof objetFRONT!=udf?objetFRONT:'');
			AttachObject('BACK', typeof objetBACK!=udf?objetBACK:'');
			AttachObject('LEFT', typeof objetLEFT!=udf?objetLEFT:'');
			AttachObject('RIGHT', typeof objetRIGHT!=udf?objetRIGHT:'');
			AttachObject('TOP', typeof objetTOP!=udf?objetTOP:'');
			AttachObject('BOTTOM', typeof objetBOTTOM!=udf?objetBOTTOM:'');
			tourne('LEFT');
		},1000);
	}
}

function arrondir(num)
{
	return Math.round(num*100)/100;
}

//axe : retourne l'axe suivant le sens de rotation
function axe(sens)
{
	var result;
	switch (sens)
	{
		case 'LEFT':case'RIGHT': result = 'Y';break;
		case 'TOP':case'BOTTOM': result = 'X';break;
	}
	return result;
}

//inverse : retourne le sens inverse du sens passe en parametre 
function inverse(sens)
{
	var result;
	switch (sens)
	{
		case 'LEFT': result = 'RIGHT';break;
		case 'RIGHT': result = 'LEFT';break;
		case 'TOP': result = 'BOTTOM';break;
		case 'BOTTOM': result = 'TOP';break;
	}
	return result;
}

// pointeur sur ID
function Swf(pName){
	if(navigator.appName.indexOf("Microsoft") != -1){
		return window[pName];
	}else{
		return document[pName];
	}
}

//attache un objet à une face
function AttachObject(face, object)
{
	if (object.split('.')[1] == 'flv' || object.split('.')[1] == 'swf')
	{
		Swf('Flash3D').AttachVideo(face, object, 185,185);
	}
	else
	{
		Swf('Flash3D').AttachImage(face, object);
	}
}
// Rotation
function Rotate(pAxe, tpsrot){
	AutoRotationTime = new Date().getTime();
	if (!tpsrot) tpsrot=1000;
	switch(pAxe){
		case 'LEFT':   Swf('Flash3D').Rotation('LEFT', tpsrot, 90);   break;
		case 'RIGHT':  Swf('Flash3D').Rotation('RIGHT', tpsrot, 90);  break;
		case 'TOP':    Swf('Flash3D').Rotation('TOP', tpsrot, 90);    break;		
		case 'BOTTOM': Swf('Flash3D').Rotation('BOTTOM', tpsrot, 90); break;
	}
}

function Actions(){
	switch(Math.round(Math.abs((Swf('Flash3D').Angle(axe(sensrotauto))/90)%4))){
		case 0:
			if(document.domain == "www.monabanq.com"){_hbLink('Face1+Espace+Client','left','0,0,300,300');}
			eval(linkFIRST);
			break;
		case 1:
			if(document.domain == "www.monabanq.com"){_hbLink('Face2+Espace+Personalise','left','0,0,300,300');}
			eval(linkSECOND);
			break;		
		case 2:
			if(document.domain == "www.monabanq.com"){_hbLink('Face3+monabanq+Premiere','left','0,0,300,300');}
			eval(linkTHIRD);
			break;	
		case 3:
			if(document.domain == "www.monabanq.com"){_hbLink('Face4+Espace+Client','left','0,0,300,300');}
			eval(linkFOURTH);
			break;
	};
}

function tourne(sens)
{
		if (!IsHover){Swf('Flash3D').Rotation(sens,5000, 360);}
		Timer = setTimeout(function(){tourne(sens)}, 10000);
}

function voirverso()
{
	Timer = clearTimeout(Timer);
	Swf('Flash3D').Rotation('LEFT',2000, 180);
}


function getCursor(e) {
	e = e || window.event;
	return {'x': e.clientX, 'y': e.clientY};
}

var debutx;

function eonmouseover(e)
{	
	IsHover =true;
	var cursor = getCursor(e);
	debutx = cursor.x;
}

function eonmouseout(e)
{
	//Timer = clearTimeout(Timer);
	IsHover =false;
}
function eonmousemove(e)
{
	//Timer = clearTimeout(Timer);
	var coeff = 3.5;
	var cursor = getCursor(e);
	var dx = cursor.x - debutx;
	debutx = cursor.x;
	if (dx<0){sens='LEFT';dx=-dx}else{sens='RIGHT'}
	Swf('Flash3D').Rotation(sens,1, dx*coeff);
}