$j = jQuery.noConflict();

var Snorkel = {
	init : function() {
		var c = Snorkel;
		var p = c.Project;

		$j(window).load(function() {
			setupZoom();
		})

		$j(document).ready(function() {
			// List function(s) to fire onload here
			p.cruft();
			p.featureZoom();
			p.inputFocus();
			p.tableStripes();
			p.tabsDownload();
			p.tabsHome();
			p.tagIt();
			p.loadFancyBox();

			if (typeof DD_belatedPNG != "undefined") {
				DD_belatedPNG.fix(c.Config.sPNGsel);
			}
		});

		p.loadSIFR();
		
	}

	,Config : {
		sHTMLtag : "can-has-js"
		,sPNGsel : "#site, #wrap-outer, #wrap-inner, #download a, body.sect-home #intro p.pic img, #footer, body.sect-home #main ol.nav img"
		,sSwfPath : "/-/swf/"
	}

	/*
		CLIENT-SPECIFIC FUNCTIONS
	*/
	,Project : {
		cruft : function() {
			$j("li.entry .title a").append("<i></i>");
		}


		,loadFancyBox : function(){
		
			$j("a.featureItem1").fancybox({
			'speedIn'		:	600, 
			'speedOut'		:	200,
			'width'			:	648,
			'height'		:	457,
			'autoScale'		:	true,
			'autoDimensions':	true,
			'overlayShow'	:	false
			});
			
			$j("a.featureItem2").fancybox({
			'speedIn'		:	600, 
			'speedOut'		:	200,
			'width'			:	648,
			'height'		:	457,
			'autoScale'		:	true,
			'autoDimensions':	true,
			'overlayShow'	:	false
			});


			$j("a.featureItem3").fancybox({
			'speedIn'		:	600, 
			'speedOut'		:	200,
			'width'			:	648,
			'height'		:	457,
			'autoScale'		:	true,
			'autoDimensions':	true,
			'overlayShow'	:	false
			});

$j("a.screenZoom").fancybox({
'speedIn' : 200,
'speedOut' : 200,
'width' : 648,
'height' : 457,
'autoScale' : true,
'autoDimensions': true,
'overlayShow' : false
});

		
		}
		/*
			sIFR
		*/
		,loadSIFR : function() {
			var c = Snorkel;

			/*
				Register the fonts
			*/
			var gothamBook = {
				src: c.Config.sSwfPath + 'gotham-book.swf'
			}

			var gothamMedium = {
				src: c.Config.sSwfPath + 'gotham-medium.swf'
			}

			/*
				Activate the fonts
			*/
			sIFR.activate(gothamBook);
			sIFR.activate(gothamMedium);

			/*
				Hi, we're the replacements
			*/
			sIFR.replace(gothamBook, {
				selector: '#content>h1',
				wmode: 'transparent',
				css: [
					'.sIFR-root { background-color: #FFFFFF; color: #CC3333; font-size: 42px; letter-spacing: -1.5; }',
					'a { color: #FFFFFF; text-decoration: none; }',
					'a:link { color: #FFFFFF; text-decoration: none; }',
					'a:hover { color: #E3E3E3; text-decoration: underline; }'
				]
			});

			sIFR.replace(gothamMedium, {
				selector: '.features h2, body.pg-2col #related .mod .title',
				wmode: 'transparent',
				css: [
					'.sIFR-root { background-color: #FFFFFF; color: #CC3333; font-size: 17px; }',
					'a { color: #FFFFFF; text-decoration: none; }',
					'a:link { color: #FFFFFF; text-decoration: none; }',
					'a:hover { color: #E3E3E3; text-decoration: underline; }'
				]
			});
		}

		/*
			Clear text fields on focus
		*/
		,inputFocus : function() {
			var oInputs = $j("input[type=text]");
			if (oInputs.length) {
				for (var i = 0; i < oInputs.length; i++) {
					oInputs[i].onfocus = function() {
						this.value = "";
					}
				}
			}
		}

		/*
			Features
		*/
		,featureZoom : function() {
			var oPicLinks = $j("li.feat>p.pic>a");

			$j(oPicLinks).each(function() {
				if ($j(this).attr("href").match(/\.(jpe?g|gif|png)/)) {
					$j(this).append("<i>View larger version of this image</i>");
				}
			});
		}

		/*
			Download tabs
		*/
		,tabsDownload : function() {
			var oItems = $j("#steps>li");

			if ($j(oItems).length) {
				var iLimit = 0;
				var sSlug = oNavList = iSafe = "";
				var oNavList = "<ol class=\"nav\">\n";

				$j(oItems).each(function(i) {
					iSafe = i + 1;
					sSlug = "step-" + iSafe;

					var iHeight = $j(this).height();

					if (iHeight > iLimit) {
						iLimit = iHeight + 20;
					}

					$j(this).attr("id", sSlug);
					oNavList += "<li><a href=\"#" + sSlug + "\"><b>Step</b> " + iSafe + "</a></li>\n";
				});

				oNavList += "</ol>";

				$j("ol#steps").before(oNavList);
				$j("#how-to ol.nav>a").remove();	/* Safari fix */

				if ($j("#how-to ol.nav").length) {
					$j("#steps").height(Math.ceil(iLimit / 13) + "em");

					if ($j.browser.msie) {
						$j("#how-to ol.nav").tabs();
					} else {
						$j("#how-to ol.nav").tabs({ fx: {
							duration: "fast"
							,opacity: "toggle"
						}});
					}
				}
			}
		}

		/*
			Homepage tabs
		*/
		,tabsHome : function() {
			var oItems = $j("ul#features>li");
			var iMax = oItems.length;

			if (iMax > 0) {
				var iLimit = 0;
				var sSlug = oNavList = sClass = iSafe = "";
				var oNavList = "<ol class=\"nav\">";

				$j(oItems).each(function(i) {
					iSafe = i + 1;
					sSlug = "feature-" + iSafe;

					var iHeight = $j(this).height();

					if (iHeight > iLimit) {
						iLimit = iHeight + 20;
					}

					$j(this).attr("id", sSlug);

					var sTitle = $j(this).find("h4 > img").attr("alt");
					if (sTitle) {
						if (sTitle.charAt(sTitle.length - 1) == ":") {
							sTitle = sTitle.slice(0, -1);
						}
					} else {
						var sTitle = $j(this).find("h4").html();
					}

					oNavList += "<li><a id=\"nav-" + sSlug + "\" href=\"#" + sSlug + "\">" + sTitle + "</a></li>";
				});

				oNavList += "</ol>";

				$j(oNavList).insertBefore("ul#features");

				

				$j("body.sect-home #main ol.nav>li:first").addClass("first");

				if ($j.browser.msie) {
					$j("body.sect-home #main ol.nav").tabs().tabs('rotate', 9000, false);
				} else {
					$j("body.sect-home #main ol.nav").tabs({ fx: {
						opacity: "toggle" 
					}}).tabs('rotate', 9000, false);
				}
			}
		}

		/*
			TABLE STRIPES!!1!
		*/
		,tableStripes : function() {
			$j("div>table tbody>tr:odd, #platforms>ul>li:odd").addClass("alt");
		}

		/*
			Add @class to <html> if JS is active
		*/
		,tagIt : function() {
			var c = Snorkel;

			var oHtml = $j("html");

			if ($j(oHtml)) {
				$j(oHtml).addClass(c.Config.sHTMLtag);
			}
		}
	}
};

Snorkel.init();


