/*----------------------------------------------------------
	
	Class Shared
	Author: Sam Soffes
	Date: 02-13-08
	Description:
		This class contains all of the shared ajax for all
		of the pages across all of the applications.
					
----------------------------------------------------------*/
var Shared = new Class({
	
	/*------------------------------------------------------
		initialize()
	------------------------------------------------------*/
	initialize: function() {
		
		// Tool tips
		this.tips = new Tips($$('.tool-tip'), {
			fixed: true
		});
		
		// Non-Fixed Tool tips
		this.tips = new Tips($$('.tool-tip-2'), {
			fixed: false
		});
		
	
		// Accordions
		if($$('div.accordion')) {
			
			// Preload images
			var on = new Image(26,27); 
			on.src ="http://ext.lifechurch.tv/img/shared/i_plus_on.jpg"; 
			
			var off = new Image(26,27); 
			off.src ="http://ext.lifechurch.tv/img/shared/i_plus.jpg"; 
		
			$$('div.accordion').each(function(el, i) {
				this.genericAccordion(el.getElements('div.accordionItem h3'), el.getElements('div.accordionInner'), el, Settings.genericAccordion);
			}.bind(this));
		}
		
		// Google Maps
		if($$('.campusMap')) {
			$$('.campusMap').each(function(el, i) {
				new ContactsMap(el, el.getProperty('rel'));
			});
		}
	},
	
	/*------------------------------------------------------
		genericAccordion()
		
		This is used for any of the accordions anywhere
		(besides the frontpage one).
	------------------------------------------------------*/
	genericAccordion: function(togglers, elements, container, settings) {
		var accordion = new Accordion(togglers, elements, {
			onActive: function(toggler, element) {
				toggler.setStyle('borderBottomColor', '#d8dde3');
				new Fx.Morph(toggler, settings.options).start(settings.active.toggler);
				new Fx.Morph(element, settings.options).start(settings.active.element);
			},
			onBackground: function(toggler, element) {
				new Fx.Morph(toggler, settings.options).start(settings.background.toggler);
				new Fx.Morph(element, settings.options).start(settings.background.element);
			}
		}, $(container));
	}
	
});

/*----------------------------------------------------------
	
	Object Settings
	Author: Sam Soffes
	Date: 01-30-08
	Description:
		This class contains all of the variables such as
		styles and sizes for all of the classes for easy
		access by people who don't know javascript like
		the Ninja.
			
----------------------------------------------------------*/
var Settings = {

	// Kwicks
	kwicks: {
		duration: 300,
		min: 144,
		max: 249,
		init: 165
	},
	
	// Blackbar
	blackBar: {
		duration: 600,
		minHeight: 48,
		maxHeight: 352,
		maxHeightSmall: 314
	},
	
	// Locations Select
	locationsSelect: { 
		duration: 400, 
		transition: Fx.Transitions.Quint.easeInOut,
		landingStart: '229px',
		landingOuterMin: '156px',
		landingOuterMax: '209px'
	},
	
	// Center Nav
	centerNav: {
		options: {
			duration: 300,
			'wait': false,
			transition: Fx.Transitions.Quad.easeInOut
		},
		active: {
			nav: { height: 76, color: '#46667f' },
			header: { color: '#406087' },
			arrow: { opacity: 1 },
			icon: { top: 17 }
		},
		background: {
			nav: { height: 38, color: '#7c7c7c' },
			header: { color: '#666' },
			arrow: { opacity: 0 },
			icon: { top: 0}
		}
	},
	
	// Generic Accordion
	genericAccordion: {
		options: {
			duration: 200,
			'wait': false,
			transition: Fx.Transitions.Quad.easeInOut,
			openClose: true
		},
		active: {
			toggler: { backgroundImage: 'url(http://ext.lifechurch.tv/img/shared/i_plus_on.jpg)' },
			element: { 'padding': '17px' }
		},
		background: {
			toggler: {  borderBottomColor: '#b3c1cb', backgroundImage: 'url(http://ext.lifechurch.tv/img/shared/i_plus.jpg)' },
			element: { 'padding': 0 }
		}
	}
	
}; // End Settings Object

/*----------------------------------------------------------
	
	Class ContactsMap
	Author: Sam Soffes
	Date: 01-24-08
	Description:
		This class loads a Google Map for the specified
		campus id.
		
		Note: This class requires that the API already
		be included.
	
----------------------------------------------------------*/
var ContactsMap = new Class({
	
	map: false,
	
	initialize: function(el, id) {
		
		// Be sure to unload the Google stuff
		window.addEvent('unload', function() {
			GUnload();
		});
		
		// Setup the custom icon
		var icon = new GIcon();
    	icon.image = 'http://ext.lifechurch.tv/img/shared/map/marker.png';
		icon.shadow = 'http://ext.lifechurch.tv/img/shared/map/shadow.png';
		icon.iconSize = new GSize(68, 54);
		icon.shadowSize = new GSize(68, 54);
		icon.iconAnchor = new GPoint(41, 56);		
		var markerOptions = { icon:icon }
	
		if (GBrowserIsCompatible()) {		
			GDownloadUrl("/utility/maps", function(data) {
				
				// Setup map
				this.map = new GMap2(el);
				this.map.addControl(new GSmallMapControl());
				//this.map.addControl(new GMapTypeControl());
				
				// Loop throught the campuses
				var xml = GXml.parse(data);
				var campuses = xml.documentElement.getElementsByTagName("campus");
				var campus;
				for (var i = 0; i < campuses.length; i++) {
					campus = campuses[i];
					
					// Load the data for the specified campus
					if(campus.getAttribute("id") == id) {
						var point = new GLatLng(parseFloat(campus.getAttribute("lat")), parseFloat(campus.getAttribute("lng")));
						this.map.setCenter(point, 13);
						this.map.addOverlay(new GMarker(point, markerOptions));
						this.map.openInfoWindowHtml(point, '<p><strong>'+campus.getAttribute("name")+'</strong></p><p>'+campus.getAttribute("address").replace(/\|/g, "<br />")+'</p>');
						//alert(campus.getAttribute("address").replace("|","<br />"));
					}
				}				
			});
		}
	}
});

/*----------------------------------------------------------
	Stuff to initialize on DOM ready
----------------------------------------------------------*/
var shared;
window.addEvent('domready', function() {
	shared = new Shared();
});