/*
JavaScript Document for 
Author: James Nicol, www.glossopteris.com, Glossopteris Web Design & Development, March 2007
*/

var Campaign = {
	
	// onload actions
	start : function()
		{
			Campaign.preload();
			Campaign.behaviour();
		},
	
	// preload images
	preload : function()
		{
			new Asset.images([	baseURL+'images/drop_shadows/ds_bg.png',
								baseURL+'images/drop_shadows/ds_big_box.png',
								baseURL+'images/drop_shadows/ds_box.png',
								baseURL+'images/drop_shadows/ds_horizontal.png',
								baseURL+'images/drop_shadows/ds_vertical.png',
								baseURL+'images/drop_shadows/ds_white_box.png',
								baseURL+'images/people_popup/pp_close_btn_blue.gif',
								baseURL+'images/people_popup/indicator_circle_ball.gif'
							  ]);
		},
	
	behaviour : function()
		{
			// Sons Of Suckerfish Dropdown (applying sfhover class to IE)
			$$('#top_nav li').each(function(el,i)
				{
					el.addEvent('mouseover', function(){ el.className = 'sfhover'; });
					el.addEvent('mouseout', function(){ el.className = ''; });						
				});
			$$('.people_popup a').each(function(el,i)
				{
					el.onclick = function()
						{
							href = el.href.split('/');
							lname = href.pop();
							fname = href.pop();
							PeoplePopup.start(fname,lname);
							return false;
						};
				});
		}
	
}

window.addEvent('domready', Campaign.start);


var PeoplePopup = {

	start : function(fname,lname)
		{
			PeoplePopup.hide();
			PeoplePopup.dropShadow();
			PeoplePopup.create_box(fname, lname);
			PeoplePopup.add_content(fname, lname);
		},
	
	// create the box for the people information to go in
	create_box : function(fname,lname)
		{
			// create popup box
			box = new Element('div');
			box.addClass('pp_box');
			// create header for box
			header = new Element('h1');
			header.innerHTML = unescape(fname) + ' ' + unescape(lname);
			box.appendChild(header);
			// create close button
			close_btn = new Element('a');
			close_btn.addClass('pp_box_close');
			close_btn.href = 'javascript:PeoplePopup.hide()';
			box.appendChild(close_btn);
			// create wrapper for box content, adding in a activity message prior to content loading
			content_div = new Element('div');
			content_div.addClass('pp_content');
			content_div.innerHTML = '<img id="activity" src="' + baseURL + 'images/people_popup/indicator_circle_ball.gif" height="16px" width="16px" border="0" alt="AJAX activity" />&nbsp;&nbsp;&nbsp;Content loading.....';
			box.appendChild(content_div);
			// attach the box to the content div
			$('ds_c').appendChild(box);
			// make the box draggable with the handle being the header
			$('dropShadow').makeDraggable({ handle: header });
			// create a variable of the box object
			PeoplePopup.currbox = box;
		},
		
	dropShadow : function()
		{
			ds_div = new Element('div');
			ds_div.id = 'dropShadow';
			var ds_html = '<table><tr><td id="ds_tl"></td><td id="ds_t"></td><td id="ds_tr"></td></tr>';
			ds_html += '<tr><td id="ds_l"></td><td id="ds_c"></td><td id="ds_r"></td></tr>';
			ds_html += '<tr><td id="ds_bl"></td><td id="ds_b"></td><td id="ds_br"></td></tr></table>';
			ds_div.setHTML(ds_html);
			$('container').appendChild(ds_div);
		},
		
	
	// hide the box
	hide : function()
		{
			$$('div#dropShadow').each(function(el,i) { $('container').removeChild(el); });
		},
		
	// use AJAX to fill the box with content	
	add_content : function(fname,lname)
		{
			content_div = PeoplePopup.currbox.getLast();
			url = siteURL + 'ajax/people_popup/' + fname + '/' + lname;
			new Ajax(url, {method: 'post', update: $(content_div)}).request();
		}
}


var EventsPopup = {
	
	start : function(date)
		{
			EventsPopup.hide();
			EventsPopup.dropShadow();
			EventsPopup.create_box(date);
			EventsPopup.add_content(date);
		},
	// create the box for the people information to go in
	create_box : function(date)
		{
			// create popup box
			box = new Element('div');
			box.addClass('evt_box');
			// create header for box
			header = new Element('h2');
			header.innerHTML = 'Events for ' + date;
			box.appendChild(header);
			// create close button
			close_btn = new Element('a');
			close_btn.addClass('evt_box_close');
			close_btn.href = 'javascript:EventsPopup.hide()';
			box.appendChild(close_btn);
			// create wrapper for box content, adding in a activity message prior to content loading
			content_div = new Element('div');
			content_div.addClass('evt_content');
			content_div.innerHTML = '<img id="activity" src="' + baseURL + 'images/people_popup/indicator_circle_ball.gif" height="16px" width="16px" border="0" alt="AJAX activity" />&nbsp;&nbsp;&nbsp;Content loading.....';
			box.appendChild(content_div);
			// attach the box to the content div
			$('ds_c').appendChild(box);
			// make the box draggable with the handle being the header
			$('dropShadow').makeDraggable({ handle: header });
			// create a variable of the box object
			EventsPopup.currbox = box;
		},
		
	dropShadow : function()
		{
			ds_div = new Element('div');
			ds_div.id = 'dropShadow';
			var ds_html = '<table><tr><td id="ds_tl"></td><td id="ds_t"></td><td id="ds_tr"></td></tr>';
			ds_html += '<tr><td id="ds_l"></td><td id="ds_c"></td><td id="ds_r"></td></tr>';
			ds_html += '<tr><td id="ds_bl"></td><td id="ds_b"></td><td id="ds_br"></td></tr></table>';
			ds_div.setHTML(ds_html);
			$('container').appendChild(ds_div);
		},
		
	// hide the box
	hide : function()
		{
			$$('div#dropShadow').each(function(el,i) { $('container').removeChild(el); });
		},
		
	// use AJAX to fill the box with content	
	add_content : function(date)
		{
			content_div = EventsPopup.currbox.getLast();
			url = siteURL + 'ajax/event_popup/' + date;
			new Ajax(url, {method: 'post', update: $(content_div)}).request();
		}
}