﻿$(function ()
{
	var w = $(window);
	var s = $("#slider");
	var p = $("#sliderpagination");
	var sp = $("#slidersplash");
	var spc = sp.find("a");
	var fw = $(".fixedwidth").width(w.width());


	function enableCarousel()
	{
		s.find(".slider-inner").carouFredSel(
		{
			cookie: "caroufredsel_default",
			auto: 5000,
			pagination: p,

			scroll: {
				duration: 600,
				pauseOnHover: true,

				onBefore: $.debounce(0, function ()
				{
					sp.fadeTo(400, 0, function ()
					{
						spc.hide();
					});
				}),

				onAfter: $.debounce(0, function ()
				{
					sp.fadeTo(200, 1);

					$(spc[parseInt($.cookie("caroufredsel_default") || "0", 10)]).show();
				})
			}
		});
	}


	w.resize($.debounce(800, function ()
	{
		fw.css("width", w.width());

		enableCarousel();
	}));


	enableCarousel();


	$(".campaigns li").mouseenter(function ()
	{
		$(this).fadeTo(300, 0.85);

	}).mouseleave(function ()
	{
		$(this).fadeTo(150, 1);
	});


	jQuery.fn.center = function ()
	{
		this.css("position", "absolute");
		this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
		this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
		return this;
	};


	var iframe = $("#clubwmodal");

	var position = [40, ($(window).width() / 2) - (iframe.width() / 2)];

	$(".call-to-action-button").click(function ()
	{
		iframe.prop("src", "ClubWSignup.aspx");

		window.clubwmodal = iframe.modal(
		{
			appendTo: "form",
			opacity: 80,
			position: position,
			overlayCss: {
				backgroundColor: "#515151"
			}
		});
	});
});
