	
	$(document).ready(function(){
		
		// ! select all on focus 
		// -----------------------------------------------------
		$("input[type=text], textarea").focus(function(){
		     this.select();
		 });
		 
		 
		// ! popup window
		// -----------------------------------------------------
		$('a.popup').click(function(){
			window.open(this.href);
			return false;
		});


		// ! remove styles on home page bucket
		// -----------------------------------------------------
		$('#home_bucket_2a p').each(function(){
			$(this).removeClass();
		});


		// ! columnize
		// -----------------------------------------------------
		$('#posts .sticky').each(function(){
			// $(this).columnize({width:241});
		});
	
		$('#merchant_list ul').each(function(){
			$(this).columnize({columns:4});
		});
		
		$('ul.pages_list').each(function(){
			$(this).columnize({columns:4});
		});
		
				
		
		// ! comboboxes
		// -----------------------------------------------------
		$('#store_list').sSelect({ddMaxHeight: '320px'})
			.change(function(){
				var page = $('#store_list').getSetSSValue();
				window.open(page, '_self');
				});
				
		$('#category_list').sSelect({ddMaxHeight: '320px'})
			.change(function(){
				var cat = $('#category_list').getSetSSValue();
				console.log(cat);
				sendToFlash(cat);
				});
		
		$('.newList a').each(function(){
			$(this).attr('href', '#');
			$(this).click(function(){
				return false;
			});
		});

		
		// ! merchant map
		// -----------------------------------------------------
		$('#test').click(function(){
			sendToFlash('bridal');
		});
		
		var flashvars = {};
		var params = {wmode:"transparent"};
		var attributes = { id: "map", name: "map" };
		swfobject.embedSWF("/~hpvillag/wp-content/themes/hp_village/_swf/merchant_map_v4.swf", "merchant_map_bucket_2_inside", "1000", "625", "10", "/path/to/expressinstall.swf", flashvars, params, attributes);
		
		function sendToFlash(text) {
  		var swf = document.getElementById("map");
  		swf.sendTextToFlash(text);
		}
		
		
		// ! legacy timeline
		// -----------------------------------------------------
		var flashvars = {};
		var params = { wmode: "transparent" };
		var attributes = { id: "hp_timeline", name: "hp_timeline" };
		swfobject.embedSWF("/~hpvillag/wp-content/themes/hp_village/_swf/HPV_timeline_scroller.swf", "timeline", "747", "241", "9", "/path/to/expressinstall.swf", flashvars, params, attributes);

		
		
		// ! small grid galleries
		// -----------------------------------------------------
		$('#small_grid_gallery li').each(function(){
			var message = $(this).find('img:not(.no_message)').attr('alt');
			if (message == null) {
				message = '';
				$(this).find('a').addClass('no_link');
			} else {
				$(this).append('<div class="sg_overlay"><span class="larger">' + message + '</span></div>');
				// make roll overs work in IE7
				$(this).find('a').hover(function(){ 
															$(this).next().addClass('gold_back'); 
															$(this).next().find('.larger').addClass('no_indent'); }, 
													 function(){ 
													 		$(this).next().removeClass('gold_back'); 
													 		$(this).next().find('.larger').removeClass('no_indent'); }
													 );
			}
		});
		
		$('.sg_overlay').click(function(){
			$(this).prev().trigger('click');
		});

		$('#small_grid_gallery.fancybox a:not(.video, .no_link)').each(function(){
			$(this).fancybox({ 'titlePosition'	: 'over',
												 'overlayOpacity'	: .8,
												 'overlayColor'		: '#000000' 
												 });
		}); 
		
		$('#small_grid_gallery.fancybox a.video').each(function(){
			var href = $(this).attr('href');
			$(this).fancybox({
								'padding'				: 0,
								'autoScale'			: false,
								'transitionIn'	: 'none',
								'transitionOut'	: 'none',
								'hideOnContentClick' : false,
								'title'					: this.title,
								'width'					: 640,
								'height'				: 385,
								'href'					: href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
								'type'					: 'swf',
								'overlayOpacity': .8,
								'overlayColor'	: '#000000'
								});
			$(this).next().removeClass().addClass('sg_overlay_video');
			});
			
			$('#small_grid_gallery.events a').each(function(){
				$(this).click(function(){
					window.open($(this).attr('href'), '_self');
				});
			});
		
		
			// ! legacy small grid
			$('#legacy_bucket_2b #small_grid_gallery li:odd').addClass('no_margin');
		
			// ! events main small grid
			$('#events_galleries #small_grid_gallery li:nth-child(2n)').addClass('no_margin');
			
			// ! events main small grid
			$('#single_gallery #small_grid_gallery li:nth-child(6n)').addClass('no_margin');
		
		
		
		// ! gallery links
		// -----------------------------------------------------		
		$('.gallery_link a').each(function(){
			// get message
			var message = $(this).find('img:not(.no_message)').attr('alt');
			if (message == null) {
				message = '';
			}
			// get date
			var date = $(this).find('span.date').remove();
			$(this).append('<div class="gallery_link_overlay"><span class="larger">' + message + '<span class="date">' + date.text() + '</span></span></div>');
		});
		
		$('.fff_info').hover(function(){
														$(this).css('text-indent', '0');
														$(this).prev().children('.gallery_link_overlay').addClass('gallery_link_overlay_over');
														},
												 function(){
												 		$(this).css('text-indent', '-9999px');
												 		$(this).prev().children('.gallery_link_overlay').removeClass('gallery_link_overlay_over');
												 		});


		// ! float images - legacy
		// -----------------------------------------------------	 
		$('#legacy_b3_right .wp-caption').each(function(e){
			
			var caption			= $(this).find('p').text();
			$('<div class="float_img num_' + e + '"><div class="caption_right"><p>' + caption + '</p></div><div class="clear"></div></div>').appendTo('#legacy_b3_left');
			
			$(this).find('img:first').prependTo('.num_' + e).addClass('align_left');
			$(this).remove();
			
		});
		
		
		// ! gallery move "host an event"
		// -----------------------------------------------------
		$('#host_event').insertAfter('.gallery_link:eq(2)');
		$('#mo_archive').insertAfter('.gallery_link:eq(5)');
		
		

		// ! youtube videos thumbnails
		// -----------------------------------------------------	
		$('.video').each(function(){
			var yt_link = $(this).attr('href');
			var yt_thumb = $.jYoutube(yt_link, 'small');
			$(this).find('img').attr('src', yt_thumb);
		});
		
		
		// ! gallery monthly archive
		// -----------------------------------------------------
		
		// create array for mo_classes
		var mo_class_array = new Array();
		
		// find each month and wrap it in a nested list, 
		// the remove span tag
		// add mo_class to consolidate lists later
		$('#gallery_list li').each(function(i){
			var month = $(this).find('.month').text().replace(" - ", "");
			var mo_class = month.replace(' ', '');
			$(this)
				.wrap('<li class="mo_list ' + mo_class + '" title="' + month + '"></li>')
				.wrap('<ul class="' + mo_class + '"></ul>')
				.parent().before('<a href="#" class="mo_link">' + month + '</a>');
			$(this).find('.month').remove();
			
			if (!include(mo_class_array, mo_class)) {
				mo_class_array.push(mo_class);
			} else {
				// don't worry about it
			}

		});
		
		// find out if object is already in an array
		function include(arr, obj) {
		  for(var i=0; i<arr.length; i++) {
		    if (arr[i] == obj) return true;
		  }
		}
		
		for (var i=0; i<mo_class_array.length; i++) {
			var holder = $('#gallery_list li.' + mo_class_array[i] + ':eq(0)');
			$('#gallery_list li ul.' + mo_class_array[i] + ' li').each(function(){
				$(this).appendTo(holder.find('ul'));
			});
			$('#gallery_list li.' + mo_class_array[i] + ':not(:eq(0))').remove();
		}

		// then create the toggle
		$('#gallery_list .mo_link').each(function(){
			$(this).next().hide();
			$(this).click(function(){
				$(this).next().slideToggle('slow');
				return false;
			});
		});
		
		
		// ! forms fancybox
		// -----------------------------------------------------		
			$("a#news_up, a#news_up_ad").fancybox({
				'hideOnContentClick': false,
				'padding': 0,
				'margin': 0,
				'autoScale': true,
				'autoDimensions': false,
				'height': 357,
				'width': 684,
				'overlayOpacity': .8,
				'overlayColor'	: '#000000'
			});


		// ! site map reveal 
		// -----------------------------------------------------
			var sm_down = false;	
			$('#f_site_map').hide();
			$('#site_map').click(function(){
				if(sm_down == false) {				
					$('#f_site_map').slideDown('slow', function(){
						$('html, body').animate({
														scrollTop: $("#bottom").offset().top
														}, 2000);
						sm_down = true;			
					});
				} else {
					$('#f_site_map').slideUp('slow');
					sm_down = false;
				}
				return false;
			});
			
		
		$('.newsletter_su').click(function(){
			$('#news_up').trigger('click');
			return false;
		});
		
		
		
		
		// ! Location Map
		// -----------------------------------------------------
		
		var locations 	= new Array(
																"The American Airlines Center",
																"Hotel Crescent Court",
																"The Ritz-Carlton Hotel",
																"DFW Airport",
																"Love Field Airport",
																"The Mansion on Turtle Creek",
																"Dallas Country Club",
																"Hotel Palomar",
																"Southern Methodist University",
																"Park Cities Hilton",
																"Hotel Lumen"
																);
																
		var directions	= new Array(
																"4.1 miles (9 minutes)",
																"3.6 miles (10 minutes)",
																"3.5 miles (11 minutes)",
																"24.1 miles (27 minutes)",
																"2.8 miles (10 minutes)",
																"2.6 miles (8 minutes)",
																".6 miles (3 minutes)",
																"1.7 miles (6 minutes)",
																"1.8 miles (5 minutes)",
																"2.7 miles (5 minutes)",
																"1.5 miles (5 minutes)"
																);
																
		var googlemaps		= new Array(
																"http://g.co/maps/7cmp9",
																"http://g.co/maps/cpjd4",
																"http://g.co/maps/g75mj",
																"http://g.co/maps/pz23u",
																"http://g.co/maps/88f2k",
																"http://g.co/maps/vv8jp",
																"http://g.co/maps/ntf3n",
																"http://g.co/maps/erszt",
																"http://g.co/maps/fc95y",
																"http://g.co/maps/p7jhv",
																"http://g.co/maps/xhvyy"
																);
		
		function testArrays(){
			console.log(locations.length, directions.length, googlemaps.length);
			}
			
			testArrays();
		
		
		
					
	});
	
		



	$('a.lightbox').fancybox({
		'width'				: '1224px',
		'height'			: '792px',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
		}); 		
		
		
