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

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

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

$("#dotLCD").mouseover(function() {
	featureRollover("/boats/z1/LCD_display");
}).click(function() {
	featureRollover("/boats/z1/LCD_display");
});

$("#dotDash").mouseover(function() {
	featureRollover("/boats/z1/low_profile_dash");
}).click(function() {
	featureRollover("/boats/z1/low_profile_dash");
});

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

$("#dotStorage").mouseover(function() {
	featureRollover("/boats/z1/massive_storage_components");
}).click(function() {
	featureRollover("/boats/z1/massive_storage_components");
});

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

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

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

function Images() {
	this.images = new Array();
	this.images[0] = "/assets/images/models/z1/main/1.jpg";
	this.images[1] = "/assets/images/models/z1/main/2.jpg";
	this.images[2] = "/assets/images/models/z1/main/3.jpg";
	this.images[3] = "/assets/images/models/z1/main/4.jpg";
	this.images[4] = "/assets/images/models/z1/main/5.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"});
		} 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"});
		} 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"});
		}
	});
	$("#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"});
		} 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 0px"});
		} 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"});
		}
	});
}

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": "hidden"});
	}
}

function featureRollover(feature) {
	$("#boatFeature").load(feature);
}