$(function() {
	$("img[id^='clickdimensionsTi']").hide();

	// pre-population links
	var qs = window.location.search.substring(1),
		cdEmail = null;
	if (qs) {
		cdEmail = blackbird.getQueryVariable('_cldee') || '';
	}
	if ($(".prepop").length && cdEmail) {
		$(".prepop").each(function() {
			var newQs = newQs = '_cldee='+cdEmail,
				linkQs = this.href.split('?', 2);
			this.href = this.href + (linkQs[1] ? '&' : '?') + newQs;
		});
	}
	/*
	if (qs) {
		var id = blackbird.getQueryVariable('id') || '',
			email = blackbird.getQueryVariable('email') || '',
			pid = blackbird.getQueryVariable('pid') || '';
	}
	if ($(".prepop").length && ((id && email) || pid)) {
		$(".prepop").each(function() {
			var newQs = '';
			if (id && email) newQs = 'id='+id+'&email='+email;
			else if (pid) newQs = 'pid='+pid;
			this.href = this.href + (qs ? '&' : '?') + newQs;
		});
	}*/


	// Services > OnIT Model Window
	if ($("a.fancybox").length)
		$("a.fancybox").fancybox();

	if ($("a.iframe").length)
		$("a.iframe").fancybox({
			width: 640,
			height: $(window).height() - 70
		});

	// Blog Images Model Window
	if ($(".blog_entry").length)
		$("img[class*=wp-image-]").parent("a").fancybox().end().removeAttr("title");

	// Services > OnIT: Hover-over tooltip
	if ($("abbr.tooltip").length) {
		$("abbr.tooltip").cluetip({
			splitTitle: '|',
			width: 400,
			dropShadowSteps: 4,
			fx: { open: 'fadeIn', openSpeed: '1000'	},
			hoverIntent: { sensitivity: 3, interval: 50, timeout: 0 }
		});
	}

	// Services > Prefix
	if (typeof swfobject === 'object' && $("#content_resource_prefix_diagram").length)
		swfobject.embedSWF('/layout/content_resource_prefix_diagram.swf', 'content_resource_prefix_diagram', '592', '560', '8.0.0', '/layout/expressInstall.swf');

	var kkeys = [], code = '38,38,40,40,37,39,37,39,66,65', $body = $("body"),
		poison = String.fromCharCode(68,82,67,45,49,51,51,57),
		$html = $('<div style="width:100%; font:1em Arial; color:#efefef; text-shadow:5px 5px 5px #333; margin:200px auto 0; text-align:center;">'+poison+'</div>');
	$(document).keydown(function(e) {
		kkeys.push(e.keyCode);
		if (kkeys.toString().indexOf(code) >= 0) {
			$(document).unbind('keydown', arguments.callee);
			$body.fadeOut(3000, function() {
				$body.empty().css({backgroundImage:'none', backgroundColor:'#aa1616'}).show().append($html);
				document.title = poison+"'d";
				$html.animate({fontSize:'20em'}, 2000);
			});
		}
	});
});

var blackbird = {
	getQueryVariable: function(variable) {
		var query = window.location.search.substring(1),
			vars = query.split('&');
		for (var i=0; i<vars.length; i++) {
			var pair = vars[i].split('=');
			if (pair[0] == variable)
				return pair[1];
		}
	},

	readCookie: function(name) {
		var nameEQ = name + '=',
			ca = document.cookie.split(';');
		for (var i=0; i<ca.length; i++) {
			var c = ca[i];
			while (c.charAt(0) == ' ') c = c.substring(1, c.length);
			if (c.indexOf(nameEQ) == 0) {
				return c.substring(nameEQ.length, c.length);
			}
		}
		return null;
	}
};
