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

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

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

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

$("#dotRevSeat").mouseover(function() {
	featureRollover("/boats/i22/reverse_seat");
}).click(function() {
	featureRollover("/boats/i22/reverse_seat");
});

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

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

$("#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();
});

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

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

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