/*----------------------------------------------------------
	
	Class Landing
	Author: Sam Soffes
	Date: 01-30-08
	Description:
		This class controlls all of the Ajax elements on
		the landing pages.	
	
----------------------------------------------------------*/
var Landing = new Class({
	
	/*------------------------------------------------------
		initialize()
	------------------------------------------------------*/
	initialize: function(){
	
		// Logo link
		if($('logo')) {
			$('logo').addEvent('click', function() {
				window.location = $('logo').getProperty('rel');
			});
		}
		
		// Add other animations
		if($('kwicks')) this.parseKwicks();
		if($('showCampusBox') && $('box2') && $('mainHome')) this.locationsSlide();
		
		// Flash counter
		if($('landingCounter')) {
			var obj = new Swiff('http://ext.lifechurch.tv/swf/landing.swf', {
				container: $('landingCounter'),
				width: 260,
				height: 45
			});
		}
		
		// Watch message
		/*if($('browserForm')) {
		
			// Submit the form if they pick a type or topic
			$('browserForm_type').addEvent('change', function(event) {
				event = new Event(event).stop();
				$('browserForm').submit();
			});
			$('browserForm_topic').addEvent('change', function(event) {
				event = new Event(event).stop();
				$('browserForm').submit();
			});
		}*/
		
		// Welcome video
		if($('welcomeVideo')) {
			$('welcomeVideoImg').addEvent('click', function(event) {
				event = new Event(event).stop();
				var obj = new Swiff('http://origin1.lifechurch.tv/player/LCPlayer.swf', {
					container: $('welcomeVideoInner'),
					width: 416,
					height: 270,
					vars: {
						autostart: true,
						showForm: false,
						file: 'Web_New_Vistor_416x232_8',
						sec: 0,
						configPath: 'http://origin1.lifechurch.tv/player/'
					}
				});
			});
		}
		// Owasso video - ows.lifechurch.tv
		if($('owassoVideo')) {
			$('owassoVideoImg').addEvent('click', function(event) {
				event = new Event(event).stop();
				var obj = new Swiff('http://origin1.lifechurch.tv/lifeplayer2/dT0zMDM1JnZpZD0xMDAxMzA4JmVrZXk9MWQxZTkwMTU.', {
					container: $('owassoVideoInner'),
					width: 416,
					height: 270,
					vars: {
						autostart: true,
						popup: false,
						mark: true,
						showHeader: false,
						showForm: false,
						bgcolor: 000000,
						file: 'Owasso_416x232_8',
						configPath: 'http://origin1.lifechurch.tv/lifeplayer2/'
					}
				});
			});
		}
		
		
	},
	
	/*------------------------------------------------------
		parseKwicks()
		Inspired by Mootools.net
	------------------------------------------------------*/
	parseKwicks: function(){
		var min = Settings.kwicks.min;
		var max = Settings.kwicks.max;
		var init = Settings.kwicks.init;
	
		var kwicks = $$('#kwicks .kwick');
		var fx = new Fx.Elements(kwicks, {wait: false, duration: Settings.kwicks.duration, transition: Fx.Transitions.Quad.easeOut});
		kwicks.each(function(kwick, i){
			kwick.addEvent('mouseenter', function(e){
				var obj = {};
				obj[i] = {
					'width': [kwick.getStyle('width').toInt(), max]
				};
				kwicks.each(function(other, j){
					if (other != kwick){
						var w = other.getStyle('width').toInt();
						if (w != min) obj[j] = {'width': [w, min]};
					}
				});
				fx.start(obj);
			});
		});
		
		$('kwicks').addEvent('mouseleave', function(e){
			var obj = {};
			kwicks.each(function(other, j){
				obj[j] = {'width': [other.getStyle('width').toInt(), init]};
			});
			fx.start(obj);
		});
	},
	
	/*------------------------------------------------------
		locationsSlide()
	------------------------------------------------------*/
	locationsSlide: function() {
		var locationsSlide = {
			fx: new Fx.Morph('box2', Settings.locationSelect),
			fx2: new Fx.Morph('mainHome', Settings.locationSelect),
			startHeight: Settings.locationsSelect.landingStart,
			state: 1,
			toggle: function() {
				this.fx.start({'height': ((this.state == 1) ? this.startHeight : 0)});
				this.state = ((this.state == 1) ? 0 : 1);
			},
			slideUp: function() {
				this.fx.start({'height': 0});
				this.fx2.start({'height': Settings.locationsSelect.landingOuterMin});
				this.state = 1;
			},
			slideDown: function() {
				this.fx.start({'height': this.startHeight});
				this.fx2.start({'height': Settings.locationsSelect.landingOuterMax});
				this.state = 1;
			},
			hide: function() {
				$('box2').setStyles({
					'height': 0,
					'display': 'block'
				});
				this.state = 1;
			}
		};

		// Start with it hidden
		locationsSlide.hide();

		// Add the event
		$('showCampusBox').addEvent('click', function(event) {
			event = new Event(event).stop();
			locationsSlide.slideDown();    
		}.bind(this));
		
		$('closeBox').addEvent('click', function(event) {
			event = new Event(event).stop();
			locationsSlide.slideUp();    
		}.bind(this));
	}
	
	
	
	
	
	
}); // End Landing Class

/*----------------------------------------------------------
	
	Initialize the class (which initializes the 
	any other used classes) when the DOM is ready.
	
----------------------------------------------------------*/
var landing;
window.addEvent('domready', function() {
    landing = new Landing();
});


