// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// Write a cookie
function createCookie(name,value,days){
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/";
	return null;
}

function erasecookie(name) {
	createCookie(name,"",-1);
}

// Read a cookie of the given name
function readCookie(myCookie){
  var nameEQ = myCookie+"=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;			
}

function replaceHighlight(picture) {
	$('welcome').style.backgroundImage = 'url(/images/home/' + picture.id + '.jpg)';
	$('greeting').style.background = 'transparent';
	createCookie('highlight', picture.id, 365)
	return null;
}

function menuInit(){
	// pictureId = readCookie('highlight');
	// if (typeof(pictureId) != "undefined") {
	// 	picture = document.getElementById(pictureId);
	// 	replaceHighlight(picture);
	// }

	var quickSearchElem = $('quicksearch');
	if (quickSearchElem) {
		quickSearchElem.value = 'Search the site';
	}

	$$('#drop-down-nav .nav').each(function(f){ 
		Event.observe(f.id, 'mouseover', function() {
	     		$$('#'+f.id+' .drop_down').each(function(g){ g.show(); })
		});
		Event.observe(f.id, 'mouseout', function() {
	     		$$('#'+f.id+' .drop_down').each(function(g){ g.hide(); })
		});
	})
	
	
	$$('#mini-gallery li').each(function(picture){
		Event.observe (picture, 'mouseover', function(e) {
			replaceHighlight(picture);
			Event.stop(e);
		}, false);	
	})
	
}

Event.observe(window, 'load', menuInit)