/* ---- =JQUERY --*/

$(function () {

	$(".textual").each(function () {
		$(this).children("p:last").addClass("remove");
	});

	$("#list-wrapper").each(function () {
		$(this).children(".caseStudies:last").addClass("bor");
	});

	$('#mainNav li:first a').addClass("init");
	$('table tr td:last').addClass("last");

	$('ul#subNav li ul li:last-child').addClass("bordered");

	$('#site .center p + h2, #site .center ul + h2, #site .center h2 + ul').addClass("con-pad");
	$('blockquote').prepend('<span class="qr"></span>').append('<span class="q"></span>');
	$('#sitemap > li > a').addClass("lev01");
	$('#sitemap > li > ul > li > ul > li > a').addClass("lev03");

	$('#site .clients li:nth-child(3n)').addClass("mr0");

	$(".ui-tabs-nav a").each(function (i) {
		$(this).attr("href", "#fragment-" + (i + 1));
	});

	// homepage hero
	if ($('#featured').length != 0) {
		$("#featured").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", 5000, true);
		$("#featured").hover(
		function () {
			$("#featured").tabs("rotate", 0, true);
		},
		function () {
			$("#featured").tabs("rotate", 5000, true);
		});
	}
	// homepage carousel
	if ($('.pics').length != 0) {
		$('.pics').cycle({
			fx: 'fade',
			speed: 'slow',
			timeout: 0,
			next: '.next',
			prev: '.prev'
		});
		$('.text').cycle({
			fx: 'fade',
			speed: 'slow',
			timeout: 0,
			next: '.next',
			prev: '.prev'
		});
	}

	// glossary show/hide
	$('.glossary h2').hover(function () {
		$(this).toggleClass("on");
	});

	$('.glossary h2').click(function () {
		console.log($(this).next());
		$(this).next().toggle();
		$(this).toggleClass('add');
		return false;
	});

	// forms
	$("select").selectBox();

	$("input:checkbox").checkbox({
		cls: 'jquery-safari-checkbox',
		empty: '/img/blank.gif'
	});

	$("input:radio").checkbox({
		cls: 'jquery-safari-radio',
		empty: '/img/blank.gif'
	});

	/* ---- =LIGHTBOX --*/

	$(".video").colorbox({ iframe: true, innerWidth: 560, innerHeight: 345, opacity: 0.8, overlayClose: false });
	$(".inline").colorbox({ width: "50%", inline: true, href: "#inline" });


	// set :active in IE7+ and opera
	if (($.browser.msie && parseInt($.browser.version) > 6) || ($.browser.opera)) {
		$("a.btn, a.btnBack, a.btnDkBlue, a.btnLtBlue").bind({
			mousedown: function () {
				$(this).addClass('ie');
			},
			mouseleave: function () {
				$(this).removeClass('ie');
			}
		});
	}


	// remove default text in forms
	$("input[type='text'], input[type='email'], textarea").each(function () {
		$(this).data("orig", $(this).val());
		$(this).click(function () { $(this).val(""); });
		$(this).blur(function () { if ($(this).val() == "") { $(this).val($(this).data("orig")); } });
	});

	// publications show/hide
	$('.pub').hide();
	$('ul.pagHolder li a.show').click(function () {
		$(this).next().toggle();
		return false;
	});

	// publications content show/hide
	$('.pubCont').hide();
	$('ul.pagHolder li a.showCont').click(function () {
		$(this).next().toggle();

		if ($(this).next().is(":visible")) {


			var contentID = $(this).attr("data-contentID");
			var contentType = $(this).attr("data-contentType");
			var subscriberID = $(this).attr("data-subscriberID");

			$.ajax({
				type: "POST",
				async: false,
				url: "/ajax.asmx/StoreSubscriberContent",
				data: "{'contentViewedSubscriberID':'" + subscriberID + "','contentViewedContentID':'" + contentID + "','contentViewedContentDetails':'" + contentType + "'}",
				contentType: "application/json; charset=utf-8",
				dataType: "json",
				success: function (msg, status) {

					//console.log(msg.d);
				},

				error: function (e) {
					//console.log("Error: " + e);
				}

			});

		}

		return false;
	});


});

