/*========================================================
 @site    Hangar Bicocca
 @company Keepthinking LTD
 @address http://keepthinking.it
 @author  Oskar Krawczyk (o.krawczyk@keepthinking.it)
 @rev     15/02/2007
 ========================================================*/


/* Switches the images on single-record page
 ========================================================*/
var expandImage = function(url) {
	var img = document.getElementById('updated-image').alt;
	var caption = document.getElementById('caption').innerHTML;
	
	Lightbox.show(url+'/5/'+img, caption);
} // end expandImage

/* Switches the images on single-record page
 ========================================================*/
var updateImage = function(imagePath, imageText, imageAlt) {
	document.getElementById('updated-image').src = imagePath;
	document.getElementById('updated-image').alt = imageAlt;
	document.getElementById('caption').innerHTML = imageText;
	return;
} // end updateImages


/* Hides the loading tickler after the ajax bit's done
 ========================================================*/
var doneLoading = function(request) {
	document.getElementById('loading').style.display = 'none';
	return;
} // end doneLoading


/* Switches the active/non-active state for navigation
 ========================================================*/
var switchNav = function(page) {
	var nav = document.getElementById('navigation'); 
	var navLinks = nav.getElementsByTagName('a'); 
	
	for (var i = 0; i < navLinks.length; i++) { 
		if(page == i+1) {
			navLinks[i].parentNode.className = 'active';	
		} else {
			navLinks[i].parentNode.className = '';
		} // end if
	} // end for
	
	jsGoHome(); // resets the timeline when nav-link is click'd
	
	return;
} // end switchNav


/* Switches the active/non-active state for navigation
 ========================================================*/
var toggle = function(id) {
	var elCon = document.getElementById(id+"-cont");
	var el = document.getElementById(id); 
	
	if(elCon.className == 'hidden') {
		elCon.className = 'show';	
		el.innerHTML = '&laquo; chiudi';
	} else {
		elCon.className = 'hidden';
		el.innerHTML = 'vedi &raquo;';
	} // end if
	
	
} // end toggle


/* Updates the page asynchronisly and highlights the
   active navigation link
 ========================================================*/
var updatePage = function(page, exhibitionId, accessKey) {

	
	document.getElementById('loading').style.display = 'block';	
	
	var myAjax = new Ajax(page);
	myAjax.setOptions({update: $('main'), onComplete: doneLoading});
	myAjax.request();
	
	if(!accessKey) {
		Cookie.set('pageId', Cookie.get('pageId'), 1);	
		Cookie.set('pageNav', Cookie.get('pageNav'), 1);	
	} else {
		Cookie.set('pageId', page, 1);
		Cookie.set('pageNav', accessKey, 1);
		if(!exhibitionId) {
			switchNav(accessKey);
		}
		
		//alert();
	} // end if
	
	if(exhibitionId) {
		jsSelectWork(exhibitionId);
	}
	
	// save the page we are on
	//Cookie.set('pageId', page, 1); 
	
	return;
} // end updatePage


/* 
 ========================================================*/
var showMoreInfo = function() {
	
	var showLink    = document.getElementById('show-more-info'); 
	var showContent = document.getElementById('more-info'); 

	if(showContent.className == 'show') {
		showContent.className = 'hide'
		showContent.style.display = 'block';
	} else {
		showContent.className = 'show'
		showContent.style.display = 'none';
	}
	
	//showLinkAll = '<a title="" href="#">'+showLink.innerHTML+'</a>';

} // end switchNav


/*   
 ========================================================*/
window.onload = function() {
	
	// gets the page we are refreshing
	if(Cookie.get('pageId')) {
		updatePage(Cookie.get('pageId'), '', Cookie.get('pageNav'));
		//alert(Cookie.get('pageId'));
	} else {
		//updatePage('1', '', '1');
		//alert(':(');
	} // end if
	
}
