
( function( $, window, document, undefined ) {

	if ( typeof $ == 'undefined' ) {
		//  jQuery isn't available - abort!
		return;
	}

	//	--	Instantiate just ONE jQuery object, use this to find other elements
	//		rather than creating a new jQuery object for each selector
	$.root = new $.prototype.init( document );

	//	--	Make Rocket Go Now
	$.root.ready( function() {

		//	--	Define head and body elements
		head = $.root.find( 'head' );
		body = $.root.find( 'body' );

		//	--	Add "js" class to body for styling
		body.addClass( 'js' );

		//	--	Invoke plugins, yo - body.find( '#element' ).functionName()
//		body.find( '#navigation'    ).dropDownNav();
		body.find( '.home_services' ).equalHeights();
		body.find( '.home_slideshow ul' ).cycle({ timeout: 5000 });
		body.find( '.google_map'    ).googleMap();
		body.find( '.login_inline'  ).loginLabels();
		body.find( '.video_embed'   ).videoEmbed();

		body.find( '.gallery_list ' ).gallery();

	});





	//	--	Custom Plugins
	( function() {

		$.prototype.dropDownNav = function() {

			var nav, lis;

			nav = this;
			lis = nav.children();

			lis.each( function() {
				var li, ul;

				li = $( this );
				ul = li.find( 'ul' )[0];

				if ( ul ) {
					li.bind({
						mouseenter: function() {
							$( this ).addClass( 'open' );
						},
						mouseleave: function() {
							$( this ).removeClass( 'open' );
						}
					});
				}
			});

			return this;

		};



		$.prototype.gallery = function() {

			return this.each( function() {
				var gallery, links, rel;

				gallery = $( this );
				links   = gallery.find( 'li a');

				rel = links.first().attr( 'rel' );

				links.colorbox({
					opacity: 0.5,
					rel: rel
				});
			});

		};



		$.prototype.equalHeights = function() {

			var list, lis, tallest;

			list    = this;
			lis     = list.children();
			tallest = 0;

			lis.each( function() {
				var li, height;

				li     = $( this );
				height = li.height();

				if (height > tallest) {
					tallest = height;
				}
			});

			lis.css('height', tallest);

			return this;

		};



		//	Google Maps
		$.prototype.googleMap = function() {

			return this.each( function() {
				var map_wrap, latitude, longitude, title, address, map, point, map_html, marker;

				map_wrap = $( this );

				if ( GBrowserIsCompatible() ) {
					latitude  = map_wrap.data( 'latitude' );
					longitude = map_wrap.data( 'longitude' );
					title     = map_wrap.data( 'title' );
					address   = map_wrap.data( 'address' );

					map = new GMap( this );

					map.addControl( new GLargeMapControl() );
					map.centerAndZoom( new GPoint( longitude, latitude ), 4 );
//					map.setMapType ( G_SATELLITE_MAP );

					point = new GPoint( longitude, latitude );

					map_html = '<div class="map_html">';
					map_html+= '<h2>' + title + '</h2>';
					map_html+= '<p>' + address + '</p>';
					map_html+= '</div>';

					marker = new GMarker( point );

					GEvent.addListener( marker, 'click', function() {
						marker.openInfoWindowHtml( map_html );
					});

					map.addOverlay( marker );
					marker.openInfoWindowHtml( map_html );
				}
				else {
					map_wrap.html( '<p>Your Browser is not compatible with Google Maps</p>' );
				}
			});

		};



		$.prototype.loginLabels = function() {

			return this.each(function() {
				var form = $( this );

				form.find( 'input:visible' ).each( function() {
					var input, label, placeholder;

					input       = $( this );
					label       = input.prev();
					placeholder = label.text().split(':')[0];

					input.data( 'placeholder', placeholder );

					input.bind({
						focus: function() {
							if ( input.val() == placeholder ) {
								input.val('');
							}
						},
						blur: function() {
							if ( input.val() == '' ) {
								input.val(placeholder);
							}
						}
					}).trigger( 'blur' );
				});

				form.bind( 'submit', function() {
					form.find( 'input:visible' ).each( function() {
						var input, placeholder;

						input       = $( this );
						placeholder = input.data( 'placeholder' );

						if (input.val() == placeholder ) {
							input.val( '' );
						}
					});
				});

			});

		};



		//	General Video embedder thinger
		$.prototype.videoEmbed = function() {

			return this.each( function() {
				var video, type, width, height, config;

				video  = $( this );
				type   = video.data( 'type'   );
				width  = video.data( 'width'  );
				height = video.data( 'height' );
				config = {
					params: {
						allowfullscreen: true,
						allowscriptaccess: 'always',
						wmode: 'transparent'
					},
					height: height,
					width: width,
					wmode: 'transparent'
				};

				if ( type == 'youtube' ) {
					config.swf = video.data( 'url' );
					config.flashvars = {
						fs: 1,
						hl: 'en',
						rel: 0
					};
				}
				else {
					config.swf = 'http://vimeo.com/moogaloop.swf';
					config.flashvars = {
						clip_id: video.data( 'id' ),
						server: 'vimeo.com',
						show_title: 1,
						show_byline: 1,
						show_portrait: 0,
						fullscreen: 1
					};
				}

				video.empty().flash( config );
			});
		};

	})();
	//	--	Good.. Can you say it faster?

} )( jQuery, this, this.document );
//	--	Custom Plugins DONE, yeah?

