<!--
// ------------------------------------------------------------------------------------------------------- //
// FORCE getElementById TO WORK FOR IE 6 and below...
// ------------------------------------------------------------------------------------------------------- //
//  Force getElementById to work
if(!document.getElementById) {
	if(document.all) {
		document.getElementById=function() {
			if(typeof document.all[arguments[0]]!="undefined")
			return document.all[arguments[0]]
			else
			return null
		}
	} else if(document.layers) {
		document.getElementById=function() {
			if(typeof document[arguments[0]]!="undefined")
			return document[arguments[0]]
			else
			return null
		}
	}
}



// ------------------------------------------------------------------------------------------------------- //
// BROWSER DETECTION
// http://www.quirksmode.org/js/detect.html
// ------------------------------------------------------------------------------------------------------- //
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};




// ------------------------------------------------------------------------------------------------------- //			
//  VARIABLE DEFINITIONS
// ------------------------------------------------------------------------------------------------------- //	
var init_journal = 0; 	// used to track first click on project or calendar
var default_date = '2008-07-13';



// ------------------------------------------------------------------------------------------------------- //
// SIMPLE TOGGLE
// ------------------------------------------------------------------------------------------------------- //
function simpleToggle(div) {
	
	if(div != null) {
		new Effect.toggle(div, 'blind', {
				duration: 1,
				queue: 'end',
				afterFinish:function() { 
					
				}
			});
	}
	return false;
	
}


// ------------------------------------------------------------------------------------------------------- //
// MODIFY THE PROJECT AND JOURNAL TOGGLE TAB LABELS 
// ------------------------------------------------------------------------------------------------------- //
function changeLabel(project_id, div) {
	
	var div = (div == null) ? 'project_info' : div;
	var divDisplayState = 'none';
	
	
	if( (div != null) && (document.getElementById( div ).style.display != 'none') ) {
		divDisplayState = 'block';
	}
	
	
	if(div == 'project_info') {
		
		switch(project_id) {
			
			case 1:
			case '1':
				document.getElementById('project_info_toggler_link').innerHTML = 'PROFILE: MICRO COMPACT HOME';
				document.getElementById('project_journal_toggler_link').innerHTML = 'JOURNAL: MICRO COMPACT HOME';
			break;
			
			case 2:
			case '2':
				document.getElementById('project_info_toggler_link').innerHTML = 'PROFILE: SYSTEM3';
				document.getElementById('project_journal_toggler_link').innerHTML = 'JOURNAL: SYSTEM3';			
			break;
			
			case 3:
			case '3':
				document.getElementById('project_info_toggler_link').innerHTML = 'PROFILE: BURST*008';
				document.getElementById('project_journal_toggler_link').innerHTML = 'JOURNAL: BURST*008';
			break;
			
			case 4:
			case '4':
				document.getElementById('project_info_toggler_link').innerHTML = 'PROFILE: DIGITALLY FABRICATED HOUSING FOR NEW ORLEANS';
				document.getElementById('project_journal_toggler_link').innerHTML = 'JOURNAL: DIGITALLY FABRICATED HOUSING FOR NEW ORLEANS';
			break;
			
			case 5:
			case '5':
				document.getElementById('project_info_toggler_link').innerHTML = 'PROFILE: CELLOPHANE HOUSE';
				document.getElementById('project_journal_toggler_link').innerHTML = 'JOURNAL: CELLOPHANE HOUSE';
			break;
			
			case 6:
			case '6':
				document.getElementById('project_info_toggler_link').innerHTML = 'PROFILE: MoMA CURATORIAL TEAM';
				document.getElementById('project_journal_toggler_link').innerHTML = 'JOURNAL: MoMA CURATORIAL TEAM';
			break;
			
		}
	}
}



// ------------------------------------------------------------------------------------------------------- //
// FUNCTION: UPDATE PROJECT INFO OR PROJECT JOURNAL
// ------------------------------------------------------------------------------------------------------- //
function requestData(id, div, date, page, limit) {
	
	// set default values for all variables used and passed into the function
	var action 	= (action == null) ? "/posts/category/" : action;
	var state 	= (state == null) ? "none" : state;
	var id 		= (id == null) ? "6" : id; // default id is 6, for MoMA Curatorial Team
	var div 	= (div == null) ? "project_journal" : div;
	var date 	= (date == null) ? null : date;
	var page 	= (page == null) ? null : page;
	var limit 	= (limit == null) ? null : limit;
	
	
	action = action + id;
	
	if(div == 'project_info') {
		action = '/documents/project_info/'+id;
	}
	
	if(date != null) {
		action = action + '/'+date;
	}
	
	if(date == null && page != null) {
		action = action + '/'+default_date+'/'+page;
	}
	else if(page != null) {
		action = action + '/'+page;
	} 
	
	
	if(date == null && limit != null) {
		action = action + '/'+default_date+'/0/'+limit;
	}
	else if(limit != null) {
		action = action + '/'+limit;
	}
	
	if( document.getElementById( div ).style.display != 'none') {
		simpleToggle( div );
		state = 'block';
	}
	
new Ajax.Request( _URL+action,{ 
	asynchronous:true,
	evalScripts:true,
	onSuccess:function(response) { 
		document.getElementById( div ).innerHTML = response.responseText;
		
			if(state != 'none') { 
				new Effect.BlindDown(div, {
						duration: 0.5,
						queue: 'end'
					});
			}
			
			if((init_journal == 0) && (document.getElementById('project_journal').style.display == "none") ) {
				new Effect.BlindDown('project_journal', { 
						duration: 0.5,
						delay: 1,
						queue: 'end'
					});
			}
					
		}
	});
}



// ------------------------------------------------------------------------------------------------------- //
// UPDATE A PROJECT AND JOURNAL BASED ON DATE
// ------------------------------------------------------------------------------------------------------- //
function pullDate(date, project_id) {
	
	// We have to correct the project id, because it is being passed in as the day of the week...
	switch (project_id) {
		case '1': // Monday = Cellophane House
			project_id = 5;
		break;
		
		case '2': // Tuesday = Burst
			project_id = 3;
		break;
		
		case '3': // Wednesday = System3
			project_id = 2;
		break;
		
		case '4': // Thursday = Housing for N.O.
			project_id = 4;
		break;
		
		case '5': // Friday = Micro Compact House
			project_id = 1;
		break;
		
		case '6': // Saturday = MoMA Curatorial
			project_id = 6;
		break;
	}
	
	_ACTIVE = project_id;
	changeLabel(project_id);
	setTimeout("requestData("+project_id+", 'project_info')",100);
	setTimeout("requestData("+project_id+", 'project_journal', '"+date+"')",150);
	
}



// ------------------------------------------------------------------------------------------------------- //
// FUNCTION: PAGINATE POSTS
// ------------------------------------------------------------------------------------------------------- //
function paginatePosts(project_id, page, date) {
	
	// set default values for all variables used and passed into the function
	var project_id = (project_id == null) ? "5" : project_id; // default id is 5, for Cellophane House
	var page 	= (page == null) ? null : page;
	var limit 	= (limit == null) ? 1 : limit;
	var date 	= (date == null || date == 'null') ? null : date;
	
	changeLabel(project_id, 'project_info');
		
	new Ajax.Updater('project_journal', _URL+'/posts/category/'+project_id+'/'+date+'/'+page+'/'+limit, {
		asynchronous:true,
		evalScripts:true,
		onSuccess:function(response) {
			
			new Effect.BlindDown(('project_journal'), { duration: 0.5, delay: 1 });
			
			new Ajax.Updater('project_info',  _URL+'/documents/project_info/'+project_id, {
				asynchronous:true,
				evalScripts:true,
				onSuccess:function(response) {
					
				}
			});
			
		}
	});
}




// ------------------------------------------------------------------------------------------------------- //
// PROJECTS MENU REQUEST
// ------------------------------------------------------------------------------------------------------- //
function selectProj(project_id) {
	_ACTIVE = project_id;
	setTimeout("requestData("+project_id+", 'project_info');",100);
	setTimeout("requestData("+project_id+", 'project_journal');",150);
	changeLabel(project_id, 'project_info');
}




// ------------------------------------------------------------------------------------------------------- //
// ABOUT - OPEN MENU FUNCTIONS....
// ------------------------------------------------------------------------------------------------------- //
function openAbout(div) {
	var about			= 	document.getElementById('about');
	var aboutInfo		= 	document.getElementById('aboutInfo');
	var aboutStatement	=	document.getElementById('aboutStatement');
	var aboutTecSpec	=	document.getElementById('aboutTecSpec');
	var aboutCredits	=	document.getElementById('aboutCredits');
	var aboutSubMenu	=	document.getElementById('aboutSubMenu');
	
	about.style.display	= 'block';
	
	if(div == 'aboutInfo' || div == 'about' ) {
		aboutInfo.style.display		= 'block';
		aboutStatement.style.display= 'none';
		aboutTecSpec.style.display 	= 'none';
		aboutCredits.style.display	= 'none';
		aboutSubMenu.style.display	= 'block';
	}
	
	if(div == "aboutStatement") {
		aboutInfo.style.display		= 'none';
		aboutStatement.style.display= 'block';
		aboutTecSpec.style.display	= 'none';
		aboutCredits.style.display	= 'none';
		aboutSubMenu.style.display	= 'none';
	}
	
	if(div == "aboutTecSpec") {
		aboutInfo.style.display		= 'none';
		aboutStatement.style.display= 'none';	
		aboutTecSpec.style.display	= 'block';
		aboutCredits.style.display	= 'none';
		aboutSubMenu.style.display	= 'block';
	}
	
	if(div == "aboutCredits") {
		aboutInfo.style.display		 = 'none';
		aboutStatement.style.display = 'none';	
		aboutTecSpec.style.display 	 = 'none';
		aboutCredits.style.display	 = 'block';	
		aboutSubMenu.style.display	 = 'block';
	}
	
	return true;
}




// ------------------------------------------------------------------------------------------------------- //
// ABOUT - CLOSE MENU FUNCTIONS....
// ------------------------------------------------------------------------------------------------------- //	
function closeAbout() {
	var about			= 	document.getElementById('about');
	var aboutInfo		= 	document.getElementById('aboutInfo');
	var aboutStatement	=	document.getElementById('aboutStatement');
	var aboutTecSpec	=	document.getElementById('aboutTecSpec');
	var aboutCredits	=	document.getElementById('aboutCredits');
	var aboutSubMenu	=	document.getElementById('aboutSubMenu');		
	
	about.style.display 		 = 'none';
	aboutInfo.style.display 	 = 'none';
	aboutStatement.style.display = 'none';
	aboutTecSpec.style.display 	 = 'none';
	aboutCredits.style.display 	 = 'none';
	aboutSubMenu.style.display 	 = 'none';
	
	return true;
}



// ------------------------------------------------------------------------------------------------------- //
// START FUCNTION, TO INTIALIZE THE SITE :: CURRENTLY NOT USED
// ------------------------------------------------------------------------------------------------------- //	
BrowserDetect.init();
if(BrowserDetect.browser == "Safari") {
	var version = parseInt(BrowserDetect.version);
	if(version < 500) {
	
	}
}



// ------------------------------------------------------------------------------------------------------- //
// CHECK FOR DEEPLINKING/PERMALINK
//
// There is a javaScript call at the bottom of the default layout which references these variables.
// That script is at the bottom of the body/layout to ensure the entire page has loaded, and all other'
// variables are defined.
// ------------------------------------------------------------------------------------------------------- //
initializeString	 = new String(document.location);
intializeSearch		 = "#/";
intializeSearchResult = initializeString.search(intializeSearch); // if "#/" does not exist, will return -1
intializeStartParent = null;
intializeStartChild  = null;

if(intializeSearchResult != -1) {	
	intializeStartResult = initializeString.slice( (initializeString.search(intializeSearch) + 2) ); // slice the URL string at the first instance of the '#/' and add 2 to compensate for those chars
	intializeStartParent = intializeStartResult;
	split = intializeStartParent.split('/',3);
	
	intializeStartParent = split[0];
	intializeStartChild	 = split[1];
	
}


// ------------------------------------------------------------------------------------------------------- //
// INITIALIZE THE SITE - This is a one time call, since all data passed in retrieved with AJAX
// ------------------------------------------------------------------------------------------------------- //
function initilizeSite(initParent, initChild) {
	
	if(!initChild) {
		
		changeLabel(initParent, 'project_info');
		
		new Ajax.Request( _URL+'/documents/project_info/'+initParent,{ 
			asynchronous:true,
			evalScripts:true,
			onSuccess:function(response) {
				
				document.getElementById('project_info').innerHTML = response.responseText;
				simpleToggle('project_info');
				
				
				new Ajax.Request( _URL+'/posts/category/'+initParent,{ 
					asynchronous:true,
					evalScripts:true,
					onSuccess:function(response) { 
						document.getElementById('project_journal').innerHTML = response.responseText;
					}
				});
				
			}
		});
		
	}
	
	else if(initChild) {
		
		changeLabel(initParent, 'project_info');
		
		new Ajax.Request( _URL+'/posts/category/'+initParent+'/'+initChild,{
			asynchronous:true,
			evalScripts:true,
			onSuccess:function(response) {
				
				document.getElementById('project_journal').innerHTML = response.responseText;
				simpleToggle('project_journal');
				
				
				new Ajax.Request( _URL+'/documents/project_info/'+initParent,{ 
					asynchronous:true,
					evalScripts:true,
					onSuccess:function(response) { 
						document.getElementById('project_info').innerHTML = response.responseText;
					}
				});
				
			}
		});
		
	}
}


// ------------------------------------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------------- //
// END OF FILE
//-->