// My Dream Rig - Ranger Boats


$(window).load(function() {
	var animglow = '<img src="images/header/animglow.gif" alt="" style="display: block; margin-left: 584px;" />';
	$('#landingHeaderBG').html(animglow);
});

$(document).ready(function() {

	$('#container').prepend('<div id="landingNavMask" style=" z-index: 9; display: none; position: fixed; left: 0; width: 100%; height: '+$(window).height()+'px; background-color: #000; -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=70); filter: alpha(opacity=70); -moz-opacity: 0.7; -khtml-opacity: 0.7; opacity: 0.7;"></div>')
	 
	// On intro page, bind onclick event to boat links
	$("#introNav a").click(function() {
		$("#introNav a").removeClass("selected");
		var model = $(this).attr("class").replace(/model(\w*).*/, "$1");
		$(this).addClass("selected");
		$("#introModLogo").attr("src", "images/"+model+"/"+model+"_model_indicator.png");
		$("#introModPhoto").attr("src", "images/"+model+"/"+model+"_photo.png");
		$("#introLearnMore").attr("href", model+".html");
		$("#introLearnMore").show();
	});
	
	// Check if this is a model landing page, and run those specific functions
	if (typeof(model) != "undefined") {
	
		// Get closed position of navigation
		landingNavOffset = $("#landingNav").css("top");
		
		// Bind onclick event to menu slide-out button
		$("#landingNavButton").click(function() {
			$("#landingNavMask").toggle('slow');
			$("#landingNav").animate({"top": ($("#landingNav").hasClass("open") ? landingNavOffset : "0px")}, 800, function() {
				$("#landingNav").toggleClass("open");
			});
		});
		
		$("#galleryPageVideo .thumbs a").click(function () {
			var vidpath = $(this).attr('rel');
			//var vidhtml = '<div id="thevideo"><img src="http://www.rangerboats.com/images/ajax-loader.gif"><\/div>';
			//$('#floatWinVideo #floatWinVideoContent #videoblock').append(vidhtml);		
			if ($('#intload').length) {
				$('#intload').remove();
			}	
			if ($('#pid_intload').length) {
				$('#pid_intload').remove();
			}	
			if ($('.mwplayer_interface').length) {
				$('.mwplayer_interface').remove();
			}	
			if ($('.mv-player').length) {
				$('.mv-player').remove();
			}
			if ($('.nativeEmbedPlayerPid').length) {
				$('.nativeEmbedPlayerPid').remove();
			}			
			if ($('#thevideo').length) {
				$('#thevideo').remove();
			}
			var newTr = "<div id='thevideo'><\/div>";			
			$("#videoblock").append(newTr);
			var flashvars = {};
			flashvars.autoPlay = "true";
			flashvars.loop = "true";
			flashvars.entryId = vidpath;
			flashvars.sourceType = "entryId";
			flashvars.widgetId = "_100";
			flashvars.partnerId = "100";
			flashvars.host = "media.pbhmarinegroup.com";
			flashvars.externalInterfaceDisabled = "false";
			//flashvars.readyF = onKdpReady;
			var params = {};
			params.quality = "best";
			params.wmode = "opaque";
			params.allowfullscreen = "true";
			params.allowscriptaccess = "always";
			var attributes = {};
			attributes.id = "thevideo";
			attributes.name = "thevideo";
			attributes.styleclass = "player";
			swfobject.embedSWF("http://media.pbhmarinegroup.com/index.php/kwidget/cache_st/1322069743/wid/_100/uiconf_id/4421531/", "thevideo", "640", "386", "10.0.0", "js/expressInstall.swf", flashvars, params, attributes);
			$('#floatWinVideo').show();			
		});
		
		// Bind onclick event to all close buttons
		$(".closebtn").attr("href", "javascript:void(0);").click(function() {
			$(this).parent().fadeOut(800);
			$(".landingFloatBtn, #landingModLogo").fadeIn(800);
			if ($(this).hasClass("isMoreLink")) $("#floatWinMore").fadeIn(800);
			bgSlideshow.show();
			if ($('#intload').length) {
				$('#intload').remove();
			}	
			if ($('#pid_intload').length) {
				$('#pid_intload').remove();
			}	
			if ($('.mwplayer_interface').length) {
				$('.mwplayer_interface').remove();
			}	
			if ($('.mv-player').length) {
				$('.mv-player').remove();
			}
			if ($('.nativeEmbedPlayerPid').length) {
				$('.nativeEmbedPlayerPid').remove();
			}			
			if ($('#thevideo').length) {
				$('#thevideo').remove();	
			}
			if ($('#floatWinPowerPole #videoplayer').length) {
				$('#floatWinPowerPole #videoplayer').empty();	
			}	

			if ($('#floatWinMinnKotaVideo #videoplayer').length) {
				$('#floatWinMinnKotaVideo #videoplayer').empty();	
			}
			
			if ($('#floatWinEvinrude #videoplayer').length) {
				$('#floatWinEvinrude #videoplayer').empty();	
			}			
		});
		
		// Create overlay floating buttons for windows that require them
		$(".landingFloatWin.showButton").each(function() {
			var selBtn = $("#"+$(this).attr("id").replace("floatWin", "floatBtn"));
			var selWin = $(this);
			var selBase = (model == "Z520" ? "left" : "right");
			var selBaseX = (selWin.attr("id") == "floatWinEvinrude" ? "left" : selBase);
			var newCSS = {};
			newCSS[selBaseX] = Math.abs(parseInt(selBtn.css(selBase))-parseInt(selWin.css(selBaseX))).toString()+"px";
			newCSS["top"] = Math.abs(parseInt(selBtn.css("top"))-parseInt(selWin.css("top"))).toString()+"px";
			selBtn.clone().attr({
				"class": "landingFloatBtnOver",
				"id": selWin.attr("id").replace("floatWin", "floatBtnOver")
			}).css(newCSS).click(function() {
				if (selWin.hasClass("fullScreen")) {
					selWin.children(".closebtn").click();
				} else {
					selWin.fadeOut(800);
				}
			}).appendTo(selWin);
		});
		
		$(".landingFloatWinContent .thumbs a").click(function () {
			var vidpath = $(this).attr('rel');
			//var vidhtml = 'insert video code here. Video path: ' + vidpath;
			//$('#floatWinVideo #floatWinVideoContent').html(vidhtml);		
			var flashvars = {};
			flashvars.autoPlay = "true";
			flashvars.entryId = vidpath;
			flashvars.sourceType = "entryId";
			flashvars.widgetId = "_100";
			flashvars.partnerId = "100";
			flashvars.host = "media.pbhmarinegroup.com";
			flashvars.externalInterfaceDisabled = "false";
			var params = {};
			params.quality = "best";
			params.wmode = "opaque";
			params.allowfullscreen = "true";
			params.allowscriptaccess = "always";
			
			var attributes = {};
			attributes.id = "evinrudevideo";
			attributes.name = "evinrudevideo";
			attributes.styleclass = "player";
			swfobject.embedSWF("http://media.pbhmarinegroup.com/index.php/kwidget/cache_st/1322069743/wid/_100/uiconf_id/4421531/", "evinrudevideo", "640", "386", "10.0.0", "js/expressInstall.swf", flashvars, params, attributes);		
		});		
		
		// Bind onclick event to window openers
		$("#floatWinMore a, #floatBtnMinnKotaVideo").attr("href", "javascript:void(0);");
		$(".landingFloatBtn, #floatWinMore a, #floatBtnMinnKotaVideo").click(function() {
			var selWin = $("#"+$(this).attr("id").replace("floatBtn", "floatWin"));
			
			$(".landingFloatWin").fadeOut(800);
			selWin.fadeIn(800);
			
			if (selWin.hasClass("fullScreen")) {
				bgSlideshow.hide();
				$(".landingFloatBtn, #landingModLogo").fadeOut(800);
			}
			if ($(this).attr("id") == "floatBtnPowerPole") {
				$("#floatWinPowerPole #videoplayer").append('<object id="ppvideo" name="ppvideo" type="application\/x-shockwave-flash" allowFullScreen="true" allowNetworking="all" allowScriptAccess="always" height="386" width="640" bgcolor="#000000" xmlns:dc="http:\/\/purl.org\/dc\/terms\/" xmlns:media="http:\/\/search.yahoo.com\/searchmonkey\/media\/" rel="media:video" resource="http:\/\/media.pbhmarinegroup.com\/index.php\/kwidget\/cache_st\/1322708200\/wid\/_100\/uiconf_id\/4421531\/entry_id\/0_6wf9mpak" data="http:\/\/media.pbhmarinegroup.com\/index.php\/kwidget\/cache_st\/1322708200\/wid\/_100\/uiconf_id\/4421531\/entry_id\/0_6wf9mpak"><param name="allowFullScreen" value="true" \/><param name="allowNetworking" value="all" \/><param name="allowScriptAccess" value="always" \/><param name="bgcolor" value="#000000" \/><param name="flashVars" value="&{FLAVOR}" \/><param name="movie" value="http:\/\/media.pbhmarinegroup.com\/index.php\/kwidget\/cache_st\/1322708200\/wid\/_100\/uiconf_id\/4421531\/entry_id\/0_6wf9mpak" \/><a rel="media:thumbnail" href="http:\/\/media.pbhmarinegroup.com\/p\/100\/sp\/10000\/thumbnail\/entry_id\/0_6wf9mpak\/width\/120\/height\/90\/bgcolor\/000000\/type\/2"><\/a> <span property="dc:description" content=""><\/span><span property="media:title" content="Power-Pole Shortcast.mp4"><\/span> <span property="media:width" content="640"><\/span><span property="media:height" content="386"><\/span> <span property="media:type" content="application\/x-shockwave-flash"><\/span> <\/object>');
			}
			else if (($(this).attr("id") == "floatBtnMinnKota")) {
				$("#floatWinMinnKotaVideo #videoplayer").append('<object id="mkvideo" name="mkvideo" type="application\/x-shockwave-flash" allowFullScreen="true" allowNetworking="all" allowScriptAccess="always" height="386" width="640" bgcolor="#000000" xmlns:dc="http:\/\/purl.org\/dc\/terms\/" xmlns:media="http:\/\/search.yahoo.com\/searchmonkey\/media\/" rel="media:video" resource="http:\/\/media.pbhmarinegroup.com\/index.php\/kwidget\/cache_st\/1322706610\/wid\/_100\/uiconf_id\/4421531\/entry_id\/0_isl6ulbj" data="http:\/\/media.pbhmarinegroup.com\/index.php\/kwidget\/cache_st\/1322706610\/wid\/_100\/uiconf_id\/4421531\/entry_id\/0_isl6ulbj"><param name="allowFullScreen" value="true" \/><param name="allowNetworking" value="all" \/><param name="allowScriptAccess" value="always" \/><param name="bgcolor" value="#000000" \/><param name="flashVars" value="&{FLAVOR}" \/><param name="movie" value="http:\/\/media.pbhmarinegroup.com\/index.php\/kwidget\/cache_st\/1322706610\/wid\/_100\/uiconf_id\/4421531\/entry_id\/0_isl6ulbj" \/><a rel="media:thumbnail" href="http:\/\/media.pbhmarinegroup.com\/p\/100\/sp\/10000\/thumbnail\/entry_id\/0_isl6ulbj\/width\/120\/height\/90\/bgcolor\/000000\/type\/2"><\/a> <span property="dc:description" content=""><\/span><span property="media:title" content="MinnKota Trolling Motor.mp4"><\/span> <span property="media:width" content="640"><\/span><span property="media:height" content="386"><\/span> <span property="media:type" content="application\/x-shockwave-flash"><\/span> <\/object>');
			}
			else if (($(this).attr("id") == "floatBtnEvinrude")) {
				$("#floatWinEvinrude .landingFloatWinContent .tab #videoplayer").append('<object id="evinrudevideo" name="evinrudevideo" type="application\/x-shockwave-flash" allowFullScreen="true" allowNetworking="all" allowScriptAccess="always" height="386" width="640" bgcolor="#000000" xmlns:dc="http:\/\/purl.org\/dc\/terms\/" xmlns:media="http:\/\/search.yahoo.com\/searchmonkey\/media\/" rel="media:video" resource="http:\/\/media.pbhmarinegroup.com\/index.php\/kwidget\/cache_st\/1322708944\/wid\/_100\/uiconf_id\/4421531\/entry_id\/0_7gf3vzfo" data="http:\/\/media.pbhmarinegroup.com\/index.php\/kwidget\/cache_st\/1322708944\/wid\/_100\/uiconf_id\/4421531\/entry_id\/0_7gf3vzfo"><param name="allowFullScreen" value="true" \/><param name="allowNetworking" value="all" \/><param name="allowScriptAccess" value="always" \/><param name="bgcolor" value="#000000" \/><param name="flashVars" value="&{FLAVOR}" \/><param name="movie" value="http:\/\/media.pbhmarinegroup.com\/index.php\/kwidget\/cache_st\/1322708944\/wid\/_100\/uiconf_id\/4421531\/entry_id\/0_7gf3vzfo" \/><a href="http:\/\/corp.kaltura.com">video platform<\/a> <a href="http:\/\/corp.kaltura.com\/video_platform\/video_management">video management<\/a> <a href="http:\/\/corp.kaltura.com\/solutions\/video_solution">video solutions<\/a> <a href="http:\/\/corp.kaltura.com\/video_platform\/video_publishing">video player<\/a> <a rel="media:thumbnail" href="http:\/\/media.pbhmarinegroup.com\/p\/100\/sp\/10000\/thumbnail\/entry_id\/0_7gf3vzfo\/width\/120\/height\/90\/bgcolor\/000000\/type\/2"><\/a> <span property="dc:description" content=""><\/span><span property="media:title" content="Evinrude E-TEC Engine.mp4"><\/span> <span property="media:width" content="640"><\/span><span property="media:height" content="386"><\/span> <span property="media:type" content="application\/x-shockwave-flash"><\/span> <\/object>');
			}
		});
		
		// Set up floating window sidebars
		$(".landingFloatWinSidebar").each(function() {
			var skipped = 0;
			$(this).children("a").each(function(index) {
				var newIndex = index - skipped;
				if (!$(this).attr("href") || $(this).attr("href") == "javascript:void(0);") {
					$(this).attr("href", "javascript:void(0);").click(function(){
						$(this).siblings("a").removeClass("selected");
						$(this).addClass("selected");
						$(this).parent().siblings(".landingFloatWinContent").children(".tab").hide().slice(newIndex, newIndex + 1).show();
					});
					if (index == 0) $(this).click();
				} else {
					skipped ++;
				}
			});
		});
		
		// Bind onclick event to Gallery tabs and close button
		$("#floatWinGalleryHead a").click(function() {
			newTab = $(this).attr("id").replace("galleryTab", "");
			$("#floatWinGalleryHead a").removeClass("selected");
			$(".galleryPage").hide();
			$(this).addClass("selected");
			if (newTab != "Video") {
				$("#galleryTabPhoto").addClass("selected");
			}
			if (newTab == "Photo") {
				$("#galleryTabExterior").addClass("selected");
				$("#galleryPageExterior").show();
			} else {
				$("#galleryPage"+newTab).show();
			}
		});
		$("#gallerySlideClose").click(function() {
			extSlideshow.hide();
			intSlideshow.hide();
			bgSlideshow.show();
		});
		
		// Add glow and shadow to Trailer dots and bind mouseover event
		$("#floatWinTrailer .trailerDots a").attr("href", "javascript:void(0);").each(function(index) {
			$(this).bind("mouseover mouseout", function() {
				$("#floatWinTrailer .trailerBlurbs div").slice(index, index+1).toggle();
			});
		}).append("<span class=\"glow\"></span><span class=\"shadow\"></span>");
		
		// Load up background slideshow
		bgSlideshow = new slideshow({
			primary: "#background img",
			secondary: "#backgroundFade img",
			indicatorDiv: "#bgIndicator",
			indicatorIcoPrefix: "bgInd",
			imgPath: "images/[model]/landing/[model]_home[number].jpg",
			autoPlay: true,
			slideDelay: 8000
		});
		
		// Load up exterior images slideshow
		extSlideshow = new slideshow({
			primary: "#gallerySlide",
			secondary: "#gallerySlideFade",
			thumbs: "#galleryPageExterior .thumbs",
			thumbPrefix: "thumbExt",
			prevButton: "#gallerySlidePrev",
			nextButton: "#gallerySlideNext",
			imgPath: "images/[model]/exterior/[model]_exterior_[number].jpg",
			autoPlay: false,
			slideDelay: 8000,
			startHidden: true,
			include: "#gallerySlideControls, #gallerySlideClose",
			exclude: ".landingFloatBtn, #floatWinGallery"
		});
		
		// Load up interior images slideshow
		intSlideshow = new slideshow({
			primary: "#gallerySlide",
			secondary: "#gallerySlideFade",
			thumbs: "#galleryPageInterior .thumbs",
			thumbPrefix: "thumbInt",
			prevButton: "#gallerySlidePrev",
			nextButton: "#gallerySlideNext",
			imgPath: "images/[model]/interior/[model]_interior_[number].jpg",
			autoPlay: false,
			slideDelay: 8000,
			startHidden: true,
			include: "#gallerySlideControls, #gallerySlideClose",
			exclude: ".landingFloatBtn, #floatWinGallery"
		});
		
		// Ensure background always fills the window
		$(window).resize(function() {
			$("#background img, #backgroundFade img, #absBackground img").each(function() {
				$(this).css("margin-left", "-"+($(this).width() / 2)+"px");
				if ($(this).width() / $(this).height() >= $(window).width() / $(window).height()) {
					$(this).css({"width": "auto", "height": "100%"});
				} else {
					$(this).css({"width": "100%", "height": "auto"});
				}
			});
		});
		
	}
	
	// Fix stupid IE bugs
	if ($.browser.msie) {
		$("a span").mouseover(function() {
			$(this).closest("a").addClass("hover");
		}).mouseout(function() {
			$(this).closest("a").removeClass("hover");
		});
	}
	
});

 


// SLIDESHOW PROTOTYPE
// When instantiating this object, the following options are available:
//
//  Required:
//     primary:              A jQuery-style selector for the main img element to contain the slides.
//     secondary:            A jQuery-style selector for an img element identical to the primary, used for fading between slides.
//     imgPath:              The path and filename pattern for the images in the slideshow. Use [model] for any place the model name appears, and [number] for the image number.
//
//  Optional:
//     thumbs:               If populated with a jQuery-style selector, that element will be filled with thumbnails as the images are loaded.
//     thumbPrefix:          Required if using thumbs. A prefix to use for the ID attributes on thumbnails.
//     indicatorDiv:         A jQuery-style selector for a div to contain an indicator of which slide is currently showing (the little dots in the corner).
//     indicatorIcoPrefix:   Required if using indicatorDiv. A prefix to use for the ID attributes on the indicator icons.
//     prevButton:           A jQuery-style selector for an element to use as a Previous button.
//     nextButton:           A jQuery-style selector for an element to use as a Next button.
//     autoPlay:             Boolean value indicating whether or not the slides should advance automatically. Default is false.
//     slideDelay:           Required if autoPlay=true. Delay between slide transitions.
//     currentImg:           Numeric value of image to display first. Default is 1.
//     fadeDuration:         Number of milliseconds it takes to fade from one slide to the next. Default is 1000.
//     startHidden:          Boolean indicating whether or not the slideshow is hidden when the page is loaded. Default is false.
//     include:              A jQuery-style selector for any extra elements that should be shown and hidden along with the slideshow.
//     exclude:              A jQuery-style selector for any elements that should be hidden while the slideshow is shown.

var slideshows = new Array();
function slideshow(options) {
	this.primary = $(options.primary);
	this.secondary = $(options.secondary);
	this.thumbs = (options.thumbs ? $(options.thumbs) : false);
	this.thumbPrefix = options.thumbPrefix;
	this.indicator = (options.indicatorDiv ? $(options.indicatorDiv) : false);
	this.indPrefix = options.indicatorIcoPrefix;
	this.path = options.imgPath.replace(/\[model\]/g, model);
	this.auto = (options.autoPlay ? true : false);
	this.current = (options.currentImg ? options.currentImg : 1);
	this.delay = options.slideDelay;
	this.fadeDuration = (options.fadeDuration ? options.fadeDuration : 1000);
	this.hidden = (options.startHidden ? true : false);
	this.include = options.include;
	this.exclude = options.exclude;
	this.loaded = false;
	this.fading = false;
	this.timer = null;
	if (this.hidden) {
		this.primary.hide();
		this.secondary.hide();
	}
	this.show = function(cycleTo) {
		$('#background').show();
		if (!this.hidden) return;
		if (cycleTo) {
			this.primary.attr("src", this.preloadImages[cycleTo].src);
			this.secondary.attr("src", this.preloadImages[cycleTo].src);
			this.current = parseInt(cycleTo) + 1;
		}
		if (options.prevButton) $(options.prevButton).click($.proxy(function() {this.cycleTo(this.current - 2);}, this));
		if (options.nextButton) $(options.nextButton).click($.proxy(function() {this.cycleTo(this.current);}, this));
		
		
		if (this.include) $(this.include).fadeIn(this.fadeDuration);
		if (this.exclude) $(this.exclude).fadeOut(this.fadeDuration);
		if (this.indicator) $(this.indicator).fadeIn(this.fadeDuration);
		this.secondary.fadeIn(this.fadeDuration, $.proxy(function() {
			if (this.auto) this.cycle();
		}, this));
		/*
		$(this.include).show();
		$(this.exclude).hide();
		$(this.indicator).show();
		this.secondary.show()
		if (this.auto) this.cycle();
		*/
		this.hidden = false;
	};
	this.hide = function() {
		if (this.hidden) return;
		if (this.fading) {
			setTimeout($.proxy(this.hide, this), this.fadeDuration);
			return;
		}
		this.hidden = true;
		clearTimeout(this.timer);
		this.primary.hide();
		/*		
		this.secondary.fadeOut(this.fadeDuration);
		if (this.include) $(this.include).fadeOut(this.fadeDuration);
		if (this.exclude) $(this.exclude).fadeIn(this.fadeDuration);
		if (this.indicator) $(this.indicator).fadeOut(this.fadeDuration);
		*/
		this.secondary.hide();
		$(this.include).hide();
		$(this.exclude).show();
		$(this.indicator).hide();

		$('#background').hide();
	};
	this.cycle = function() {
		if (!this.preloadImages[this.current]) {
			if (this.loaded) {
				this.current = 1;
			} else {
				setTimeout($.proxy(this.cycle, this), 500);
				return;
			}
		}
		this.fading = true;
		this.primary.show();
		this.secondary.attr("src", this.preloadImages[this.current].src);
		if (this.indicator) {
			this.indicator.children("a").removeClass("selected");
			$("#"+this.indPrefix+this.current).addClass("selected");
		}
		this.primary.fadeOut(this.fadeDuration, $.proxy(function() {
			this.primary.attr("src", this.preloadImages[this.current].src);
			this.current ++;
			if (this.auto) this.timer = setTimeout($.proxy(this.cycle, this), this.delay);
			this.fading = false;
		}, this));
	};
	this.cycleFromInd = function(element) {
		this.cycleTo(parseInt($(element).attr("id").replace(this.indPrefix, "")));
	};
	this.cycleTo = function(number) {
		if (this.fading) return;
		clearTimeout(this.timer);
		this.current = (number < 1 ? this.preloadImages.length - 1 : number);
		this.cycle();
	};
	this.preloadImages = new Array();
	this.preloadIndex = 1;
	this.preload = function() {
		var newImage = new Image();
		newImage.onload = $.proxy(function() {
			if (this.thumbs) this.thumbs.append($("<a>").attr({
				"id": this.thumbPrefix+this.preloadIndex,
				"class": "thumb",
				"href": "javascript:void(0);"
			}).click(this, function(e) {
				$.each(slideshows, function(key, val) {
					val.hide();
				});
				e.data.show($(this).attr("id").replace(e.data.thumbPrefix, ""));
			}).append($("<img>").attr("src", newImage.src)));
			if (this.indicator) this.indicator.append($("<a>").attr({
				"id": this.indPrefix+this.preloadIndex,
				"href": "javascript:void(0);"
			}).toggleClass("selected", this.preloadIndex == 1).click(this, function(e) {
				e.data.cycleFromInd(this);
			}));
			if (this.preloadIndex == 1) {
				this.primary.attr("src", newImage.src);
				this.secondary.attr("src", newImage.src);
			}
			this.preloadImages[this.preloadIndex] = newImage;
			this.preloadIndex ++;
			this.preload();
		}, this);
		newImage.onerror = $.proxy(function() {
			this.loaded = true;
		}, this);
		newImage.src = this.path.replace("[number]", this.preloadIndex);
	};
	this.preload();
	
	if (this.auto) this.cycle();
	slideshows.push(this);
}


