/*
WebFontConfig = {
	google: { families: [ 'Nobile' ] },
	custom: { urls: [ 'http://www.jetgraphics.net/layout/style-quicksandbook.css' ] }
};
(function() {
	var wf = document.createElement('script');
	wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
	'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
	wf.type = 'text/javascript';
	wf.async = 'true';
	var s = document.getElementsByTagName('script')[0];
	s.parentNode.insertBefore(wf, s);
})();
*/

$(function() {
	var qs = window.location.search.substring(1);

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

	/*
	$(".flip_left, .flip_right").hover(function() {
		$(this).toggleClass('flip_over', 1000);
	});
	*/


	// pre-population links
	var cdEmail = null;
	if (qs && !getQueryVariable('ignore')) {
		cdEmail = 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;
		});
	}

	// fancybox assignment
	var popupConfig = [
		{ className:'.request-sample-kit', height:600 },
		{ className:'.schedule-a-pickup', height:600 },
		{ className:'.request-sticker-kit', height:550 },
		{ className:'.submit-pic', height:580 },
		{ className:'.rules', height:270 }
	];
	$.each(popupConfig, function(i, item) {
		var $item = $(item.className);
		if ($item.length) {
			var linkQs = $item.attr('href').split('?', 2);
			$item.attr('href', $item.attr('href') + (linkQs[1] ? '&' : '?') + 'format=popup');
			// if current page not in a frame
			if (!!(window.location == window.parent.location)) {
				$item.fancybox({
					type: 'iframe',
					width: 535,
					height: item.height,
					margin: 0,
					padding: 0
				});
			}
		}
	});

	//$('.fancybox').fancybox({ margin:0, padding:0 });

	hashLinks();
	createClueTips();
});

// convert normal like to hijax links
function hashLinks() {
	var $hashLinks = $(".hash");
	if ($hashLinks.length) {
		$hashLinks.each(function() {
			this.href = this.href.replace(/\?/, '#');
		});
	}
};

function createClueTips() {
	if ($(".tooltip").length) {
		$(".tooltip").cluetip({
			splitTitle: '|',
			width: 400,
			clickThrough: true,
			dropShadow: false,
			fx: { open: 'fadeIn', openSpeed: 500 },
			hoverIntent: { sensitivity: 3, interval: 50, timeout: 1000 }
		});
	}
};

function readCookie(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;
};


function getQueryVariable(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];
	}
};

if (typeof console === 'undefined') var console = { log: function() {} };
