var mainImages = new Images();
var contentGallery = new ContentGallery();

var num = Math.floor(Math.random() * 4);
mainImgUpdate();

$("#mainimg-nav ul .previmg").click(function() {
	if(num == 0) {
		num = 3;
	} else {
		num = num - 1;
	}
	mainImgUpdate();
});
$("#mainimg-nav ul .nextimg").click(function() {
	if(num == 3) {
		num = 0;
	} else {
		num = num + 1;
	}
	mainImgUpdate();
});


$("#dotAlphaZ").mouseover(function() {
	featureRollover("/boats/rz4/Alpha_Z_Tower");
}).click(function() {
	featureRollover("/boats/rz4/Alpha_Z_Tower");
});

$("#dotTouch").mouseover(function() {
	featureRollover("/boats/rz4/Tige_Touch");
}).click(function() {
	featureRollover("/boats/rz4/Tige_Touch");
});

$("#dotTAC").mouseover(function() {
	featureRollover("/boats/rz4/transom_activity_center");
}).click(function() {
	featureRollover("/boats/rz4/transom_activity_center");
});

$("#dotWalkOverTran").mouseover(function() {
	featureRollover("/boats/rz4/walkover_transom");
}).click(function() {
	featureRollover("/boats/rz4/walkover_transom");
});

$("#dotPcm").mouseover(function() {
	featureRollover("/boats/rz4/PCM_engines");
}).click(function() {
	featureRollover("/boats/rz4/PCM_engines");
});

$("#dotSidePockets").mouseover(function() {
	featureRollover("/boats/rz4/interior_side_pockets");
}).click(function() {
	featureRollover("/boats/rz4/interior_side_pockets");
});

$("#dotBow").mouseover(function() {
	featureRollover("/boats/rz4/oversized_bow");
}).click(function() {
	featureRollover("/boats/rz4/oversized_bow");
});

$("#dotObservSeat").mouseover(function() {
	featureRollover("/boats/rz4/wrap_around_observers_seat");
}).click(function() {
	featureRollover("/boats/rz4/wrap_around_observers_seat");
});

$("#dotCarpet").mouseover(function() {
	featureRollover("/boats/rz4/snap_in_carpet");
}).click(function() {
	featureRollover("/boats/rz4/snap_in_carpet");
});

$("#dotAudio").mouseover(function() {
	featureRollover("/boats/rz4/Wet_Sounds_Audio");
}).click(function() {
	featureRollover("/boats/rz4/Wet_Sounds_Audio");
});

$("#dotDesign").mouseover(function() {
	featureRollover("/boats/rz4/design_and_comfort");
}).click(function() {
	featureRollover("/boats/rz4/design_and_comfort");
});

$("#dotSwimPlatform").mouseover(function() {
	featureRollover("/boats/rz4/oversized_swim_platform");
}).click(function() {
	featureRollover("/boats/rz4/oversized_swim_platform");
});

function Images() {
	this.images = new Array();
	this.images[0] = "/assets/images/models/rz4/main/1.jpg";
	this.images[1] = "/assets/images/models/rz4/main/2.jpg";
	this.images[2] = "/assets/images/models/rz4/main/3.jpg";
	this.images[3] = "/assets/images/models/rz4/main/4.jpg";
}

function ContentGallery() {
	$("#contentGalleryLt").css({"visibility": "hidden"});
	$("#contentGalleryLt").click(function() {
		$("#contentGallery .galleryWrapper ul").stop(true, true);
		if($("#contentGallery .galleryWrapper ul").position().left >= -464) {
			$("#contentGallery .galleryWrapper ul").animate({"left": "+=465px"}, "slow", showHideArrows);
			$("#contentGalleryPg1").css({"background-position": "0 -7px"});
			$("#contentGalleryPg2").css({"background-position": "0 0"});
			$("#contentGalleryPg3").css({"background-position": "0 0"});
			$("#contentGalleryPg4").css({"background-position": "0 0"});
			$("#contentGalleryPg5").css({"background-position": "0 0"});
		} else if($("#contentGallery .galleryWrapper ul").position().left >= -929) {
			$("#contentGallery .galleryWrapper ul").animate({"left": "+=465px"}, "slow", showHideArrows);
			$("#contentGalleryPg1").css({"background-position": "0 0"});
			$("#contentGalleryPg2").css({"background-position": "0 -7px"});
			$("#contentGalleryPg3").css({"background-position": "0 0"});
			$("#contentGalleryPg4").css({"background-position": "0 0"});
			$("#contentGalleryPg5").css({"background-position": "0 0"});
		} else if($("#contentGallery .galleryWrapper ul").position().left >= -1394) {
			$("#contentGallery .galleryWrapper ul").animate({"left": "+=465px"}, "slow", showHideArrows);
			$("#contentGalleryPg1").css({"background-position": "0 0"});
			$("#contentGalleryPg2").css({"background-position": "0 0px"});
			$("#contentGalleryPg3").css({"background-position": "0 -7px"});
			$("#contentGalleryPg4").css({"background-position": "0 0"});
			$("#contentGalleryPg5").css({"background-position": "0 0"});
		} else if($("#contentGallery .galleryWrapper ul").position().left >= -2309) {
			$("#contentGallery .galleryWrapper ul").animate({"left": "+=465px"}, "slow", showHideArrows);
			$("#contentGalleryPg1").css({"background-position": "0 0"});
			$("#contentGalleryPg2").css({"background-position": "0 0px"});
			$("#contentGalleryPg3").css({"background-position": "0 0px"});
			$("#contentGalleryPg4").css({"background-position": "0 -7px"});
			$("#contentGalleryPg5").css({"background-position": "0 0"});
		}
	});
	$("#contentGalleryRt").click(function() {
		$("#contentGallery .galleryWrapper ul").stop(true, true);
		if($("#contentGallery .galleryWrapper ul").position().left >= -462) {
			$("#contentGallery .galleryWrapper ul").animate({"left": "-=465px"}, "slow", showHideArrows);
			$("#contentGalleryPg1").css({"background-position": "0 0"});
			$("#contentGalleryPg2").css({"background-position": "0 -7px"});
			$("#contentGalleryPg3").css({"background-position": "0 0"});
			$("#contentGalleryPg4").css({"background-position": "0 0"});
			$("#contentGalleryPg5").css({"background-position": "0 0"});
		} else if($("#contentGallery .galleryWrapper ul").position().left >= -927) {
			$("#contentGallery .galleryWrapper ul").animate({"left": "-=465px"}, "slow", showHideArrows);
			$("#contentGalleryPg1").css({"background-position": "0 0"});
			$("#contentGalleryPg2").css({"background-position": "0 0"});
			$("#contentGalleryPg3").css({"background-position": "0 -7px"});
			$("#contentGalleryPg4").css({"background-position": "0 0"});
			$("#contentGalleryPg5").css({"background-position": "0 0"});
		} else if($("#contentGallery .galleryWrapper ul").position().left >= -1392) {
			$("#contentGallery .galleryWrapper ul").animate({"left": "-=465px"}, "slow", showHideArrows);
			$("#contentGalleryPg1").css({"background-position": "0 0"});
			$("#contentGalleryPg2").css({"background-position": "0 0"});
			$("#contentGalleryPg3").css({"background-position": "0 0"});
			$("#contentGalleryPg4").css({"background-position": "0 -7px"});
			$("#contentGalleryPg5").css({"background-position": "0 0"});
		} else if($("#contentGallery .galleryWrapper ul").position().left >= -2307) {
			$("#contentGallery .galleryWrapper ul").animate({"left": "-=465px"}, "slow", showHideArrows);
			$("#contentGalleryPg1").css({"background-position": "0 0"});
			$("#contentGalleryPg2").css({"background-position": "0 0"});
			$("#contentGalleryPg3").css({"background-position": "0 0"});
			$("#contentGalleryPg4").css({"background-position": "0 0px"});
			$("#contentGalleryPg5").css({"background-position": "0 -7px"});
		}
	});
}

function mainImgUpdate() {
	with(mainImages) {
		$("#mainimg").css({"background": "url("+ images[num] +") no-repeat"});
	}
	$("#mainimg-nav ul .imgdot").css({"background-position": "0 0"});
	$("#mainimg-nav ul .imgdot:eq("+ num +")").css({"background-position": "0 -6px"});
}

function showHideArrows() {
	if($("#contentGallery .galleryWrapper ul").position().left >= -462) {
		$("#contentGalleryLt").css({"visibility": "hidden"});
		$("#contentGalleryRt").css({"visibility": "visible"});
	} else if($("#contentGallery .galleryWrapper ul").position().left >= -927) {
		$("#contentGalleryLt").css({"visibility": "visible"});
		$("#contentGalleryRt").css({"visibility": "visible"});
	} else if($("#contentGallery .galleryWrapper ul").position().left >= -1392) {
		$("#contentGalleryLt").css({"visibility": "visible"});
		$("#contentGalleryRt").css({"visibility": "visible"});
	} else if($("#contentGallery .galleryWrapper ul").position().left >= -1857) {
		$("#contentGalleryLt").css({"visibility": "visible"});
		$("#contentGalleryRt").css({"visibility": "visible"});
	} else if($("#contentGallery .galleryWrapper ul").position().left >= -2307) {
		$("#contentGalleryLt").css({"visibility": "visible"});
		$("#contentGalleryRt").css({"visibility": "hidden"});
	}
}

function featureRollover(feature) {
	$("#boatFeature").load(feature);
	// only use below if calling reset.css in feature layout.
	//$("body").css({"background-color": "#333"});
}