/*jslint white: true, browser: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: true */
/*global $: false, window: false */

(function () {
	"use strict";
	
	window.LSSMS = {
		init: function () {
			this.makeHinted();
			this.makeFeedbackForm();
	
		// Creative Showcase
			this.makeHoverAnimation("#content .creativeshowcase>.item .thumb a", { height: 200 });
		},
		
	// Make label.hint text become the "peek-a-boo" textbox text
		makeHinted: function () {
			$("label.hint").each(function () {
				var text = $(this).text(), item = $(this).attr("for"), $item = "", value = "";
				if (item.length > 0) {
					$item = $("[name=" + item + "]");
					$item
						.focus(function () {
							if ($(this).val() === text) {
								$(this).val("");
							}
						})
						.blur(function () {
							if ($(this).val() === "") {
								$(this).val(text);
							}
						});
						
					value = $item.val();
					if (value === "") {
						$item.val(text);
					}
				}
			}).hide();
		},
		
	// Makes the feedback comment textarea show up when a feedback option is clicked or focused.
		makeFeedbackForm: function () {
			$("input,label", "#bottom_feedback_form")
				.bind("focus click", function () {
					$(this).parent().children(".button,.feedback_comment").show();
				});
		},
		
	// Animates a hover on a selector using an object of properties to animate to.
		makeHoverAnimation: function (sel, targets) {
			var el = $(sel), to = targets || {}, from = {};
			
			$.each(to, function (i, v) {
				from[i] = el.css(i);
			});
			
			$(sel)
				.hover(function () {
					$(this).stop();
					$(this).animate(to);
				}, function () {
					$(this).stop();
					$(this).animate(from);
				});
		}
	};
	
	$(document).ready(function () {
		window.LSSMS.init();
	});
}());
