DAN ZEN EXPO - CODE EXHIBIT - ZEN MIX


//////////////////  mash panels   ////////////////////

function function8() {
	prefix = "http://www.zenmix.com/mix.php?";	
	extend = u + "/" + panel.page8.mixes.value;
	panel.page9.link.text = prefix + extend;
	panel.page9.code.text = '<!-- Zen Mix code - you can set the width in two places... 500x375 and 400x300 work as well.  Note autoplay setting in two places --><object width="600" height="450" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"  align="middle"><param name="movie" value="http://www.zenmix.com/zenmix/mix.swf?'+extend+'" /><param name="allowScriptAccess" value="sameDomain" /><param name="FlashVars" value="autoplay=false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="http://www.zenmix.com/zenmix/mix.swf?'+extend+'" width="600" height="450" FlashVars="autoplay=false" quality="high" bgcolor="#ffffff" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
}
function function9() {
	temp = panel.page8.mixes.dataProvider.join("~");
	panel.page10.randomly.text = prefix + "{" + u + "/" + temp + "}";
	panel.page10.complex.text = prefix + "[user1/file1~(file2~file3)~file4]~user2/file5~user3/file6~{file7~[file8~file9]~file10}";
}


//////////////////  video play controls   ////////////////////

import mx.video.*;
mov.playPauseButton = control.myPlay;
mov.muteButton = control.myMute;
mov.seekBar = control.mySeek;

control._visible = false;
mov._visible = false;

mov.onEnterFrame = function() {
	if (this._visible == true && this.hitTest(_xmouse, _ymouse, false)) {
		if (_root._ymouse > this._y + this._height - 70) {
			control._x = this._x + this._width / 2 - control._width / 2;
			control._y = this._y + this._height - 30 - control._height / 2;
			control._visible = true;
		} else {
			control._visible = false;
		}
	} else {
		control._visible = false;
	}
}

//////////////////  mixes page - view edit delete   ////////////////////

logoPosX = logo._x;
logoPosY = logo._y;

panel.page8.view.onRelease = function() {	
	getURL("http://www.zenmix.com/mix.php?"+u+"/"+panel.page8.mixes.value, "mix");
	
}

panel.page8.edit.onRelease = function() {
	edit(panel.page8.mixes.value);
}

function edit(f) {
	myVars = new LoadVars();
	myVars.u = u;	
	myVars.f = f;	
	myVars.command = "getdata";
	newVars = new LoadVars();
	newVars.onLoad = edit2;
	myVars.sendAndLoad("http://www.zenmix.com/zenmix/mixes.php", newVars, "post");
}
function edit2() {		
 	myXML = new XML(newVars.filedata);
	myXML.ignoreWhite;	
	mm = myXML.childNodes[0];
	background._visible = false;

	pic._visible = false;
	mov._visible = false;
	if (lastm != "" && lastm !== undefined) {
		mov.stop();
	}
	panel.page4.title.text = (mm.attributes.title != undefined) ? unescape(mm.attributes.title) : "";
	panel.page4.keywords.text = (mm.attributes.keywords != undefined) ? unescape(mm.attributes.keywords) : "";
	panel.page5.filename.text = f = mm.attributes.id;	
	mm = myXML.childNodes[0].childNodes[0];
	logo._x = mm.attributes.x;
	logo._y = mm.attributes.y;
	mm = myXML.childNodes[0].childNodes[1];
	panel.page1.jpg.text = mm.attributes.file;
	pic.loadMovie(mm.attributes.file);
	pic._x = mm.attributes.x;
	pic._y = mm.attributes.y;
	picscale = mm.attributes.scale;
	mm = myXML.childNodes[0].childNodes[2];
	panel.page1.flv.text = mm.attributes.file;
	m = mm.attributes.file;
	if (m != lastm && m != "" && m != undefined) {
		lastm = m;
		mov.load(m);	
	}
	mov._x = mm.attributes.x;
	mov._y = mm.attributes.y;
	movscale = mm.attributes.scale;
	moveffect = mm.attributes.effect;
	panel.page3.effects.selectedIndex = moveffect;
	clearInterval(wid);
	wid = setInterval(setProps, 500);	
	lastF = f;
	lastData = currentData = newVars.filedata;
	trace (lastData);
	clearPanels();
	panel.page5._visible = true;
	if (panel.page1.flv.text == "" && panel.page1.jpg.text == "") {
		panel.page1.sample._visible = true;
	} else {
		panel.page1.sample._visible = false;
	}	
}
function setProps() {
	pic._visible = true;
	if (m != "" && m != undefined) {
		mov._visible = true;	
	}
	pic._xscale = pic._yscale = picscale;
	mov._xscale = mov._yscale = movscale;
	mov.blendMode = panel.page3.effects.value;
	clearInterval(wid);	
}

panel.page8.del.onRelease = function() {
	del(panel.page8.mixes.value);
}

function del(f) {
	myVars = new LoadVars();
	myVars.u = u;
	myVars.p = p;
	myVars.f = f;	
	myVars.command = "delete";
	newVars = new LoadVars();
	newVars.onLoad = del2;
	myVars.sendAndLoad("http://www.zenmix.com/zenmix/mixes.php", newVars, "post");
}
function del2() {	
	if (newVars.error == 0) {
		//load files into list
		mArray = newVars.mixes.split(",");
		mArray.pop();
		panel.page8.mixes.dataProvider = mArray;
		resetAssets();
	} 
}

function resetAssets() {
	pic._visible = mov._visible = false;
	background._visible = true;
	pic._xscale = pic._yscale = mov._xscale = mov._yscale = 100;
	pic._x = pic._y = 0;
	mov._x = 137; mov._y = 30;	
	panel.page5.filename.text = "";
	panel.page5.nextfile.text = "";	
	panel.page1.jpg.text = "";
	panel.page1.flv.text = "";
	lastP = lastM = null; 
	panel.page3.effects.selectedIndex = 0;
	panel.page1.sample._visible = true;
	logo._x = logoPosX;
	logo._y = logoPosY;
	f = null;
	m = null;
}

//////////////////  reporting   ////////////////////

function reportTool(u) {
	myVars3 = new LoadVars();
	myVars3.u = u;
	myVars3.command = "tool";
	newVars3 = new LoadVars();	
	newVars3.onLoad = null;
	myVars3.sendAndLoad("http://www.zenmix.com/zenmix/report.php", newVars3, "POST");
}

//////////////////  shared local object   ////////////////////

so = SharedObject.getLocal("zenmix","/"); 

// get rid of below

//so.data.uid = null;
//so.data.pass = null;
loginCheck = false;	


if (so.data.uid != "" && so.data.uid != undefined && so.data.uid != null) {	
	u = so.data.uid;
	p = so.data.pass;
	reportTool(u);
	loginCheck = true;
}

//////////////////  signup   ////////////////////

function signup(u,p,c,e,r,t) {
	clearPanels();
	panel.signup2._visible = true;
	myVars = new LoadVars();
	myVars.u = u;	
	myVars.p = p;
	myVars.c = c;	
	myVars.e = e;
	myVars.r = r;	
	myVars.t = t;	
	newVars = new LoadVars();
	newVars.onLoad = signup2;
	myVars.sendAndLoad("http://www.zenmix.com/zenmix/signup.php", newVars, "post");
}
function signup2() {		
	if (newVars.error == 0) {	
		// set local object if checked	
		if (r == 1) {
			so.data.uid = u;
			so.data.pass = p;
		}
		so.data.c = u; // used to track creator views
		clearPanels();
		loginCheck = true;
		if (f == "") {
			panel.page8._visible = true;						
		} else {
			processFile(f);
		}
	} else if (newVars.error == 1) {		
		panel.signup2.myText.text = "SIGN UP:  Sorry, that username is taken\nClick Prev to try again.";
	} else {
		panel.signup2.myText.text = "SIGN UP:  Sorry, there seems to be a problem\nClick Prev to try again.";
	}
}

panel.signup2.prev.onRelease = function() {
	clearPanels();
	panel.signup2.myText.text = "SIGN UP:  contacting...";
	panel.signup._visible = true;
}

panel.signup.next.onRelease = function() {
	u = panel.signup.username.text;
	p = panel.signup.password.text;
	c = panel.signup.confirm.text;
	e = panel.signup.email.text;
	r = panel.signup.remember.value * 1;
	t = panel.signup.telepathy.value * 1;
	
	if (u == undefined || u == "" || p == undefined || p == "" || c == undefined || c == "" || e == undefined || e == "") {
		panel.signup.myText.text = "Sign Up:  please fill in the four text fields";
		return;
	} else if (u == "username (one word)" || p == "password" || c == "confirm password" || e == "e-mail") {
		panel.signup.myText.text = "Sign Up:  please fill in the four text fields";
		return;
	} else if (p != c) {
		panel.signup.myText.text = "Sign Up:  please match two text fields at right";
		return;
	}
	signup(u,p,c,e,r,t);
	
}

panel.signup.prev.onRelease = function() {
	clearPanels();
	panel.page6._visible = true;
}

passwordchange = new Object();
passwordchange.change = function(obj) {
	obj.target.password = true;
}
panel.signup.password.addEventListener("change",passwordchange);
panel.signup.confirm.addEventListener("change",passwordchange);



//////////////////  login   ////////////////////

function function6() {
	u = panel.page6.username.text;
	p = panel.page6.password.text;
	panel.page7.myText.text = "LOGIN:  verifying...";
	login(u,p);
}

function login(u,p) {
	myVars = new LoadVars();
	myVars.u = u;
	myVars.p = p;
	
	if (u == "" || u == undefined || p == "" || p == undefined) {
		panel.page7.myText.text = "LOGIN:  please go back and enter a username\nand password or to sign up...";
		return;
	}
	
	newVars = new LoadVars();
	newVars.onLoad = login2;
	myVars.sendAndLoad("http://www.zenmix.com/zenmix/login.php", newVars, "post");
}
function login2() {	
	if (newVars.error == 0) {
		loginCheck = true;	
		reportTool(u)
		processFile(f);
	} else if (newVars.error == 1) {
		panel.page7.myText.text = "LOGIN:  Sorry, that username is not found\nClick Prev to sign up or try again.";
	} else if (newVars.error == 2) {
		panel.page7.myText.text = "LOGIN:  Sorry, that password is not correct\nClick Prev to try again or get a hint.";
	} else {
		panel.page7.myText.text = "LOGIN:  Sorry, there seems to be a problem\nClick Prev to try again or get a hint.";
	}
}

panel.page6.mail.onRelease = function() {
	myVars = new LoadVars();
	myVars.u = panel.page6.username.text;
	myVars.command = "mailhint";
	newVars = new LoadVars();
	newVars.onLoad = mail2;
	rand = Math.round(Math.random()*1000000);
	myVars.sendAndLoad("http://www.zenmix.com/zenmix/mixes.php?r="+rand, newVars, "post");
}

function mail2() {
	panel.page6.underline._visible = false;
	if (newVars.error == 0) {
		panel.page6.hint.text = "Username:\n\nPassword (sent):";
	} else {
		panel.page6.hint.text = "Username:\n\nPassword (error):";
	}		
}		
panel.page6.click.onRelease = function() {
	clearPanels();
	panel.signup._visible = true;
}


//////////////////  blend   ////////////////////


var myChange:Object = new Object();
myChange.change = function(eventObject:Object) {
	effect = panel.page3.effects.value;
	if (effect != "" && effect != "----------") {
		mov.blendMode = effect;
	} else {
		mov.blendMode = "normal";		
	}
};
panel.page3.effects.addEventListener("change",myChange);



//////////////////  saving file   ////////////////////


function function5() {
	f = panel.page5.filename.text;
	n = panel.page5.nextfile.text;
	clearPanels();
	if (loginCheck == null || loginCheck == false) {
		// to login screen
		panel.page6._visible = true;	
		return;
	}
	processFile(f);
} 

function makeFileData() {
	// this makes all the xml for file information that gets stored in the database	
	string = ''; 	
	string += '<mix author="'+u+'" id="'+f+'" title="'+escape(panel.page4.title.text)+'" keywords="'+escape(panel.page4.keywords.text)+'">';
	string += '<logo x="'+logo._x+'" y="'+logo._y+'" />';
	string += '<picture file="'+panel.page1.jpg.text+'" x="'+pic._x+'" y="'+pic._y+'" scale="'+pic._xscale+'" />';
	string += '<video file="'+panel.page1.flv.text+'" x="'+mov._x+'" y="'+mov._y+'" scale="'+mov._xscale+'" effect="'+panel.page3.effects.selectedIndex+'" />';
	string += '<caption />';
	string += '</mix>';	
/*	
<mix author="uid" id="filename" nextid="secondfile">
	<logo x="111" y="222" />
	<picture file="someurl" x="0" y="0" scale="100" />
	<video file="someurl" x="0" y="0" scale="100" effect="0" />	
	<caption />
</mix>
*/	
	return string;	
}

function setFile(f) {
	// sets the file select to the current file
	if (f == undefined || f == null || f == "") {return;}
	for (i=0; i<panel.page8.mixes.dataProvider.length; i++) {
		if (f == panel.page8.mixes.dataProvider[i]) {
			panel.page8.mixes.selectedIndex = i;			
			return;
		}
	}
}

function processFile(f) {
	// if same filename as last time see if file changes	
	
	currentData = makeFileData();
	trace ("cd="+currentData);
	if (f == lastF) {	
		// test to see if file has been changed since the last time		
		if (currentData == lastData) {
			clearPanels();
			setFile(f);
			panel.page8._visible = true;				
		} else {
			confirm(f);
		}
	} else {
		// changed file name
		// check to see if filename already exists
		checkFileName(f)
	}
}

function confirm(f) {
	clearPanels();
	panel.pageConfirm._visible = true;
	panel.pageConfirm.confirm.text = f;
}

panel.pageConfirm.no.onRelease = function() {
	saveFile("");
}

panel.pageConfirm.yes.onRelease = function() {
	saveFile(f);	
}


function checkFileName(f) {
	// sees if filename f already exists in user's files
	myVars = new LoadVars();
	myVars.f = f;
	myVars.u = u;
	myVars.command = "checkfile";
	newVars = new LoadVars();
	newVars.onLoad = checkFileName2;
	rand = Math.round(Math.random()*1000000);
	myVars.sendAndLoad("http://www.zenmix.com/zenmix/mixes.php?r="+rand, newVars, "post");
}

function checkFileName2() {
	if (newVars.error == 1) {
		confirm(f);
	} else {
		saveFile(f);
	}		
}		

function saveFile(f) {
	lastF = f;
	lastData = currentData;
	myVars = new LoadVars();
	myVars.u = u;
	myVars.p = p;
	myVars.f = f;
	myVars.d = currentData;
	myVars.tt = Math.round(mov.totalTime);
	myVars.command = "savemixes";
	newVars = new LoadVars();
	newVars.onLoad = savefile2;
	rand = Math.round(Math.random()*1000000);
	myVars.sendAndLoad("http://www.zenmix.com/zenmix/mixes.php?r="+rand, newVars, "post");
}
function savefile2() {	
	if (newVars.error == 0) {
		//load files into list
		mArray = newVars.mixes.split(",");
		mArray.pop(); 
		panel.page8.mixes.dataProvider = mArray;
	} 
	clearPanels();
	setFile(f);
	panel.page8._visible = true;		

}


//////////////////  resize and positioning   ////////////////////


this.onKeyDown = function() {
	if (Key.getCode() == Key.CONTROL) {
		mov.onPress = pic.onPress = function() {
			if (moveMe != null) {return;}
			moveMe = this;			
			this.startDrag();			
		}
		mov.onMouseUp = pic.onMouseUp = logo.onMouseUp = function() {
			this.stopDrag();
			moveMe = null;
		}
		logo.onPress = function() {
			if (moveMe != null) {return;}
			moveMe = this;					
			this.startDrag(false,0,0,sw,sh);			
		}
	}
	if (Key.getCode() == Key.SHIFT) {
		if (mov.onPress == null) {
			mov.onPress = pic.onPress = function() {
				if (scaleMe != null) {return;}
				scaleMe = this;				
				if (mouseX == null) {
					mouseX = _root._xmouse;
					startScale = scaleMe._xscale;
					this._parent.onEnterFrame = function() {
						distance = _root._xmouse - mouseX;
						scale = startScale + distance;
						scaleMe._xscale =  scaleMe._yscale = scale;
					}
				}
			}
			mov.onMouseUp = pic.onMouseUp = function() {
				delete(this._parent.onEnterFrame);
				mouseX = null;
				scaleMe = null;
			}
		}
	}	
}
this.onKeyUp = function() {
	if (Key.getCode() == Key.CONTROL) {
		delete(mov.onPress);
		delete(mov.onRelease);
		mov.stopDrag();
		delete(pic.onPress);
		delete(pic.onRelease);
		pic.stopDrag();	
		delete(logo.onPress);
		delete(logo.onRelease);
		logo.stopDrag();	
		moveMe = null;
	}		
	if (Key.getCode() == Key.SHIFT) {
		delete(mov.onPress);
		delete(mov.onRelease);
		delete(pic.onPress);
		delete(pic.onRelease);
		delete(this.onEnterFrame);
		scaleMe = null;
	}
}
Key.addListener(this);


//////////////////  assets   ////////////////////

mov._visible = false;
function function1() {	
	var m = panel.page1.flv.text;
	if (m != "" && m != lastm) {
		mov._visible = true;
		lastm = m;
		mov.load(m);
		mov._x = 146;
		mov._y = 42;
		mov._xscale = mov._yscale = 100;		
		background._visible = false;
	}
	if (m == "" || m == undefined) {
		mov._visible = false;
	}
	var p = panel.page1.jpg.text;
	if (p != "" & p != lastp) {
		pic._visible = true;
		lastp = p;
		pic.loadMovie(p);
		pic._x = 0;
		pic._y = 0;
		pic._xscale = pic._yscale = 100;
		background._visible = false;
	}	
	if (p == "" || p == undefined) {
		pic._visible = false;
	}	
	if ((p == "" || p == undefined) && (m == "" || m == undefined)) {
		background._visible = true;
	}		
	
}
myChange = new Object();
myChange.change = function() {
	if (panel.page1.flv.text == "" && panel.page1.jpg.text == "") {
		panel.page1.sample._visible = true;
	} else {
		panel.page1.sample._visible = false;
	}
}
panel.page1.flv.addEventListener("change", myChange);
panel.page1.jpg.addEventListener("change", myChange);

panel.page1.sample.onRelease = function() {
	panel.page1.jpg.text = "http://static.flickr.com/68/165699313_337b94b982_o.jpg";
	panel.page1.flv.text = "http://80.media.vimeo.com/d1/clips/2006/06/05/vimeo.144280.e65890.flv";	
	//panel.page1.flv.text = "http://clips2.vimeo.com/video_files/2006/06/05/vimeo.144280.e65890.flv";	
	panel.page1.sample._visible = false;
}


//////////////////  initial conditions   ////////////////////


//panel.page1.jpg.text = "http://static.flickr.com/59/157113841_f7e5785de1_o.jpg";
//panel.page1.jpg.text = "http://static.flickr.com/34/70325197_f45ba72635_o.jpg";
//panel.page1.flv.text = "http://clips2.vimeo.com/video_files/2006/06/05/vimeo.144280.e65890.flv";
//panel.page1.flv.text = "http://www.zenmix.com/zenmix/woods1.flv";
//panel.page1.jpg.text = "http://www.zenmix.com/zenmix/blurredtree.jpg";

panel.page6.click.tabEnabled = false;
panel.page6.mail.tabEnabled = false;

left = 0; top = 0;
sw = Stage.width;
sh = 450;
right = sw - panel._width;
bottom = sh - 121; // seems to have problem with this panel._height;

panel.signup.username.restrict = "A-Z_a-z\\-0-9";
panel.page5.filename.restrict = "A-Z_a-z\\-0-9";
panel.page5.nextfile.restrict = "A-Z_a-z\\-/0-9";
panel.page6.username.restrict = "A-Z_a-z\\-0-9";

smallPanel._visible = false;
panel.logo.onRelease = function() {
	smallPanel._x = panel._x;
	smallPanel._y = panel._y;	
	panel._visible = false;
	smallPanel._visible = true;
}
smallPanel.logo.onRelease = function() {
	panel._x = smallPanel._x;
	panel._y = smallPanel._y;	
	panel._visible = true;
	smallPanel._visible = false;
}
panel.backing.onPress = smallPanel.backing.onPress = function() {
	if (moveMe != null) {return;}
	if (scaleMe != null) {return;}
	moveMe = this;	
	this._parent.startDrag(false,left,top,right,bottom)
}
panel.backing.onMouseUp = smallPanel.backing.onMouseUp = function() {
	moveMe = null;
	this._parent.stopDrag();
}

logo.zen.onRollOver = logo.mix.onRollOver = function() {
	logo.zen.word._alpha = 50;
	logo.mix.word._alpha = 50;
}
logo.zen.onRollOut = logo.mix.onRollOut = function() {
	logo.zen.word._alpha = 0;
	logo.mix.word._alpha = 0;
}
logo.zen.onRelease = logo.mix.onRelease = function() {
	trace ("logo");
}

panel.signup.telep.onRelease = function() {
	getURL("http://www.zenmix.com/telepathy","telepathy");
}
panel.signup.priv.onRelease = function() {
	getURL("http://www.zenmix.com/help/privacy.html","privacy");
}

panels = 10;
function clearPanels() {
	for (i=1; i<=panels; i++) {
		pan = panel["page"+i];
		pan._visible = false;
	}
	panel.pageConfirm._visible = false;
	panel.signup._visible = false;
	panel.signup2._visible = false;
}
clearPanels();
for (i=1; i<=panels; i++) {	
	pan = panel["page"+i];
	pan.i = i;
	pan.next.onRelease = function() {			
		panel["page"+this._parent.i]._visible = false;
		i2=this._parent.i+1;
		panel["page"+i2]._visible = true;
		_root["function"+this._parent.i].call();
	}
	pan.prev.onRelease = function() {	
		panel["page"+this._parent.i]._visible = false;
		if (this._parent.i == 8) {
			i2 = 5;
		} else {
			i2=this._parent.i-1;
		}
		panel["page"+i2]._visible = true;
	}	
}

panel.page1._visible = true;