//
// 
//  GalleryNavigator.js
//
//  Created by  on 2009-11-02.
//  Copyright (c) 2009 murat n konar. All rights reserved.
//

var GalleryNavigator = new Class({

	// -------------------------------------------------------------
	//	initialize
	// -------------------------------------------------------------
	initialize: function(div, id) 
	{ 
		this.div = div
		this.div.controller = this
		this.div.empty() // remove all current children
	},

	// -------------------------------------------------------------
	//	addSection
	// -------------------------------------------------------------
	addSection: function(id)
	{
		this.div.adopt(new Element('ul', {'id': id}))
	},
	
	// -------------------------------------------------------------
	//	getSectionWithId
	// -------------------------------------------------------------
	getSectionWithId: function(id)
	{
		return this.div.getElementById(id)
	},

	// -------------------------------------------------------------
	//	addItem
	// -------------------------------------------------------------
	addItem: function(name, clickHandler, gref, sectionID)
	{
		var section = this.getSectionWithId(sectionID)
		if (section != undefined)
		{
			var link = new Element('a', {'html':name, 'href':'#', 'class':'gallery-link'})
		
			link.addEvent('click', clickHandler)
		
			var li = new Element('li', {'class':'gallery-item'})

			li.adopt(link)
			section.adopt(li)
		
			if (gref != undefined)
			{
				link.gref = gref
				li.gref = gref
			}
		}
	},
	
	// -------------------------------------------------------------
	//	setCurrentByGref
	// -------------------------------------------------------------
	setCurrentByGref: function (gref)
	{
		this.div.getElements('a').each(function (galleryLink, index){
			galleryLink.setOn(galleryLink.gref == gref)
		})
	}
});
