﻿//<!--

$("#highlights").ready(function() {

	// MENU //
	// menu selection
	var $carouselDivs = $("#highlights .carousels > div");
	var highlightCategorySelect = function() {
		$("#highlights div.category img").attr("selected", "false");
		$("#highlights div.category img").hide();
		$(this).attr("selected", "true");
		$(this).show();
		$("#highlights div.category a").show();
		$("#highlights div.category a").attr("selected", "true");
		$(this).prev().attr("selected", "false");
		$(this).prev().hide();
		$carouselDivs.hide();
		$("#highlights .carousels [carousel=" + $(this).attr("carousel") + "]").show();
		CreateCarousel($(this).attr("carousel"));
		return false;
	}

	var $categoryImgTags = $("#highlights div.categories img");
	$categoryImgTags.click(highlightCategorySelect);

	// hover over items
	var highlightMenuHover = function() {
		$(this).hide();
		$(this).next().show();
	}

	// mouse out of hovered item
	var highlightMenuMouseOut = function() {
		$("#highlights div.category img[selected=false]").hide();
		$("#highlights div.category a[selected=true]").show();
	}

	var $hlATags = $("#highlights div.categories a");
	$hlATags.hover(highlightMenuHover);

	var $hlImgTags = $("#highlights div.categories img");
	$hlImgTags.mouseout(highlightMenuMouseOut);

	// CAROUSELS //
	var $carousels = new Array();
	function CreateCarousel(id) {
		var idx = Number(id);
		if ($carousels[idx] == null) {
			$carousels[idx] = $("#highlights .carousels [carousel=" + id + "] .carousel").jCarouselLite({
				btnNext: "#highlights .carousels [carousel=" + id + "] .next",
				btnPrev: "#highlights .carousels [carousel=" + id + "] .prev",
				auto: 4000,
				scroll: -1,
				speed: 1000,
				circular: true,
				visible: 3.5,
				autoStopOnNextPrevClick: true,
				autoStopOnItemClick: true,
				autoShow: true,
				onItemClick: itemClick,
				afterEnd: itemClick,
				afterLoad: itemClick
			});
		}
	}

	// image select show blurb
	var itemClick = function(item) {
		$("#highlights .blurbs div div[item]").hide(); // hide all blurbs
		$("#highlights .blurbs div[carousel=" + $(item).closest("[carousel]").attr("carousel") + "] div[item=" + $(item).eq($(item).size() - 1).children("img").attr("item") + "]").show();
		$(item).eq($(item).size() - 1).siblings().addClass("option");
		$(item).eq($(item).size() - 1).removeClass("option");
	}

	// random carousel to show
	var randomnumber = Math.floor(Math.random() * $("#highlights .categories .category").size());
	var randomCategory = $("#highlights .categories img[carousel=" + randomnumber.toString() + "]");
	highlightCategorySelect.call(randomCategory);

});

// -->
