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

var GalleryLinkController = new Class({

	// -------------------------------------------------------------
	//	initialize
	// -------------------------------------------------------------
	initialize: function(linkElement) 
	{ 
		this.linkElement = linkElement
		this.linkElement.controller = this
		
		this.linkElement.addEvent('mouseover', function(){this.controller.mouseover()})
		this.linkElement.addEvent('mouseout', function(){this.controller.mouseout()})
		this.linkElement.addEvent('mousedown', function(){this.controller.mousedown()})
		this.linkElement.addEvent('mouseup', function(){this.controller.mouseup()})
		
		this.linkElement.set('morph', {duration: 250, transition: 'linear'})
		
		this.on 		= false
		this.faded 		= false
		
		// As a convenience...
		this.linkElement.setOn 			= function(newOn){this.controller.setOn(newOn)}
		this.linkElement.setFaded 		= function(newFaded){this.controller.setFaded(newFaded)}
	},
	
	// -------------------------------------------------------------
	//	mouseover
	// -------------------------------------------------------------
	mouseover: function(e) 
	{ 
		if (!this.on) 
		{
			this.linkElement.morph('.gallery-link-hover')
		}
	},
	
	// -------------------------------------------------------------
	//	mouseout
	// -------------------------------------------------------------
	mouseout: function(e) 
	{ 
		if (!this.on) 
		{
			this.linkElement.morph('.gallery-link')
		}
	},

	// -------------------------------------------------------------
	//	mousedown
	// -------------------------------------------------------------
	mousedown: function(e) {},

	// -------------------------------------------------------------
	//	mouseup
	// -------------------------------------------------------------
	mouseup: function(e) {},
	
	// -------------------------------------------------------------
	//	setOn
	// -------------------------------------------------------------
	setOn: function(newOn) 
	{ 
		this.on = newOn
		if (this.on) 
		{
			this.linkElement.get('morph').cancel()
			this.linkElement.get('morph').set('.gallery-link-current')
		}
		else
		{
			this.linkElement.get('morph').cancel()
			this.linkElement.morph('.gallery-link')
		}
	},		

	// -------------------------------------------------------------
	//	setFaded
	// -------------------------------------------------------------
	setFaded: function(newFaded) 
	{ 
		this.faded = newFaded
		if (!this.on) 
		{
			this.linkElement.get('morph').cancel()
			if (this.faded)
			{
				this.linkElement.morph('.gallery-link-faded')
			}
			else
			{
				this.linkElement.morph('.gallery-link')
			}
		}
	}
});

