var ProgramBlockImage = new Class({

	initialize: function(e, parent)
	{
		
		this.e = e;
		
		this.parent = parent;
		this.overlayDiv = this.e.getElements('.overlayDiv')[0];
		this.overlayDivWidth = this.overlayDiv.getSize().x;
		this.overlayDivHeight = this.overlayDiv.getSize().y;
		
		this.colorDiv =  this.e.getElements('.colorDiv')[0];
		this.colorDivWidth = this.colorDiv.getSize().x;
		this.colorDivHeight = this.colorDiv.getSize().y;		
		
		if(this.e.hasClass('BT') | this.e.hasClass('RL'))
		{
			this.animateDiv = this.overlayDiv;	
			this.animateWhich = 'overlayDiv';
			this.overlayDiv.setStyles(
			{
				'position':'absolute', 
				'z-index': 1
			});
			this.colorDiv.setStyles(
			{
				'position':'absolute', 
				'z-index': 0
			});
			if(this.e.hasClass('BT'))
			{
				this.duration = this.overlayDivHeight;
				this.animateProperty = 'height';
			}else{
				this.duration = this.overlayDivWidth;
				this.animateProperty = 'width';
			}
		}
		
		if(this.e.hasClass('TB') | this.e.hasClass('LR'))
		{
			this.animateDiv = this.colorDiv;
			this.animateWhich = 'colorDiv';
			this.colorDiv.setStyles(
			{
				'position':'absolute', 
				'z-index': 1
			});
			this.overlayDiv.setStyles(
			{
				'position':'absolute', 
				'z-index': 0
			});
			if(this.e.hasClass('TB'))
			{
				this.duration = this.colorDivHeight;
				this.animateDiv.setStyle('height',0);
				this.animateProperty = 'height';
			}else{
				this.duration = this.colorDivWidth;
				this.animateDiv.setStyle('width',0);
				this.animateProperty = 'width';
			}
		}
		this.overlayDiv.setStyle('display','block');
		this.colorDiv.setStyle('display','block');
		
		this.slide = new Fx.Tween(this.animateDiv,{'duration':400, 'link': 'chain', 'transition': Fx.Transitions.Cubic.easeOut });//this.duration
	},
	
	animateOver: function()
	{
	
		this.slide.clearChain();
		if(this.animateWhich == 'overlayDiv' && this.animateProperty == 'width')
		{
			this.slide.start(this.animateProperty, 0);
		}
		if(this.animateWhich == 'overlayDiv' && this.animateProperty == 'height')
		{
			this.slide.start(this.animateProperty, 0);
		}
		if(this.animateWhich == 'colorDiv' && this.animateProperty == 'width')
		{
			this.slide.start(this.animateProperty, this.colorDivWidth);
		}
		if(this.animateWhich == 'colorDiv' && this.animateProperty == 'height')
		{
			this.slide.start(this.animateProperty, this.colorDivHeight);
		}
	},
	
	animateOut: function()
	{
		this.slide.clearChain();
		
		if(this.animateWhich == 'overlayDiv' && this.animateProperty == 'width')
		{
			this.slide.start(this.animateProperty, 0, this.overlayDivWidth);
		}
		if(this.animateWhich == 'overlayDiv' && this.animateProperty == 'height')
		{
			this.slide.start(this.animateProperty, 0, this.overlayDivHeight);
		}
		if(this.animateWhich == 'colorDiv' && this.animateProperty == 'width')
		{
			this.slide.start(this.animateProperty, 0);
		}
		if(this.animateWhich == 'colorDiv' && this.animateProperty == 'height')
		{
			this.slide.start(this.animateProperty, 0);
		}
	}
	
})

var ProgramBlockText = new Class({
	
	initialize:function(e)
	{
		this.e = e;
		if(this.e)
		{
			if(this.e.getElements('.programBlockHeader')[0])
			{
				this.programBlockHeader = this.e.getElements('.programBlockHeader')[0];
			}
			if(this.e.getElements('.programBlockLabel')[0] && this.e.getElements('.programBlockLabel')[0].getProperty('html') != '')
			{
				this.programBlockLabel = this.e.getElements('.programBlockLabel')[0];
			}
			if(this.e.getElements('.programBlockPayoff')[0] && this.e.getElements('.programBlockPayoff')[0].getProperty('html') != '')
			{
				this.programBlockPayoff = this.e.getElements('.programBlockPayoff')[0];
			}
			if(this.e.getStyle('max-height') != 'none')
			{
				this.setProgramBlockHeader();
			}
		}
	},
	
	setProgramBlockHeader: function()
	{
		//var maxHeight = 0;

		var paddingTop = this.styleToInt(this.e, 'padding-top');
		var paddingBottom = this.styleToInt(this.e, 'padding-bottom');
	
		maxHeight = this.styleToInt(this.e, 'max-height') - (paddingTop + paddingBottom);
		
		minHeight =  this.styleToInt(this.e, 'min-height') - (paddingTop + paddingBottom);
		this.e.setStyle('min-height' , minHeight + 'px');
		
		if(this.programBlockLabel)
		{
			if(this.programBlockLabel.get('html').length == 0)
			{
				this.programBlockLabel.dispose();
			}else{
				maxHeight -= this.programBlockLabel.getCoordinates().height;
			}
		}
		
		headerHeight = parseInt(this.programBlockHeader.getCoordinates().height);
		
		if(this.programBlockPayoff)
		{
			var heightPlusPayoff = headerHeight + parseInt(this.programBlockPayoff.getCoordinates().height);
			
			if(this.programBlockPayoff.get('html').length == 0 )
			{
				this.programBlockPayoff.dispose();
			}
			
			if(heightPlusPayoff > maxHeight)
			{
				this.programBlockPayoff.dispose();
			}
		}
		
		var lineHeight = this.styleToInt(this.programBlockHeader, 'line-height');
		if( headerHeight > maxHeight-lineHeight )
		{
			
			var lines = Math.floor(maxHeight/lineHeight);
			this.programBlockHeader.setStyle('height' , (lines*lineHeight) + 'px');	
			this.programBlockHeader.setStyle('overflow' , 'hidden');
		}
	},
	
	styleToInt: function(e, style)
	{
		var styleAsString = e.getStyle(style);
		var styleAsInt = parseInt(styleAsString.substring(0, (styleAsString.length-2)));
		return styleAsInt;
	}
	
})