(function($) {
	/*
		Image preview script 
		powered by jQuery (http://www.jquery.com)
		
		written by Alen Grakalic (http://cssglobe.com)
		modified by Damien du Toit (http://coda.co.za)

		for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
	*/

	$.fn.imagePreview = function(options) {

		$.fn.imagePreview.defaults = {
			xOffset: 30,
			yOffset: 10,
			relocate: true
		};

		var o = $.extend({}, $.fn.imagePreview.defaults, options);

		$("a.preview").hoverIntent(function(e) {
			this.t = this.title;
			this.title = "";	
			var c = (this.t != "") ? "<br />" + this.t : "";
			$("body").append("<p id='preview'><img src='" + this.href + "' alt='Image preview' />" + c + "</p>");								 
			$("#preview")
				.css("top", (e.pageY - o.yOffset) + "px")
				.css("left", (e.pageX + o.xOffset) + "px")
				.fadeIn("normal");						
		},	
		function() {
			this.title = this.t;	
			$("#preview").remove();
		});
	
		if (o.relocate) {
			$("a.preview").mousemove(function(e) {
				$("#preview")
					.css("top", (e.pageY - o.yOffset) + "px")
					.css("left", (e.pageX + o.xOffset) + "px")
			});
		}

		$("a.preview").click(function() {
			return false;
		});
	};
})(jQuery);


// equal height divs
(function($) {
    $.fn.equalHeights = function(o) {
        var maxHeight = 0;
        var maxElement = null;

        $(this).each(function(i) {
            if (($(this).height() + parseInt($(this).css("padding-bottom")) + parseInt($(this).css("padding-top"))) > maxHeight) {
                maxHeight = $(this).height() + parseInt($(this).css("padding-top")) + parseInt($(this).css("padding-bottom"));
                maxElement = $(this);
            }
        });

        $(this).not($(maxElement)).each(function() {
            $(this).height(maxHeight - parseInt($(this).css("padding-top")) - parseInt($(this).css("padding-bottom")));
        });
    };
})(jQuery);


$(document).ready(function() {
	// set form field styles on focus and blur
	$("input[type='text'], textarea").focus(function() { // IE doesn't like this on 'select' elements
		$(this).removeClass("idleField").addClass("focusField");
	}).blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
	});

	$("#signup").imagePreview({
		xOffset: -410,
		yOffset: 150,
		relocate: true
	});

	// slideshow
	if ($("#slideshow").length) {
		$("#slideshow").css("visibility", "visible");

		$("#slideshow").jCarouselLite({
			auto: 5000,
			speed: 1500,
			easing: "easeOutExpo",
			visible: 2,
			scroll: 1,
			vertical: false,
			circular: true
		});
	}

	if ($("input#tshirt").is(":checked")) {
		$("select", "fieldset#t").attr("disabled", "");
	}
	else {
		$("select", "fieldset#t").attr("disabled", "disabled");
	}

	$("input#tshirt").click(function() {
		if ($(this).is(":checked")) {
			$("select", "fieldset#t").attr("disabled", "");
		}
		else {
			$("select", "fieldset#t").attr("disabled", "disabled");
		}
	});

	$("#cell").keypress(function(e) {
		if (e.which != 0 && e.which != 8 && e.which != 43 && (e.which < 48 || e.which > 57)) {
			return false;
		}
	});

	$("#details, #signup").equalHeights();

	// preload images
	var image1 = $("<img />").attr("src", "/img/global/tshirt10.png");
	var image2 = $("<img />").attr("src", "/img/global/measurements.png");

	// open external links in a new window
	$("a.blank").attr("target", "_blank");
});



/*!
 * jQuery Google Analytics Plugin
 * http://www.shamasis.net/projects/ga/
 * 
 * jquery.ga.js
 * Refer jquery.ga.debug.js
 * Revision: 12
 */
(function($){$.ga={};$.ga.load=function(uid){jQuery.ajax({type:'GET',url:(document.location.protocol=="https:"?"https://ssl":"http://www")+'.google-analytics.com/ga.js',cache:true,success:function(){if(typeof _gat!=undefined){pageTracker=_gat._getTracker(uid);pageTracker._trackPageview()}else{throw"_gat has not been defined";}},dataType:'script',data:null})};$.ga.track=function(category,action,label,value){if(typeof pageTracker!=undefined){pageTracker._trackEvent(category,action,label,value)}else{throw"pageTracker has not been defined";}};var pageTracker})(jQuery);

$(window).bind("load", function() {
	$.ga.load("UA-7246387-1");
});