//
// 
//  arrows.js
//
//  Created by  on 2008-07-19.
//  Copyright (c) 2008 murat n konar. All rights reserved.
//


var kHighlightedOpacity = 1
var kUnhighlightedOpacity = 0.2

var kMouseIsOverUnknown 	= 0
var kMouseIsOverLeftHalf 	= 1
var kMouseIsOverRightHalf 	= 2
var kMouseIsOverMenuButton 	= 3

var ArrowsController = new Class({

	// ------------------------------------------------------------
    initialize: function(previousArrowNode, nextArrowNode, clickHandler, menuButton, menuButtonAction) {
/*
		this.previousArrowNode = previousArrowNode
        this.nextArrowNode = nextArrowNode

		this.previousArrowNode.set('morph', {'duration': 250})
		this.nextArrowNode.set('morph', {'duration': 250})

		this.previousArrowNode.setStyle('opacity', kUnhighlightedOpacity)
		this.nextArrowNode.setStyle('opacity', kUnhighlightedOpacity)

		this.shouldShowPreviousArrow = false
		this.shouldShowNextArrow = false
		
		this.mouseIsInLeftHalf = false
		this.mouseIsOver = kMouseIsOverUnknown
		
		this.lastMouseEvent = undefined

		if ($defined(clickHandler)){
			this.previousArrowNode.addEvent('click', clickHandler)
			this.nextArrowNode.addEvent('click', clickHandler)
		}

		var self = this
		this.menuButtonNode = menuButton
		this.menuButtonNode.set({'opacity': kUnhighlightedOpacity})

		this.menuButtonNode.set('morph', {'duration': 100})

		this.menuButtonNode.addEvent('mouseover', 	function (){
														self.menuButtonNode.morph({'opacity': kHighlightedOpacity}); 
														self.mouseIsOver = kMouseIsOverMenuButton
														self.updateHighlighting()
													})
	
		this.menuButtonNode.addEvent('mouseout', 	function (){
														self.menuButtonNode.morph({'opacity': kUnhighlightedOpacity}); 
														self.mouseIsOver = kMouseIsOverUnknown
														self.updateHighlighting()
													})

		globalz.menuButton.addEvent('click', 		function (){menuButtonAction(); return false;})

		
		var self = this
		window.document.addEvent('mousemove', function (event){self.mouseMonitor(event)})
		window.addEvent('resize', function (event){self.resizeHandler(event)})


		this.menuButtonNode.addEvent('mousedown', 		function (){return false;}) // prevent user from dragging element (can f*ck up Safari by causing an autoscroll)
		this.previousArrowNode.addEvent('mousedown', function (){return false;}) // prevent user from dragging element (can f*ck up Safari by causing an autoscroll)
		this.nextArrowNode.addEvent('mousedown', 	function (){return false;}) // prevent user from dragging element (can f*ck up Safari by causing an autoscroll)
*/   },


	// ------------------------------------------------------------
	updateHighlighting: function ()
	{
/*
		var newPreviousArrowOpacity = 0
		var newNextArrowOpacity = 0

		switch(this.mouseIsOver)
		{
			case kMouseIsOverLeftHalf:
				newPreviousArrowOpacity = (this.shouldShowPreviousArrow? kHighlightedOpacity:0)
				newNextArrowOpacity 	= (this.shouldShowNextArrow? kUnhighlightedOpacity:0)
				break;
			
			case kMouseIsOverRightHalf:
				newPreviousArrowOpacity = (this.shouldShowPreviousArrow? kUnhighlightedOpacity:0)
				newNextArrowOpacity 	= (this.shouldShowNextArrow? kHighlightedOpacity:0)
				break;

			case kMouseIsOverMenuButton:
				newPreviousArrowOpacity = (this.shouldShowPreviousArrow? kUnhighlightedOpacity:0)
				newNextArrowOpacity 	= (this.shouldShowNextArrow? kUnhighlightedOpacity:0)
				break;

			default:
				;
				
		}
	
		this.previousArrowNode.morph({'opacity': newPreviousArrowOpacity})
		this.nextArrowNode.morph({'opacity': newNextArrowOpacity})			
*/
	},

	// ------------------------------------------------------------
	mouseMonitor:function(anEvent){
/*
		if (anEvent && this.mouseIsOver != kMouseIsOverMenuButton)
		{
			// If the x coord of the even is left of center, we'll highlight the 'previous' button, 
			// otherwise we'll we'll highlight the 'next' button.
	
			var xMin = globalz.pagewrap.getPosition()['x']
			var xMax = xMin + globalz.pagewrap.getSize().x

			var newMouseIsOver = (anEvent.client.x < (xMin+xMax)/2) ? kMouseIsOverLeftHalf:kMouseIsOverRightHalf
									
			if (newMouseIsOver != this.mouseIsOver) {
				this.mouseIsOver = newMouseIsOver
				this.updateHighlighting()
			}
		}
		this.lastMouseEvent = anEvent
*/
	},
	
	// ------------------------------------------------------------
	resizeHandler:function(event){
		this.updateLayout()
	},
	
	// ------------------------------------------------------------
	updateLayout:function(coordinates){
/*		
		// coordinates is a hash that looks like this: 
		// { top: 50, left: 100, width: 200, height: 300, right: 300, bottom: 350}
		
		var coords = window.getCoordinates()
		
		this.previousArrowNode.setStyle('left', coords['left'])
		this.nextArrowNode.setStyle('left', coords['right']/2 - this.nextArrowNode.getStyle('width'))
*/
	},
	
	// ------------------------------------------------------------
	showPrevious: function(show){
/*		if (show != this.shouldShowPreviousArrow) {
			this.shouldShowPreviousArrow = show
			this.updateHighlighting()
		}
*/
	},
	
	// ------------------------------------------------------------
	showNext: function(show){
/*
		if (show != this.shouldShowNextArrow) {
			this.shouldShowNextArrow = show
			this.updateHighlighting()
		}
*/
	}
});