//setup the panels with their animations and content animations
var panel = [
	{//Resources
		el:document.getElementById('panel-0'),
		content: document.getElementById('content-0'),
		outPos: new YAHOO.util.Anim('panel-0', {
				left: { to: -115 }
			}, 1, YAHOO.util.Easing.easeOut),
		overPos: new YAHOO.util.Anim('panel-0', {
				left: { to: -1 }
			}, 1, YAHOO.util.Easing.easeOut),
		offPos: new YAHOO.util.Anim('panel-0', {
				left: { to: -500 }
			}, 1,YAHOO.util.Easing.easeIn),
		contentInPos: new YAHOO.util.Anim('content-0', {
				left: { to: 20 }
			}, .75, YAHOO.util.Easing.easeIn),
		contentOutPos: new YAHOO.util.Anim('content-0', {
				left: { to: -1200 }
			}, .75, YAHOO.util.Easing.easeIn),
		left:-115,
		panel:0
	},
	{//Sessions
		el:document.getElementById('panel-1'),
		content: document.getElementById('content-1'),
		outPos: new YAHOO.util.Anim('panel-1', {
				left: { to: 140 }
			}, 1, YAHOO.util.Easing.easeOut),
		overPos: new YAHOO.util.Anim('panel-1', {
				left: { to: 210 }
			}, 1, YAHOO.util.Easing.easeOut),
		underPos: new YAHOO.util.Anim('panel-1', {
				left: { to: 20 }
			}, 1, YAHOO.util.Easing.easeOut),
		offPos: new YAHOO.util.Anim('panel-1', {
				left: { to: -500 }
			}, 1,YAHOO.util.Easing.easeIn),
		contentInPos: new YAHOO.util.Anim('content-1', {
				left: { to: 20 }
			}, .75, YAHOO.util.Easing.easeIn),
		contentOutPos: new YAHOO.util.Anim('content-1', {
				left: { to: -1200 }
			}, .75, YAHOO.util.Easing.easeIn),
		left:150,
		panel:1
	},
	{//Registration
		el:document.getElementById('panel-2'),
		content: document.getElementById('content-2'),
		outPos: new YAHOO.util.Anim('panel-2', {
				height: { to: 281 },
				width: { to: 281 },
				top: { to: 175 },
				left: { to: 360 }
			}, 1, YAHOO.util.Easing.easeOut),
		overPos: new YAHOO.util.Anim('panel-2', {
				height: { to: 430 },
				width: { to: 430 },
				top: { to: 110 },
				left: { to: 285 }
			}, 1, YAHOO.util.Easing.easeOut),
		offPos: new YAHOO.util.Anim('panel-2', {
				left: { to: -500 }
			}, 1,YAHOO.util.Easing.easeIn),
		contentInPos: new YAHOO.util.Anim('content-2', {
				left: { to: 20 }
			}, .75, YAHOO.util.Easing.easeIn),
		contentOutPos: new YAHOO.util.Anim('content-2', {
				left: { to: -1200 }
			}, .75, YAHOO.util.Easing.easeIn),
		height:281,
		width:281,
		top:175,
		left:360,
		panel:2
	},
	{//Calendar
		el:document.getElementById('panel-3'),
		content: document.getElementById('content-3'),
		outPos: new YAHOO.util.Anim('panel-3', {
				left: { to: 604 }
			}, 1, YAHOO.util.Easing.easeOut),
		overPos: new YAHOO.util.Anim('panel-3', {
				left: { to: 534 }
			}, 1, YAHOO.util.Easing.easeOut),
		underPos: new YAHOO.util.Anim('panel-3', {
				left: { to: 724 }
			}, 1, YAHOO.util.Easing.easeOut),
		offPos: new YAHOO.util.Anim('panel-3', {
				left: { to: -500 }
			}, 1,YAHOO.util.Easing.easeIn),
		contentInPos: new YAHOO.util.Anim('content-3', {
				left: { to: 20 }
			}, .75, YAHOO.util.Easing.easeIn),
		contentOutPos: new YAHOO.util.Anim('content-3', {
				left: { to: -1200 }
			}, .75, YAHOO.util.Easing.easeIn),
		left:594,
		panel:3
	},
	{//Testimonials
		el: document.getElementById('panel-4'),
		content: document.getElementById('content-4'),
		outPos: new YAHOO.util.Anim('panel-4', {
				left: { to: 790 }
			}, 1, YAHOO.util.Easing.easeOut),
		overPos: new YAHOO.util.Anim('panel-4', {
				left: { to: 675 }
			}, 1, YAHOO.util.Easing.easeOut),
		offPos: new YAHOO.util.Anim('panel-4', {
				left: { to: -500 }
			}, 1,YAHOO.util.Easing.easeIn),
		contentInPos: new YAHOO.util.Anim('content-4', {
				left: { to: 20 }
			}, .75, YAHOO.util.Easing.easeIn),
		contentOutPos: new YAHOO.util.Anim('content-4', {
				left: { to: -1200 }
			}, .75, YAHOO.util.Easing.easeIn),
		left:790,
		panel:4
	}
];

var currentContentPanel = false;
var videoPanel = {};

//initialize the page
YAHOO.util.Event.onDOMReady(pageInit);
function pageInit(){
	//adjust middle panel
	panel[2].el.style.height = panel[2].height+'px';
	panel[2].el.style.widht = panel[2].widht+'px';
	panel[2].el.style.top = panel[2].top+'px';

	//add link for last animated item
	panel[0].outPos.onComplete.subscribe(function(){
			for(i=0;i<panel.length;i++){//add the listeners to the panels
				addListener(i);
			}
			YAHOO.util.Event.addListener('li-5',"click", homeClick);
			panelMouseOver(2);
			this.onComplete.unsubscribe();
		});

	var delay = 0;
	for(i=panel.length-1;i>=0;i--){//for each panel... animate them in
		setTimeout('panel['+i+'].outPos.animate();',delay += 300);
	}

	if(typeof(currentContentPanel)!='number'){//if this is a first call
		var bkgrnd = document.getElementById('background');
		var shim = document.getElementById('shim');
		shim.style.width = bkgrnd.offsetLeft+'px';
		shim.style.height = bkgrnd.offsetHeight+'px';
		shim.style.top = bkgrnd.offsetTop+'px';
		YAHOO.util.Event.addListener(window, 'resize', function(){document.getElementById('shim').style.width = document.getElementById('background').offsetLeft+'px';});
	}

	//setup accordian for the access to conference page
	var d = YAHOO.util.Dom;
	var aElArr = d.getElementsByClassName('accordian', 'div', 'meetingLinks');//get all accrodian elements
	for(var i = 0;i < aElArr.length;i++){
		var el = aElArr[i];
		var elDiv = d.getChildren(el)[1];
		if(i == 0){
			d.addClass(el,'accordianSelected');
		}
		d.addClass(elDiv,'accordianDiv');//add the appropriate class
		YAHOO.util.Event.addListener(el,'click',accordianClick,el,true);//add the appropriate event listeners
	}

	//create the video popup
	videoPanel = new YAHOO.widget.Panel('videoPanel',{
		close:true,
		modal:true,
		visible:false,
		fixedcenter:true,
		zindex:100
	});
	videoPanel.render('container');
	videoPanel.hideEvent.subscribe(function(){videoPanel.setBody('');});
}

function accordianClick(e){
	var d = YAHOO.util.Dom;
	d.removeClass(d.getElementsByClassName('accordianSelected'),'accordianSelected');//get the selected item and remove the selected title
	d.addClass(this,'accordianSelected');//add the class to the div
}
function videoClick(whichVideo,title){
	videoPanel.setHeader(title);
	videoPanel.setBody('<iframe src="resources/'+whichVideo+'/'+whichVideo+'.html" style="height:578px;width:720px;"></iframe>');
	videoPanel.show();
}
function videoClear(){
	videoPanel.setBody(' ');
	alert('body set');
}

function addListener(whichPanel){//add the listeners
	YAHOO.util.Event.addListener(panel[whichPanel].el, "mouseover", panelMouseOver, panel[whichPanel], true);
	YAHOO.util.Event.addListener(panel[whichPanel].el, "mouseout", panelMouseOut, panel[whichPanel], true);
	YAHOO.util.Event.addListener(panel[whichPanel].el, "click", panelClick, panel[whichPanel], true);
	YAHOO.util.Event.addListener('li-'+whichPanel,"click", panelClick, panel[whichPanel], true);
}
function removeListener(whichPanel){//remove the listeners
	YAHOO.util.Event.removeListener(panel[whichPanel].el, "mouseover", panelMouseOver);
	YAHOO.util.Event.removeListener(panel[whichPanel].el, "mouseout", panelMouseOut);
	YAHOO.util.Event.removeListener(panel[whichPanel].el, "click", panelClick);
	YAHOO.util.Event.addListener('li-'+whichPanel,"click", panelClick, panel[whichPanel], true);
}
function addPanelListener(whichPanel){
	YAHOO.util.Event.removeListener('li-'+whichPanel,"click", panelClick);
}

function panelMouseOver(whichPanel){
	thePanel = typeof(whichPanel)=='number'?panel[whichPanel]:this;
	for(i=0;i<panel.length;i++){//make sure all panels are in place
		if(i!=thePanel.panel && panel[i].left!=(panel[i].el.offsetLeft+2)){
			panel[i].outPos.animate();
		}
	}
	switch(thePanel.panel){
		case 2:
			panel[1].outPos.stop();
			panel[1].overPos.stop();
			panel[1].underPos.animate();
			panel[3].outPos.stop();
			panel[3].overPos.stop();
			panel[3].underPos.animate();
			break;
		case 1:
		case 3:
			thePanel.underPos.stop();
			break;
	}
	thePanel.outPos.stop();
	thePanel.overPos.animate();
}
function panelMouseOut(whichPanel){
	thePanel = typeof(whichPanel)=='number'?panel[whichPanel]:this;
	panel[2].overPos.onComplete.unsubscribe();
	switch(thePanel.panel){
		case 2:
			panel[1].overPos.stop();
			panel[1].underPos.stop();
			panel[1].outPos.animate();
			panel[3].overPos.stop();
			panel[3].underPos.stop();
			panel[3].outPos.animate();
			break;
		case 1:
		case 3:
			thePanel.underPos.stop();
			break;
	}
	thePanel.overPos.stop();
	thePanel.outPos.animate();
}
function panelClick(whichPanel){
	thePanel = typeof(whichPanel)=='number'?panel[whichPanel]:this;

	if(typeof(currentContentPanel)!='number'){//if content is not already out
		//stop all animation & remove listeners
		for(i=0;i<panel.length;i++){
			panel[i].outPos.stop();
			panel[i].overPos.stop();
			if(i==1||i==3){
				panel[i].underPos.stop();
			}
			removeListener(i);
		}
		//run off animations
		var delay = 0;
		for(i=0;i<panel.length;i++){
			removeListener(i);
			if(i!==thePanel.panel){
				setTimeout('panel['+i+'].offPos.animate();',delay += 200);
			}
		}
		//chain off last animation
		thePanel.offPos.onComplete.subscribe(function(){
				if(thePanel.panel==2){
					thePanel.el.style.zIndex = 6;
				}
				thePanel.contentInPos.animate();
				this.onComplete.unsubscribe();
			});
		thePanel.contentInPos.onComplete.subscribe(function(){
				for(i=0;i<panel.length;i++){//add the listeners to the panels
					addPanelListener(i);
				}
				currentContentPanel = thePanel.panel;
				this.onComplete.unsubscribe();
			});
		if(thePanel.panel==2){
			thePanel.el.style.zIndex = 11;
		}
		setTimeout('panel['+thePanel.panel+'].offPos.animate();',delay + 800 - (thePanel.panel*125));//trigger final animation

	}else{//if content is already ou t
		for(i=0;i<panel.length;i++){//remove listeners
			removeListener(i);
		}
		//chain animations
		thePanel.contentInPos.onComplete.subscribe(function(){
				for(i=0;i<panel.length;i++){//add the listeners to the panels
					addListener(i);
				}
				currentContentPanel = thePanel.panel;
				this.onComplete.unsubscribe();
			});

		//check every panel and make sure none are out
		var firstCall = true;
		for(i=0;i<panel.length;i++){
			if(thePanel.panel != i && panel[i].content.offsetLeft!=-1202){//if this is not the current panel and it's out
				if(firstCall){//only take the first call to prevent multiple animation calls
					panel[i].contentOutPos.onComplete.subscribe(function(){
							thePanel.contentInPos.animate();
							this.onComplete.unsubscribe();
						});
					firstCall=false;
				}
				panel[i].contentInPos.stop();//stop any incoming animations
				panel[i].contentOutPos.animate();//animate everything out
			}
		}
		if(firstCall){//if no panels got called, just call the clicked panel
			if(thePanel.content.offsetLeft != 18){//if the panel is not in place
				thePanel.contentInPos.animate();//animate it
			}else{
				thePanel.contentInPos.onComplete.unsubscribe();//unsubscribe the oncomplete
				for(i=0;i<panel.length;i++){//add the listeners back to the panels
					addListener(i);
				}
			}
		}
	}
}
function homeClick(){
	if(typeof(currentContentPanel)=='number'){//if there is a current panel
		YAHOO.util.Event.removeListener('li-5',"click", homeClick);//prevent multiple clicks
		//stop all the content animations
		var firstCall = true;
		for(i=0;i<panel.length;i++){
			removeListener(i);
			if(panel[i].content.offsetLeft!=-1202){
				if(firstCall){//only take the first call to prevent multiple animation calls
					panel[i].contentOutPos.onComplete.subscribe(function(){
							pageInit();
							currentContentPanel = false;
							this.onComplete.unsubscribe();
						});
					firstCall=false;
				}
				panel[i].contentInPos.stop();//stop any incoming animations
				panel[i].contentOutPos.animate();//animate everything out
			}
		}
	}
}

//logging & registration functions
handleSubmit = function(){
	this.submit();
};
handleCancel = function() {
	this.cancel();
};
loginSuccess = function() {
	window.location.reload();
};
loginPanel = new YAHOO.widget.Dialog('DJ_login_panel', {
		postmethod: 'async',
		postdata: 'djAction=login',
		buttons: [
				{ text:'Submit', handler:handleSubmit, isDefault:true },
				{ text:'Cancel', handler:handleCancel }
			],
		visible: false,
		effect: {
				effect:YAHOO.widget.ContainerEffect.FADE,
				duration:0.25
			},
		fixedcenter: true,
		width: '400px',
		constraintoviewport: true,
		close: false,
		draggable: true,
		modal: true,
		zIndex: 120
	});
loginPanel.callback = {
	success: function(o){
		var rObj = YAHOO.lang.JSON.parse(o.responseText);
		if(!rObj.error){
			document.getElementById('DJ_login_link').innerHTML = 'Welcome '+rObj.name+'. <a href="#" onclick="return logout();">logout</a>';
			alert('Welcome '+rObj.name);
			loginSuccess();
		}else{
			alert("There was a problem logging you in: \n\n" + rObj.error + "\n\n...Please try again");
		}
	},
	failure: function(o){
		alert('There was a problem connecting to the server, please try again.');
	}
};
loginPanel.validate = function() {
	var data = this.getData();
	if (data.DJemail == '' || data.DJpassword == '') {
		alert('You must supply a username and password');
		return false;
	} else {
		return true;
	}
};
loginPanel.render();


registerPanel = new YAHOO.widget.Dialog('DJ_register_panel', {
			postmethod: 'async',
			postdata: 'djAction=register',
			buttons: [
					{ text:'Submit', handler:handleSubmit, isDefault:true },
					{ text:'Cancel', handler:handleCancel }
				],
			visible: false,
			effect: {
					effect:YAHOO.widget.ContainerEffect.FADE,
					duration:0.25
				},
			fixedcenter: true,
			width: '400px',
			constraintoviewport: true,
			close: false,
			draggable: true,
			modal: true,
			zIndex: 120
		});
registerPanel.callback = {
		success: function(o){
			var rObj = YAHOO.lang.JSON.parse(o.responseText);
			if(!rObj.error){
				document.getElementById('DJ_login_link').innerHTML = 'Welcome '+rObj.name+'. <a href="#" onclick="return logout();">logout</a>';
				alert('Welcome '+rObj.name+', your account was successfully created!');
				loginSuccess();
			}else{
				if(confirm("There was a problem registring your account: \n\n" + rObj.error + "\n\nWould you like to reset your password?")){
					forgotPW(document.getElementById('DJremail').value);
				}
			}
		},
		failure: function(o){
			alert('There was a problem connecting to the server, please try again.');
		}
	};
registerPanel.validate = function() {
		var data = this.getData();
		if (data.DJremail == '' || data.DJrpassword == '' || data.DJrpassword2 == '') {
			alert('You must supply a username and password');
			return false;
		} else if(data.DJrpassword != data.DJrpassword2) {
			alert('Your passwords do not match.');
			return false;
		}else{
			return true;
		}
	};

registerPanel.render();

register = function(){
	loginPanel.cancel();
	registerPanel.show();
	return false;
};

forgotPW = function(email){
	if(!email){
		if(document.getElementById('DJemail').value==''){//if the email is blank
			alert('Please enter your email.');
			return false;
		}else{
			email = document.getElementById('DJemail').value;
		}
	}
	var transaction = YAHOO.util.Connect.asyncRequest(
			'POST',
			server,
			forgotPW.callback,
			'djAction=reset&DJemail='+email
		);
	return false;
};
forgotPW.callback = {
	success: function(o){
		var rObj = YAHOO.lang.JSON.parse(o.responseText);
		if(!rObj.error){
			alert('Your password has been reset... Please check your email for your new password.');
		}else{
			alert('We were unable to find an account with a matching email.');
		}
	},
	failure: function(o){
		alert('There was a problem connecting to the server, please try again.');
	}
};

logout = function(){
	var transaction = YAHOO.util.Connect.asyncRequest(
				'POST',
				server,
				logout.callback,
				'djAction=logout'
			);
	return false;
};
logout.callback = {
	success: function(o){
		alert('You have been successfully logged out.');
		window.location.reload();
	},
	failure: function(o){
		alert('There was a problem connecting to the server, please try again.');
	}
};

function login_click(){
	loginPanel.show();
	return false;
}
function logout_click(){
	logout();
	return false;
}

//sessions js
var currentSession = 0;
function sessionContentClick(whichSession){
	var myAnim1 = new YAHOO.util.Anim('session-content-'+currentSession, {
		opacity: { to: 0 }
	}, .3, YAHOO.util.Easing.easeOut);
	var myAnim2 = new YAHOO.util.Anim('session-content-'+whichSession, {
		opacity: { to: 1 }
	}, 1.3, YAHOO.util.Easing.easeOut);
	myAnim1.onComplete.subscribe(function(){
		document.getElementById('session-content-'+currentSession).style.display = "none";
		document.getElementById('session-content-'+whichSession).style.display = "block";
		myAnim2.animate();
		currentSession = whichSession;
	});
	myAnim1.animate();
}


var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
try {
	var pageTracker = _gat._getTracker("UA-1646858-7");
	pageTracker._trackPageview();
} catch(err) {}
