var bpcvs,bpctx,bpstage;
var spcvs,spctx,spstage;
var btncvs,btnctx,btnstage;
var navcvs,navctx,navstage;
var oldid=0;
var pid=0;
var pid2=0;
var spmc,sparrow;
var bpmc,infomc;
var bpindexbtn1,bpindexbtn2,bpindexbtn3;
var infobtn;
var targetX;
var vx=0;
var sparr=[];
var sourcesarr=[];
var spimgarr=[];
var bpimgarr=[];
var sourcesimgarr=[];
var sploaded=0;
var bploaded=0;
var sourcesloaded=0;
var loadingmcbar;
var loadingtxt;
var indexbtn1down=true;
var indexbtn2down=false;
var indexbtn3down=false;
var curindeximg,newindeximg;
var cursppage=0;
var showinfo=true;
var navarrow,navtargetX;
var bpstartmove=false;
var spstartmove=false;
var bpstartmoveX;
var spstartmoveX;
var projecttitle;
var projecttextmc;
var bpimgmcarr=[];
var canshowarr=[];

function init(){
	bpcvs=document.getElementById("bpcanvas");
	bpctx=bpcvs.getContext("2d");
	spcvs=document.getElementById("spcanvas");
	spctx=spcvs.getContext("2d");
	navcvs=document.getElementById("navcanvas");
	navctx=navcvs.getContext("2d");
	
	bpstage = new Stage(bpctx);
	bpstage.setFrameRate(20);
	spstage=new Stage(spctx);
	spstage.setFrameRate(20);
	navstage=new Stage(navctx);
	navstage.setFrameRate(20);
	
	//spctx.beginPath(); 
	//spctx.rect(0, 0, 600, 80); 
	//spctx.clip();
	
	setuploadingbar();
	loadimg();
}
function loadimg(){
	var picloadFun=function(ptype){
		if(ptype=="sp"){
			sploaded++;
		}else if(ptype=="bp"){
			bploaded++;
		}else{
			sourcesloaded++;
		}
		loadingmcbar.scaleX=(sploaded+sourcesloaded)/(spurlarr.length+sourcesurlarr.length);
	}
	for(var i=0;i<spurlarr.length;i++){
		var img=new Image();
		img.src=spurlarr[i];
		img.onload=function(){
			picloadFun("sp");
		};
		sparr[i]=img;
	}
	for(i=0;i<sourcesurlarr.length;i++){
		var img=new Image();
		img.src=sourcesurlarr[i];
		img.onload=function(){
			picloadFun("sources");
		};
		sourcesarr[i]=img;
	}
}
function loadbpimg(i,j){
	//if(bpimgarr[i][j]==null||bpimgarr[i][j]==""){
		var img=new Image();
		img.src=bpurlarr[i][j];
		img.onload=function(){
			imgloadhandler(img,i,j);
		};
	//}else{
		//canshowarr[i][j]=1;
		//loadingtxt.visible=false;
	//}
}
function imgloadhandler(img,i,j){
	var bmp=new Bitmap(img);
	bpimgarr[i][j]=bmp;
	bpimgmcarr[i][j].addChild(bpimgarr[i][j]);
	bpimgmcarr[i][j].onMouseEvent=bponmousemove;
	canshowarr[i][j]=1;
	if(i==pid&&j==pid2){
		loadingtxt.visible=false;
		bpindexbtn1.visible=true;
		bpindexbtn2.visible=true;
		bpindexbtn3.visible=true;
		infobtn.visible=true;
	}
}
function start(){
	//===================================sp===========================================
	for(var i=0;i<sparr.length;i++){
		var bmp=new Bitmap(sparr[i]);
		bmp.y=15;
		bmp.pid=i;
		bmp.mouseEnabled=true;
		bmp.useHandCursor=true;
		bmp.onMouseEvent=spmousedown;
		spimgarr[i]=bmp;
	}
	spmc=new Sprite();
	spstage.addChild(spmc);
	for(i=0;i<spimgarr.length;i++){
		spimgarr[i].x=(52+8)*i+5;
		spmc.addChild(spimgarr[i]);
	}
	spmc.width=(52+8)*spimgarr.length;
	sparrow=new Shape();
	sparrow.graphics.beginFill("#ffffff");
	sparrow.graphics.lineStyle(1,"#ffffff");
	sparrow.graphics.moveTo(0,0);
	sparrow.graphics.lineTo(10,0);
	sparrow.graphics.lineTo(5,4);
	sparrow.graphics.lineTo(0,0);
	sparrow.graphics.endFill();
	sparrow.y=8;
	sparrow.x=26;
	spmc.addChild(sparrow);
	document.getElementById("splbtn").onclick=spleft;
	document.getElementById("sprbtn").onclick=spright;
	
	//=========================================infobtn==============================
	infomc=new Sprite();
	infomc.x=250;
	infomc.y=463;
	infomc.regY=260;
	infomc.alpha=0.91;
	infomc.scaleY=0.001;
	infomc.visible=false;
	var infomcbg=new Shape();
	infomcbg.graphics.beginFill("#ffffff");
	infomcbg.graphics.drawRoundRectComplex(0,0,700,260,0,0,10,10);
	infomcbg.graphics.endFill();
	infomc.addChild(infomcbg);
	projecttextmc=new Sprite();
	projecttextmc.x=250;
	projecttextmc.y=203;
	projecttextmc.visible=false;
	projecttitle=new Text();
	projecttitle.x=50;
	projecttitle.y=36;
	projecttitle.font=titlefont;
	projecttitle.color=titlefontcolor;
	projecttextmc.addChild(projecttitle);
	
	
	//=========================================bp==================================
	for(i=0;i<sourcesarr.length;i++){
		var bmp=new Bitmap(sourcesarr[i]);
		sourcesimgarr[i]=bmp;
	}
	
	var infoframes=[new Frame(sourcesimgarr[11],null,0,0,true),new Frame(sourcesimgarr[12],null,0,0,true)];
	infobtn=new MovieClip(infoframes);
	infobtn.x=844;
	infobtn.y=463;
	infobtn.mouseEnabled=true;
	infobtn.useHandCursor=true;
	infobtn.onMouseEvent=clickinfo;
	bpstage.addChild(infobtn);
	
	bpmc=new Sprite();
	bpmc.x=240;
	bpmc.mouseEnabled=true;
	//bpmc.onMouseEvent=bponmousemove;
	bpstage.addChild(bpmc);
	loadingtxt.x=550;
	loadingtxt.y=265;
	loadingtxt.text="Image loading";
	bpstage.addChild(loadingtxt);
	for(i=0;i<bpurlarr.length;i++){
		bpimgarr[i]=new Array(3);
	}
	for(i=0;i<bpurlarr.length;i++){
		bpimgmcarr[i]=new Array(3);
		bpimgmcarr[i][0]=new Sprite();
		bpimgmcarr[i][1]=new Sprite();
		bpimgmcarr[i][2]=new Sprite();
	}
	for(i=0;i<bpurlarr.length;i++){
		canshowarr[i]=new Array(3);
		canshowarr[i][0]=0;
		canshowarr[i][1]=0;
		canshowarr[i][2]=0;
	}
	for(i=0;i<bpimgmcarr.length;i++){
		for(j=0;j<3;j++){
			loadbpimg(i,j);
		}
	}
	//loadbpimg(0,0);
	curindeximg=bpimgmcarr[0][0];
	bpmc.addChild(curindeximg);
	
	
	document.getElementById("bplbtn").onclick=bpleft;
	document.getElementById("bprbtn").onclick=bpright;
	document.onkeydown=keyhandler;
	
	//=======================================bpindexbtn==============================
	
	var btn1frames=[new Frame(sourcesimgarr[0],null,0,0,true),new Frame(sourcesimgarr[1],null,0,0,true)];
	var btn2frames=[new Frame(sourcesimgarr[2],null,0,0,true),new Frame(sourcesimgarr[3],null,0,0,true)];
	var btn3frames=[new Frame(sourcesimgarr[4],null,0,0,true),new Frame(sourcesimgarr[5],null,0,0,true)];
	bpindexbtn1=new MovieClip(btn1frames);
	bpindexbtn2=new MovieClip(btn2frames);
	bpindexbtn3=new MovieClip(btn3frames);
	bpindexbtn1.gotoAndStop(2);
	bpindexbtn1.y=bpindexbtn2.y=bpindexbtn3.y=434;
	bpindexbtn1.x=260;
	bpindexbtn2.x=280;
	bpindexbtn3.x=300;
	bpindexbtn1.mouseEnabled=true;
	bpindexbtn1.useHandCursor=true;
	bpindexbtn2.mouseEnabled=true;
	bpindexbtn2.useHandCursor=true;
	bpindexbtn3.mouseEnabled=true;
	bpindexbtn3.useHandCursor=true;
	bpindexbtn1.onMouseEvent=bpindexbtn2.onMouseEvent=bpindexbtn3.onMouseEvent=bpindexbtndown;
	bpindexbtn1.btnname="indexbtn1";
	bpindexbtn2.btnname="indexbtn2";
	bpindexbtn3.btnname="indexbtn3";
	bpstage.addChild(bpindexbtn1);
	bpstage.addChild(bpindexbtn2);
	bpstage.addChild(bpindexbtn3);
	bpstage.addChild(infomc);
	bpstage.addChild(projecttextmc);
	
	bpindexbtn1.visible=false;
	bpindexbtn2.visible=false;
	bpindexbtn3.visible=false;
	infobtn.visible=false;
	
	//------------------------------------------navigation-------------------------------------
	for(i=6;i<11;i++){
		sourcesimgarr[i].x=144*(i-6);
		sourcesimgarr[i].y=10;
		sourcesimgarr[i].navindex=i-6;
		sourcesimgarr[i].mouseEnabled=true;
		sourcesimgarr[i].useHandCursor=true;
		sourcesimgarr[i].onMouseEvent=onchangenav;
		navstage.addChild(sourcesimgarr[i]);
	}
	navarrow=new Shape();
	navarrow.graphics.beginFill("#ffffff");
	navarrow.graphics.lineStyle(1,"#ffffff");
	navarrow.graphics.moveTo(0,0);
	navarrow.graphics.lineTo(10,0);
	navarrow.graphics.lineTo(5,4);
	navarrow.graphics.lineTo(0,0);
	navarrow.graphics.endFill();
	navarrow.y=1;
	navarrow.x=30;
	navstage.addChild(navarrow);
}
function onchangenav(e){
	if(e.type=="mousedown"){
		switch(e.target.navindex){
			case 0:
				navtargetX=30;
				break;
			case 1:
				window.location.href="over.html";
				navtargetX=174;
				break;
			case 2:
				window.location.href="diensten.html";
				navtargetX=318;
				break;
			case 3:
				window.location.href="contact.html";
				navtargetX=460;
				break;
			case 4:
				window.location.href="vacatures.html";
				navtargetX=610;
				break;
		}
		navstage.addEventListener(StageEvent.ENTER_FRAME,navmove);
	}
}
function navmove(){
	navarrow.x+=(navtargetX-navarrow.x)*0.3;
	if(Math.abs(navtargetX-navarrow)<1){
		navarrow.x=navtargetX;
		navstage.removeEventListener(StageEvent.ENTER_FRAME,navmove);
	}
}
function setuploadingbar(){
	loadingmcbar=new Shape();
	loadingmcbar.graphics.beginFill("#2f7ca5");
	loadingmcbar.graphics.drawRect(0,0,180,20);
	loadingmcbar.graphics.endFill();
	loadingmcbar.scaleX=0.1;
	loadingmcbar.x=495;
	loadingmcbar.y=225;
	bpstage.addChild(loadingmcbar);
	loadingtxt=new Text();
	loadingtxt.color="#ffffff";
	loadingtxt.x=497;
	loadingtxt.y=215;
	loadingtxt.text="De website wordt geladen: ";
	bpstage.addChild(loadingtxt);
	bpstage.addEventListener(StageEvent.ENTER_FRAME, checkpicloaded);
}
function checkpicloaded(){
	loadingtxt.text="De website wordt geladen: "+Math.floor((sploaded+sourcesloaded)/(spurlarr.length+sourcesurlarr.length)*100)+" %";
	if((sploaded+sourcesloaded)==(spurlarr.length+sourcesarr.length)){
		bpstage.removeEventListener(StageEvent.ENTER_FRAME, checkpicloaded);
		setTimeout("removeloading()",500);
	}
}
function removeloading(){
	bpstage.removeChild(loadingtxt);
	bpstage.removeChild(loadingmcbar);
	//loadingtxt=null;
	loadingmcbar=null;
	document.getElementById("bplbtn").style.display="none";
	document.getElementById("bprbtn").style.display="";
	document.getElementById("splbtn").style.display="";
	document.getElementById("sprbtn").style.display="";
	start();
}
function spleft(){
	if(spmc.x<0){
		document.getElementById("splbtn").onclick=null;
		document.getElementById("sprbtn").onclick=null;
		spstage.removeEventListener(StageEvent.ENTER_FRAME, moveleft);
		targetX=spmc.x;
		//console.log(targetX);
		spstage.addEventListener(StageEvent.ENTER_FRAME, moveright);
		//spmc.x+=600;
	}
	
}
function spright(){
	if(spmc.x>-Math.floor(spimgarr.length/10)*600){
		if(spmc.x!=-(spimgarr.length/10-1)*600){
			document.getElementById("splbtn").onclick=null;
			document.getElementById("sprbtn").onclick=null;
			spstage.removeEventListener(StageEvent.ENTER_FRAME, moveright);
			targetX=spmc.x;
			//console.log(targetX);
			spstage.addEventListener(StageEvent.ENTER_FRAME, moveleft);
			//spmc.x-=600;
		}
	}
}
function moveleft(){
	var dx=(targetX-600)-spmc.x;
	if(Math.abs(dx)<1){
		spmc.x=targetX-600;
		spstage.removeEventListener(StageEvent.ENTER_FRAME, moveleft);
		//document.getElementById("splbtn").onclick=spleft;
		//document.getElementById("sprbtn").onclick=spright;
		cursppage++;
		oldid=pid;
		pid=cursppage*10;
		pid2=0;
		if(pid==spimgarr.length-1)document.getElementById("bprbtn").style.display="none";
		else document.getElementById("bprbtn").style.display="";
		if(pid==0)document.getElementById("bplbtn").style.display="none";
		else document.getElementById("bplbtn").style.display="";
		onchangespbar();
	}else{
		spmc.x+=dx*speasing;
	}
}
function moveright(){
	var dx=(targetX+600)-spmc.x;
	if(Math.abs(dx)<1){
		spmc.x=targetX+600;
		spstage.removeEventListener(StageEvent.ENTER_FRAME, moveright);
		//document.getElementById("splbtn").onclick=spleft;
		//document.getElementById("sprbtn").onclick=spright;
		cursppage--;
		oldid=pid;
		pid=cursppage*10;
		pid2=0;
		if(pid==spimgarr.length-1)document.getElementById("bprbtn").style.display="none";
		else document.getElementById("bprbtn").style.display="";
		if(pid==0)document.getElementById("bplbtn").style.display="none";
		else document.getElementById("bplbtn").style.display="";
		onchangespbar();
	}else{
		spmc.x+=dx*speasing;
	}
}
function onchangespbar(){
	sparrow.x=spimgarr[pid].x+21;
	for(i=0;i<spimgarr.length;i++){
		spimgarr[i].onMouseEvent=null;
	}
	indexbtn1down=true;
	indexbtn2down=false;
	indexbtn3down=false;
	bpindexbtn1.gotoAndStop(2);
	bpindexbtn2.gotoAndStop(1);
	bpindexbtn3.gotoAndStop(1);
	bpindexbtn1.visible=false;
	bpindexbtn2.visible=false;
	bpindexbtn3.visible=false;
	infobtn.visible=false;
	infobtn.gotoAndStop(1);
	infomc.scaleY=0.001;
	infomc.visible=false;
	projecttextmc.removeAllChildren();
	projecttextmc.visible=false;
	showinfo=true;
	if(bpimgarr[pid][0]!=null){
		loadingtxt.visible=false;
		canshowarr[pid][0]=1;
	}else{
		loadingtxt.visible=true;
		canshowarr[pid][0]=0;
	}
	//loadbpimg(pid,0);
	newindeximg=bpimgmcarr[pid][0];
	if(pid>oldid){
		newindeximg.x=700;
	}else{
		newindeximg.x=-700;
	}
	newindeximg.alpha=0;
	bpmc.addChild(newindeximg);
	bpstage.addEventListener(StageEvent.ENTER_FRAME, changeproject1);
	bpindexbtn1.onMouseEvent=bpindexbtn2.onMouseEvent=bpindexbtn3.onMouseEvent=null;
}
function spmousedown(e){
	if(e.type=="mousedown"){
		spstartmove=true;
		spstartmoveX=spstage.mouseX;
	}
	if(e.type=="mouseup" && spstartmove){
		spstartmove=false;
		if((spstartmoveX-spstage.mouseX)>0){
			spright();
		}else if((spstartmoveX-spstage.mouseX)<0){
			spleft();
		}else{
			sparrow.x=e.target.x+21;
			if(pid==e.target.pid){
			
			}else{
				for(i=0;i<spimgarr.length;i++){
				spimgarr[i].onMouseEvent=null;
				}
				oldid=pid;
				pid=e.target.pid;
				pid2=0;
				if(pid==spimgarr.length-1)document.getElementById("bprbtn").style.display="none";
				else document.getElementById("bprbtn").style.display="";
				if(pid==0)document.getElementById("bplbtn").style.display="none";
				else document.getElementById("bplbtn").style.display="";
				indexbtn1down=true;
				indexbtn2down=false;
				indexbtn3down=false;
				bpindexbtn1.gotoAndStop(2);
				bpindexbtn2.gotoAndStop(1);
				bpindexbtn3.gotoAndStop(1);
				bpindexbtn1.visible=false;
				bpindexbtn2.visible=false;
				bpindexbtn3.visible=false;
				infobtn.visible=false;
				infobtn.gotoAndStop(1);
				infomc.scaleY=0.001;
				infomc.visible=false;
				projecttextmc.removeAllChildren();
				projecttextmc.visible=false;
				showinfo=true;
				if(bpimgarr[pid][0]!=null){
					loadingtxt.visible=false;
					canshowarr[pid][0]=1;
				}else{
					loadingtxt.visible=true;
					canshowarr[pid][0]=0;
				}
				//loadbpimg(pid,0);
				newindeximg=bpimgmcarr[pid][0];
				if(pid>oldid){
					newindeximg.x=700;
				}else{
					newindeximg.x=-700;
				}
				newindeximg.alpha=0;
				bpmc.addChild(newindeximg);
				for(i=6;i<11;i++){
					sourcesimgarr[i].onMouseEvent=null;
				}
				bpstage.addEventListener(StageEvent.ENTER_FRAME, changeproject1);
				bpindexbtn1.onMouseEvent=bpindexbtn2.onMouseEvent=bpindexbtn3.onMouseEvent=null;
			}
		}
	}
}
function bpleft(){
	if(pid!=0){
		document.getElementById("bplbtn").onclick=null;
		document.getElementById("bprbtn").onclick=null;
		document.getElementById("splbtn").onclick=null;
		document.getElementById("sprbtn").onclick=null;
		document.onkeydown=null;
		for(i=0;i<spimgarr.length;i++){
			spimgarr[i].onMouseEvent=null;
		}
		for(i=6;i<11;i++){
			sourcesimgarr[i].onMouseEvent=null;
		}
		oldid=pid;
		pid--;
		pid2=0;
		if(pid==spimgarr.length-1)document.getElementById("bprbtn").style.display="none";
		else document.getElementById("bprbtn").style.display="";
		if(pid==0)document.getElementById("bplbtn").style.display="none";
		else document.getElementById("bplbtn").style.display="";
		sparrow.x=spimgarr[pid].x+21;
		if(!(oldid%10)){
			spmc.x+=600;
			cursppage--;
		}
		indexbtn1down=true;
		indexbtn2down=false;
		indexbtn3down=false;
		bpindexbtn1.gotoAndStop(2);
		bpindexbtn2.gotoAndStop(1);
		bpindexbtn3.gotoAndStop(1);
		bpindexbtn1.visible=false;
		bpindexbtn2.visible=false;
		bpindexbtn3.visible=false;
		infobtn.visible=false;
		infobtn.gotoAndStop(1);
		infomc.scaleY=0.001;
		infomc.visible=false;
		projecttextmc.removeAllChildren();
		projecttextmc.visible=false;
		showinfo=true;
		if(bpimgarr[pid][0]!=null){
					loadingtxt.visible=false;
					canshowarr[pid][0]=1;
				}else{
					loadingtxt.visible=true;
					canshowarr[pid][0]=0;
				}
		//loadbpimg(pid,0);
		newindeximg=bpimgmcarr[pid][0];
		newindeximg.x=-700;
		newindeximg.alpha=0;
		bpmc.addChild(newindeximg);
		bpstage.addEventListener(StageEvent.ENTER_FRAME, changeproject1);
		bpindexbtn1.onMouseEvent=bpindexbtn2.onMouseEvent=bpindexbtn3.onMouseEvent=null;
	}
}
function bpright(){
	if(pid!=spimgarr.length-1){
		document.getElementById("bplbtn").onclick=null;
		document.getElementById("bprbtn").onclick=null;
		document.getElementById("splbtn").onclick=null;
		document.getElementById("sprbtn").onclick=null;
		document.onkeydown=null;
		for(i=0;i<spimgarr.length;i++){
			spimgarr[i].onMouseEvent=null;
		}
		for(i=6;i<11;i++){
			sourcesimgarr[i].onMouseEvent=null;
		}
		oldid=pid;
		pid++;
		pid2=0;
		if(pid==spimgarr.length-1)document.getElementById("bprbtn").style.display="none";
		else document.getElementById("bprbtn").style.display="";
		if(pid==0)document.getElementById("bplbtn").style.display="none";
		else document.getElementById("bplbtn").style.display="";
		sparrow.x=spimgarr[pid].x+21;
		if((!(oldid%9))&&(oldid!=0)){
			spmc.x-=600;
			cursppage++;
		}
		indexbtn1down=true;
		indexbtn2down=false;
		indexbtn3down=false;
		bpindexbtn1.gotoAndStop(2);
		bpindexbtn2.gotoAndStop(1);
		bpindexbtn3.gotoAndStop(1);
		bpindexbtn1.visible=false;
		bpindexbtn2.visible=false;
		bpindexbtn3.visible=false;
		infobtn.visible=false;
		infobtn.gotoAndStop(1);
		infomc.scaleY=0.001;
		infomc.visible=false;
		projecttextmc.removeAllChildren();
		projecttextmc.visible=false;
		showinfo=true;
		if(bpimgarr[pid][0]!=null){
					loadingtxt.visible=false;
					canshowarr[pid][0]=1;
				}else{
					loadingtxt.visible=true;
					canshowarr[pid][0]=0;
				}
		//loadbpimg(pid,0);
		newindeximg=bpimgmcarr[pid][0];
		newindeximg.x=700;
		newindeximg.alpha=0;
		bpmc.addChild(newindeximg);
		bpstage.addEventListener(StageEvent.ENTER_FRAME, changeproject1);
		bpindexbtn1.onMouseEvent=bpindexbtn2.onMouseEvent=bpindexbtn3.onMouseEvent=null;
	}
}
function bpindexbtndown(e){
	if(e.type=="mousedown"){
		if(e.target.btnname=="indexbtn1"){
			if(indexbtn1down!=true){
				indexbtn1down=true;
				indexbtn2down=false;
				indexbtn3down=false;
				bpindexbtn1.gotoAndStop(2);
				bpindexbtn2.gotoAndStop(1);
				bpindexbtn3.gotoAndStop(1);
				pid2=0;
				if(bpimgarr[pid][0]!=null){
					loadingtxt.visible=false;
					canshowarr[pid][0]=1;
				}else{
					loadingtxt.visible=true;
					canshowarr[pid][0]=0;
				}
				//loadbpimg(pid,0);
				if(canshowarr[pid][pid2]==1){
					bpindexbtn1.visible=true;
					bpindexbtn2.visible=true;
					bpindexbtn3.visible=true;
					infobtn.visible=true;
				}else{
					bpindexbtn1.visible=false;
					bpindexbtn2.visible=false;
					bpindexbtn3.visible=false;
					infobtn.visible=false;
				}
				newindeximg=bpimgmcarr[pid][0];
				bpmc.addChild(newindeximg);
					newindeximg.alpha=0.01;
				bpstage.addEventListener(StageEvent.ENTER_FRAME, moveindeximg);
				bpindexbtn1.onMouseEvent=bpindexbtn2.onMouseEvent=bpindexbtn3.onMouseEvent=null;
			}
		}else if(e.target.btnname=="indexbtn2"){
			if(indexbtn2down!=true){
				indexbtn2down=true;
				indexbtn1down=false;
				indexbtn3down=false;
				bpindexbtn1.gotoAndStop(1);
				bpindexbtn2.gotoAndStop(2);
				bpindexbtn3.gotoAndStop(1);
				pid2=1;
				if(bpimgarr[pid][1]!=null){
					loadingtxt.visible=false;
					canshowarr[pid][1]=1;
				}else{
					loadingtxt.visible=true;
					canshowarr[pid][1]=0;
				}
				//loadbpimg(pid,1);
				if(canshowarr[pid][pid2]==1){
					bpindexbtn1.visible=true;
					bpindexbtn2.visible=true;
					bpindexbtn3.visible=true;
					infobtn.visible=true;
				}else{
					bpindexbtn1.visible=false;
					bpindexbtn2.visible=false;
					bpindexbtn3.visible=false;
					infobtn.visible=false;
				}
				newindeximg=bpimgmcarr[pid][1];
				bpmc.addChild(newindeximg);
					newindeximg.alpha=0.01;
				bpstage.addEventListener(StageEvent.ENTER_FRAME, moveindeximg);
				bpindexbtn1.onMouseEvent=bpindexbtn2.onMouseEvent=bpindexbtn3.onMouseEvent=null;
			}
		}else{
			if(indexbtn3down!=true){
				indexbtn3down=true;
				indexbtn1down=false;
				indexbtn2down=false;
				bpindexbtn1.gotoAndStop(1);
				bpindexbtn2.gotoAndStop(1);
				bpindexbtn3.gotoAndStop(2);
				pid2=2;
				if(bpimgarr[pid][2]!=null){
					loadingtxt.visible=false;
					canshowarr[pid][2]=1;
				}else{
					loadingtxt.visible=true;
					canshowarr[pid][2]=0;
				}
				//loadbpimg(pid,2);
				if(canshowarr[pid][pid2]==1){
					bpindexbtn1.visible=true;
					bpindexbtn2.visible=true;
					bpindexbtn3.visible=true;
					infobtn.visible=true;
				}else{
					bpindexbtn1.visible=false;
					bpindexbtn2.visible=false;
					bpindexbtn3.visible=false;
					infobtn.visible=false;
				}
				newindeximg=bpimgmcarr[pid][2];
				bpmc.addChild(newindeximg);
					newindeximg.alpha=0.01;
				bpstage.addEventListener(StageEvent.ENTER_FRAME, moveindeximg);
				bpindexbtn1.onMouseEvent=bpindexbtn2.onMouseEvent=bpindexbtn3.onMouseEvent=null;
			}
		}
	}
}
function moveindeximg(){
	//curindeximg.alpha+=(0-curindeximg.alpha)*0.2;
	//newindeximg.alpha+=(1-newindeximg.alpha)*0.2;
	curindeximg.alpha-=indexalphaspeed;
	newindeximg.alpha+=indexalphaspeed;
	if(curindeximg.alpha<=0||newindeximg.alpha>=1){
		//if(Math.abs(0-curindeximg.alpha)<0.001){
			newindeximg.alpha=1;
			bpmc.removeChild(curindeximg);
			curindeximg.alpha=1;
			curindeximg=null;
			curindeximg=newindeximg;
			newindeximg=null;
			if(canshowarr[pid][pid2]==1){
				bpindexbtn1.visible=true;
				bpindexbtn2.visible=true;
				bpindexbtn3.visible=true;
				infobtn.visible=true;
			}
			bpindexbtn1.onMouseEvent=bpindexbtn2.onMouseEvent=bpindexbtn3.onMouseEvent=bpindexbtndown;
			bpstage.removeEventListener(StageEvent.ENTER_FRAME, moveindeximg);
		}
	
}
function changeproject1(){
	
/*var changeX:Number=mc.x +(len-(targetX - mc.x-1))/.5;
if(changeX<=targetX) mc.x+=(len-(targetX - mc.x-1))/.5;
else {mc.x=targetX;removeEventListener(Event.ENTER_FRAME,enterHd);}*/

	if(pid>oldid){
		//curindeximg.x+=(-700-curindeximg.x)*0.3;
		//curindeximg.alpha+=(0-curindeximg.alpha)*0.3;
		curindeximg.x-=bpdisappearspeed;
		curindeximg.alpha-=bpdisappearalpha;
		if(curindeximg.x<=-700){
		//if(Math.abs(-700-curindeximg.x)<1){
			bpstage.removeEventListener(StageEvent.ENTER_FRAME, changeproject1);
			bpmc.removeChild(curindeximg);
			curindeximg.x=0;
			curindeximg.alpha=1;
			curindeximg=null;
			curindeximg=newindeximg;
			newindeximg=null;
			bpstage.addEventListener(StageEvent.ENTER_FRAME,changeproject2);
		}
	}else{
		//curindeximg.x+=(700-curindeximg.x)*0.3;
		//curindeximg.alpha+=(0-curindeximg.alpha)*0.3;
		curindeximg.x+=bpdisappearspeed;
		curindeximg.alpha-=bpdisappearalpha;
		if(curindeximg.x>=700){
		//if(Math.abs(700-curindeximg.x)<1){
			bpstage.removeEventListener(StageEvent.ENTER_FRAME, changeproject1);
			bpmc.removeChild(curindeximg);
			curindeximg.x=0;
			curindeximg.alpha=1;
			curindeximg=null;
			curindeximg=newindeximg;
			newindeximg=null;
			vx=0;
			bpstage.addEventListener(StageEvent.ENTER_FRAME,changeproject2);
		}
	}
}
function changeproject2(){
	
	var ax=(0-curindeximg.x)*spring;
	vx+=ax;
	vx*=friction;
	curindeximg.x+=vx;
	curindeximg.alpha+=(1-curindeximg.alpha)*0.1;
	if(Math.abs(vx)<0.03){
		curindeximg.x=0;
		curindeximg.alpha=1;
		if(canshowarr[pid][pid2]==1){
			bpindexbtn1.visible=true;
			bpindexbtn2.visible=true;
			bpindexbtn3.visible=true;
			infobtn.visible=true;
		}
		bpstage.removeEventListener(StageEvent.ENTER_FRAME,changeproject2);
		for(i=0;i<spimgarr.length;i++){
			spimgarr[i].onMouseEvent=spmousedown;
		}
		bpindexbtn1.onMouseEvent=bpindexbtn2.onMouseEvent=bpindexbtn3.onMouseEvent=bpindexbtndown;
		document.getElementById("bplbtn").onclick=bpleft;
		document.getElementById("bprbtn").onclick=bpright;
		document.getElementById("splbtn").onclick=spleft;
		document.getElementById("sprbtn").onclick=spright;
		document.onkeydown=keyhandler;
		for(i=6;i<11;i++){
			sourcesimgarr[i].onMouseEvent=onchangenav;
		}
	}
}
function clickinfo(e){
	if(e.type=="mousedown"){
		infobtn.onMouseEvent=null;
		if(showinfo){
			infobtn.gotoAndStop(2);
			infomc.visible=true;
			bpstage.addEventListener(StageEvent.ENTER_FRAME,showinfomc);
		}else{
			infobtn.gotoAndStop(1);
			projecttextmc.visible=false;
			projecttextmc.removeAllChildren();
			bpstage.addEventListener(StageEvent.ENTER_FRAME,hideinfomc);
		}
	}
}
function showinfomc(){
	infomc.scaleY+=(1-infomc.scaleY)*infoeasing;
	if(Math.abs(1-infomc.scaleY)<0.01){
		infomc.scaleY=1;
		bpstage.removeEventListener(StageEvent.ENTER_FRAME,showinfomc);
		projecttextmc.visible=true;
		
		projecttitle.text=projecttitlearr[pid];
		projecttextmc.addChild(projecttitle);
		var strarr=projecttextarr[pid].split("\n");
		for(i=0;i<strarr.length;i++){
			var txt=new Text();
			txt.x=50;
			txt.y=65+i*20;
			txt.font=infotextfont;
			txt.color=infotextfontcolor;
			txt.text=strarr[i];
			if(i==strarr.length-1){
				txt.color="#2f7ca5";
				txt.url="http://"+txt.text.replace(/^\s+|\s+$/g,"");
				txt.mouseEnabled=true;
				txt.useHandCursor=true;
				txt.onMouseEvent=gotoprojectpage;
			}
			projecttextmc.addChild(txt);
		}
		
		showinfo=!showinfo;
		infobtn.onMouseEvent=clickinfo;
	}
}
function hideinfomc(){
	infomc.scaleY+=(0.001-infomc.scaleY)*infoeasing;
	if(Math.abs(0.001-infomc.scaleY)<0.0005){
		infomc.scaleY=0.001;
		bpstage.removeEventListener(StageEvent.ENTER_FRAME,hideinfomc);
		showinfo=!showinfo;
		infobtn.onMouseEvent=clickinfo;
		infomc.visible=false;
	}
}
function gotoprojectpage(e){
	if(e.type=="mousedown"){
		window.open(e.target.url,"_blank");
		//window.location.href=e.target.url;
	}
}
function resizeFun(){
	var navtopnum=(window.innerHeight-60)<640?640:(window.innerHeight-42);
	document.getElementById("navdiv").style.top=navtopnum+"px";
	document.getElementById("navcanvas").style.left=(document.getElementById("bpcanvas").offsetLeft+275)+"px";
	document.getElementById("navcanvas").style.top=(navtopnum+6)+"px";
	document.getElementById("titletxt").style.marginLeft=document.getElementById("titletxt").offsetLeft<226?"220px":"310px";
}
function bponmousemove(e){
	if(e.type=="mousedown"){
		bpstartmove=true;
		bpstartmoveX=bpstage.mouseX;
	}
	if(e.type=="mouseup" && bpstartmove){
		bpstartmove=false;
		if((bpstartmoveX-bpstage.mouseX)>0){
			bpright();
		}else if((bpstartmoveX-bpstage.mouseX)<0){
			bpleft();
		}else{
			
		}
	}
}
function keyhandler(e){
	if(e.keyCode==37)bpleft();
	if(e.keyCode==39)bpright();
}
window.onscroll=function(){
	document.getElementById("navdiv").style.width=window.screen.availWidth+"px";
}
window.onload=function(){
	var navtopnum=(window.innerHeight-60)<640?640:(window.innerHeight-42);
	document.getElementById("navdiv").style.top=navtopnum+"px";
	document.getElementById("navcanvas").style.left=(document.getElementById("bpcanvas").offsetLeft+275)+"px";
	document.getElementById("navcanvas").style.top=(navtopnum+6)+"px";
	document.getElementById("titletxt").style.marginLeft=document.getElementById("titletxt").offsetLeft<226?"220px":"295px";
	window.onresize=resizeFun;
	init();
}
