(function(jQuery) {

	var hpage = {
		top: 0,
		currentPanel: "",
		panelHeight: 0,
		panelWidth: 0,
		panelMotionSet: {
			top: 0,
			left: 0
		},
		onDomReady: function() {

			//setting initial values based on actuals
			hpage.currentPanel = jQuery("#carousel ul li:first").attr("id");
			hpage.panelHeight = jQuery("#carousel ul li:first").height();
			hpage.panelWidth = jQuery("#carousel ul li:first").width();
			//hpage.panelMotionSet.left = hpage.panelWidth + "px";

			//hpage.onImagesLoaded();
			//hpage.bindHover("#carouselNav li.next");
			//hpage.unbindHover("#carouselNav li.next");
			jQuery("#carousel li").click(hpage.movePanels);
			jQuery("#carouselNav li.next").click(hpage.movePanels);

		},
		onImagesLoaded: function() {
			jQuery("#completeWrapper").css("display","none");
			var imgLoader = new Image();
			jQuery(imgLoader).load(function() { jQuery("#completeWrapper").fadeIn(5000); });
			imgLoader.src = "/wp-content/themes/arx-default/_inc/images/who.jpg";
		},
		bindHover: function(el) {
			jQuery(el).css({ display:"block", opacity:0 });
			jQuery(el).mouseenter(function() {
				jQuery(this).animate({ opacity: 1 },200);
			});
			jQuery(el).mouseleave(function() {
				jQuery(this).stop(true);
				jQuery(this).animate({ opacity: 0 },200);
			});
		},
		unbindHover: function(el) {
			jQuery(el).css({ display:"none" }).unbind();
		},
		movePanels: function() {


			var thisPanel = "#carousel ul li#" + hpage.currentPanel;
			if(jQuery(thisPanel).next("li").length) {
				hpage.currentPanel = jQuery(thisPanel).next("li").attr("id");
			}
			else {
				hpage.currentPanel = jQuery("#carousel ul li:first").attr("id");
			}



			//var hasClass = jQuery(this).hasClass("class");
			if(hpage.currentPanel == "who") {
				hpage.panelMotionSet.top = 0;
				hpage.panelMotionSet.left = 0;
			}
			else if(hpage.currentPanel == "what") {
				hpage.panelMotionSet.top = 0;
				hpage.panelMotionSet.left = (-hpage.panelWidth) + "px";
			}
			else if(hpage.currentPanel == "where") {
				hpage.panelMotionSet.top = (-hpage.panelHeight) + "px";
				hpage.panelMotionSet.left = (-hpage.panelWidth) + "px";
			}
			else if(hpage.currentPanel == "why") {
				hpage.panelMotionSet.top = (-hpage.panelHeight) + "px";
				hpage.panelMotionSet.left = (-hpage.panelWidth*2) + "px";
			}


//			hpage.top = hpage.top - 301;
//			if(jQuery("#carousel ul").css("top") == "-903px") { hpage.top = 0; }
//			var topWithPx = hpage.top + "px";
			jQuery("#carousel ul").animate(hpage.panelMotionSet, 500);
			return false;
		}

	}

	window.hpage = hpage;
	jQuery(document).ready(function(){ hpage.onDomReady(); });

})(jQuery);