
/* do the Cufon replace
	*/
Cufon.replace('h1', {
	fontFamily: 'Avenir LT 65 Medium'
});
Cufon.replace('#navigation a', {
	fontFamily: 'Avenir LT 65 Medium',
	hover: true
});
Cufon.replace('h2', {
	fontFamily: 'Avenir LT 65 Medium'
});
Cufon.replace('h3', {
	fontFamily: 'Avenir LT 65 Medium'
});
Cufon.replace('.SuperHeading h1', {
	color: '-linear-gradient(#fdfefe, #d6dcdf)',
	textShadow: '#333 1px 1px',
	fontFamily: 'Avenir LT 65 Medium'
});
Cufon.replace('.BigPrice', {
	color: '-linear-gradient(#ffffff, #c0cace)',
	textShadow: '#000 1px 2px',
	fontFamily: 'Avenir LT 65 Medium'
});

/*
	setup both the global language options
	and setup the mailing list fields
	*/
redrocketcms.classes.ContactPage.setFormRequiredFields("CF2dc92f", ["FromNameField", "FromAddrField"]);
redrocketcms.classes.ContactPage.setGlobalStringTable({
	FromName: "name",
	FromAddr: "email address",
	UserURI: "phone number or url",
	EmailSubject: "subject",
	EmailTxtBody: "message",
	SubmitButton: "> GO!"
});

/* add functionality with jquery
	*/
$(document).ready(function() {
	setNewsScollPane();
	enableProductBar();
	enableDisplays();
	enableAlbums();
	makeChildRollOvers();
	enableProductPages();
	createContactPageEvents();
	fixSubNavs();
});
function fixSubNavs () {
	$("#navigation .NoHref > a")
		.removeAttr("href")
		.css("cursor", "default")
		.click(function () {
			return false;
		});
}
function setNewsScollPane () {
	var innerheight = 250;
	var newsfeed = $("#ID-1e8820 .Children").get(0);
	/* setup the newsfeed scrollbar
		*/
	itdr.classes.ScrollPane.initialize(newsfeed, {
		thickness: 8,
		autohide: true
	});
	itdr.classes.ScrollPane.resize(newsfeed, 282, innerheight);
	$("#skirt").height(innerheight+70);
	$("#skirt .Bucket .Data").height(innerheight);
}
function createContactPageEvents () {
	var selector = "fieldset.MainInfoFieldset input, fieldset textarea";
	$(selector).blur(function () {
		var self = $(this);
		var value = self.val();
		self.removeClass("Focused");
		if (value!="") self.addClass("Valid");
		else self.removeClass("Valid");
	});
	$(selector).blur();
	$(selector).focus(function () {
		$(this).addClass("Focused");
	});
}
function enableProductBar () {
	if ($.browser.msie && $.browser.version < 7) return;
	$('#ID-1e88a9 li')
		.removeClass('highlight')
		.find('a')
		.append('<span class="hover" />')
		.each(function () {
			var $span = $('> span.hover', this).css('opacity', 0);
			$(this).hover(function () {
				$span.stop().fadeTo(200, 1);
			}, function () {
				$span.stop().fadeTo(200, 0);
			});
		});

}
function showDisplayNext (num) {
	$(".Display").each(function (i) {
		if (i==num) {
			var self = $(this);
			var index = self.data("index");
			var total = self.data("total");
			index += 1;
			if (index>=total) index = 0;
			self.data("index", index);
			showDisplayIndex(num, index);
		}
	});
}
function showDisplayIndex (num, index) {
	$(".Display").each(function (i) {
		if (i==num) {
			var self = $(this);
			var href = "";
			self.find("a").each(function (i) {
				if (i==index) href = $(this).attr("href");
			});
			self.data("href", href);
			self.find("li").removeClass("Active")
				.each(function (i) {
					if (i==index) $(this).addClass("Active");
				});
			self.find(".ItemsInner")
				.stop()
				.animate({
					"left": index*882*-1
				}, 800, "easeInOutExpo");
		}
	});
}
function enableDisplays () {
	$(".Display").each(function (i) {
		var self = $(this);
		var items = self.find(".Item");
		items.each(function (j) {
			$(this).css("left", (j*882) + "px");
		});
		if (items.length>1) {
			var chrome = self.find(".DisplayChrome");
			chrome.css("cursor", "pointer");
			chrome.click(function () {
				if (self.data("href")!="") document.location = self.data("href");
			});
		}
		self.data("href", "");
		self.data("index", 0);
		self.data("total", items.length);
		self.data("slideshow", setInterval("showDisplayNext(" + i + ");", 8000));
		var dots = self.find("li");
		dots.each(function (j) {
			$(this).find("a")
				.removeAttr("href")
				.data("num", i)
				.data("index", j)
				.click(function () {
					clearInterval(self.data("slideshow"));
					showDisplayIndex($(this).data("num"), $(this).data("index"));
				});
		});
		showDisplayIndex(i, 0);
		var selector = self.find(".Selector").first();
		var width = selector.outerWidth();
		selector.css("left", ((887-width)/2)+"px");
	});

}
function showNextProductPageChild (num) {
	$(".ProductPage .Children").each(function (i) {
		if (i==num) {
			var self = $(this);
			var index = self.data("index");
			var total = self.data("total");
			index += 1;
			if (index>=total) index = 0;
			self.data("index", index);
			var items = self.find(".Child");
			items.each(function (j) {
				if (j==index) $(this).fadeIn();
				else $(this).fadeOut();
			});
		}
	});
}
function enableProductPages () {
	$(".ProductPage .Children").each(function (i) {
		var self = $(this);
		var items = self.find(".Child");
		self.css("position", "relative");
		self.css("overflow", "hidden");
		self.css("height", "80px");
		self.data("index", 0);
		self.data("total", items.length);
		self.data("slideshow", setInterval("showNextProductPageChild(" + i + ");", 5000));
		items.each(function (j) {
			$(this).css("position", "absolute");
			$(this).css("top", "0px");
			$(this).css("left", "0px");
			if (j>0) $(this).fadeOut();
		});
	});
}
function enableAlbums () {
	$("a[rel='slideshow']").colorbox({
		slideshow: false,
		transition: "fade",
		slideshowSpeed: 5000,
		opacity: .5
	});
}
function makeChildRollOvers () {
	var selector = ".Album";
	$(selector + " .Children .Child .Graphic img").css("opacity", 1);
	$(selector + " .Children .Child .Context").css("opacity", 0);
	$(selector + " .Children .Child .Context").each(function () {
		var offset = (($(this).height()-$(this).parent().height())/2)*-1;
		$(this).css("top", offset);
	});
	$(selector + " .Children .Child").mouseenter(function () {
		$(".Graphic img", this).fadeTo("fast", .15);
		$(".Context", this).fadeTo("fast", 100);
	});
	$(selector + " .Children .Child").mouseleave(function () {
		$(".Graphic img", this).fadeTo("fast", 1);
		$(".Context", this).fadeTo("fast", 0);
	});
}
