// Copyright (c) 2008-2009 Label Media (http://www.labelmedia.co.uk)
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// For details, see the LabelEd web site: http://labeled.labelmedia.co.uk

var WindowBlind = Class.create({
	initialize: function(container, options)
	{
		if ($(container))
		{
			this.container = $(container);
			this.inner = false;
			
			this.options = {
				innerClass: 'inner',
				width: 290,
				height: 318,
				innerStartTop: 255,
				innerStopTop: 100
			};
			
			if (options)
			{
				for (var key in this.options)
				{
					if (options[key] != undefined)
					{
						this.options[key] = options[key];
					}
				}
			}

			this.effect = false;
			
			this.start();
		}
	},
	
	start: function()
	{
		this.container.select('.' + this.options.innerClass).each(function(element){
			this.inner = element;
		}.bind(this))
		
		this.annimate = false;
		
		this.build();
	},
	
	build: function()
	{
		this.container.setStyle({
			position: 'relative',
			height: this.options.height + 'px',
			width: this.options.width + 'px',
			overflow: 'hidden',
			display: 'block'
		});
		
		this.inner.setStyle({
			position: 'absolute',
			width: this.options.width + 'px',
			top: this.options.innerStartTop + 'px'
		});
		this.effect = false;
		
		this.container.observe('mouseover', this.mouseIn.bind(this));
		this.container.observe('mouseout', this.mouseOut.bind(this));
	},
	
	mouseIn: function()
	{
		if (this.effect)
		{
			this.effect.cancel();
		}
		this.effect = new Effect.Morph(this.inner, {style: 'top: ' + this.options.innerStopTop + 'px', duration: 0.3, afterFinish: this.afterEffect.bind(this)});
	},
	
	mouseOut: function()
	{
		if (this.effect)
		{
			this.effect.cancel();
		}
		this.effect = new Effect.Morph(this.inner, {style: 'top: ' + this.options.innerStartTop + 'px', duration: 0.6, afterFinish: this.afterEffect.bind(this)});
	},
	
	afterEffect: function()
	{
		this.effect = false;
	}

});