﻿// JavaScript Document
var $ov = jQuery.noConflict();

$ov(document).ready(function(){
	model_nav_bind_events();
	model_nav_dom_inserts();
	
	//ose_change_quote('contact a dealer');
});



//This Function is used to change the OSE Quote word - being used 
//     for optimizing said OSE control....
function ose_change_quote(newText){
	$ov("div:.oseOff span").each(function(index, value) {
		if ($ov(this).html() == 'quote')
		{
		    $ov(this).text(newText);
		    
		    if (newText.length > 10)
		    {
			    $ov(this).parent().css('line-height', '20px');
			    //$ov(this).parent().css('padding-left', '30px');
			    //$ov(this).parent().css('width', '145px');
			    //$ov(this).parent().css('font-size', '18px');

				//$ov("div:.oseOff").css('padding-left', '25px');
				//$ov("div:.oseOff").css('width', '145px');
				//$ov("div:.oseOn").css('padding-left', '25px');
				//$ov("div:.oseOn").css('width', '145px');

				//$ov("li:.oseHead").css('backgroundPosition', '3px 0px');
				//$ov("li:.oseFoot").css('backgroundPosition', '3px 0px');
		    }
		}
	});
}


function model_nav_bind_events(){
	$ov('.model_nav_tier1_li').mouseenter(model_nav_tier1_li_MOUSE_ENTER);
	$ov('.model_nav_tier1_li').mouseleave(model_nav_tier1_li_MOUSE_LEAVE);
	$ov('.model_nav_tier2_li').mouseenter(model_nav_tier2_li_MOUSE_ENTER);
	$ov('.model_nav_tier2_li').mouseleave(model_nav_tier2_li_MOUSE_LEAVE);
	$ov('.model_nav_tier2_a').mouseenter(model_nav_tier2_a_MOUSE_ENTER);
	$ov('.model_nav_tier1_a').mouseenter(model_nav_tier1_a_MOUSE_ENTER);
	$ov('.model_nav_tier3_a').mouseenter(model_nav_tier3_a_MOUSE_ENTER);
	$ov('.model_nav_tier3_a').mouseleave(model_nav_tier3_a_MOUSE_LEAVE);
}

function model_nav_dom_inserts(){
	if(browserCheck(8)){
		var model_nav_tier1_li_cap = '<div class="model_nav_tier1_li_cap">';
        model_nav_tier1_li_cap += '<img src="/Style%20Library/Polaris/ORV/2011/model_nav_tier1_li_cap_img.png" class="model_nav_tier1_li_cap_img" height="5" width="5" />';
        model_nav_tier1_li_cap += '</div>';
		$ov('.model_nav_tier1_a').before(model_nav_tier1_li_cap);
		
		var model_nav_tier1_li_corner_img = '<img src="/Style%20Library/Polaris/ORV/2011/model_nav_tier1_li_corner_img.png" class="model_nav_tier1_li_corner_img" height="9" width="9" />';
		$ov('.model_nav_tier2_ul').after(model_nav_tier1_li_corner_img);
	}else{
		$ov('.model_nav_tier2_a').width(195);
	}
	
	var model_nav_tier1_li_divider = '<img src="/Style%20Library/Polaris/ORV/2011/model_nav_tier1_li_divider.gif" height="8" width="4" class="model_nav_tier1_li_divider" />';
	$ov('.model_nav_tier1_li:not(:last-child)').after(model_nav_tier1_li_divider);
	
	var model_nav_tier1_ul_cap_left = '<img src="/Style%20Library/Polaris/ORV/2011/model_nav_tier1_ul_cap_left.png" height="32" width="32" class="model_nav_tier1_ul_cap_left" />';
	$ov('.model_nav_tier1_li:first-child').before(model_nav_tier1_ul_cap_left);
	
	var model_nav_tier1_ul_cap_right = '<img src="/Style%20Library/Polaris/ORV/2011/model_nav_tier1_ul_cap_right.png" height="32" width="32" class="model_nav_tier1_ul_cap_right" />';
	$ov('.model_nav_tier1_li:last-child').before(model_nav_tier1_ul_cap_right);
}

function model_nav_tier2_li_MOUSE_ENTER(){
	var myWidth = $ov(this).parent().width();
	$ov('.model_nav_tier3_ul', this).css("left", myWidth);
	var numChildren = $ov('.model_nav_tier3_ul', this).children().length;
	var colWidth = 3;
	var colHeight = 1;
	switch(numChildren){
		case 1:
			colWidth = 1;
			break;
		case 2:
			colWidth = 2;
			break;
		case 3:
			colWidth = 3;
			break;
		case 4:
			colWidth = 2;
			break;
		case 5:
			colWidth = 3;
			break;
		case 6:
			colWidth = 3;
			break;
		case 7:
			colWidth = 3;
			break;
		case 8:
			colWidth = 3;
			break;
		case 9:
			colWidth = 3;
			break;
		default:
			colWidth = 3;
			break;
	}
	var childWidth = parseInt($ov(".model_nav_tier3_a").css("width"));
	childWidth += parseInt($ov(".model_nav_tier3_li").css("padding-right"));
	childWidth += 2; //borders must be entered manually
	var finalWidth = childWidth * colWidth;
	//var offsetHeight = $ov(this).index() * 10;
	$ov('.model_nav_tier3_ul', this).css({width: finalWidth});
	$ov('.model_nav_tier3_ul', this).stop(true, true);
	$ov('.model_nav_tier3_ul', this).fadeIn("fast");
	
	// Added below
	$ov(".model_nav_tier3_img", this).each(function(index){
		var newSource = $ov(this).attr("imageSrc");
		//alert(newSource);
		$ov(this).attr("src", newSource);
	});
	//
	
}

function model_nav_tier2_li_MOUSE_LEAVE(){
	$ov('.model_nav_tier3_ul', this).stop(true, true);
	$ov('.model_nav_tier3_ul', this).fadeOut("fast");
}

function model_nav_tier1_li_MOUSE_ENTER(){
	$ov('#topNavDiv').css({zIndex: 1000});
	$ov('.model_nav_tier1_a', this).addClass('model_nav_tier1_a_hover');
	$ov('.model_nav_tier1_li_cap', this).show();
	$ov('.model_nav_tier1_li_corner_img', this).show();
	$ov('.model_nav_tier2_ul', this).stop(true, true);
	if($ov('.model_nav_tier2_ul', this).children().length){
		$ov('.model_nav_tier2_ul', this).fadeIn("fast");
	}
}

function model_nav_tier1_li_MOUSE_LEAVE(){
	$ov('#topNavDiv').css({zIndex: 5});
	$ov('.model_nav_tier1_a', this).removeClass('model_nav_tier1_a_hover');
	$ov('.model_nav_tier1_li_cap', this).hide();
	$ov('.model_nav_tier1_li_corner_img', this).hide();
	$ov('.model_nav_tier2_ul', this).stop(true, true);
	$ov('.model_nav_tier2_ul', this).fadeOut("fast");
}

function model_nav_tier2_a_MOUSE_ENTER(){
	$ov(".model_nav_tier2_a").removeClass("model_nav_tier2_a_hover");
	$ov(this).addClass('model_nav_tier2_a_hover');
}

function model_nav_tier1_a_MOUSE_ENTER(){
	$ov(".model_nav_tier2_a").removeClass("model_nav_tier2_a_hover");
}

function model_nav_tier3_a_MOUSE_ENTER(){
	$ov(this).addClass('model_nav_tier3_a_hover');
}

function model_nav_tier3_a_MOUSE_LEAVE(){
	$ov(this).removeClass('model_nav_tier3_a_hover');
}

function browserCheck(ieVersion){
	if($ov.browser.msie && $ov.browser.version < ieVersion){
		return false;
	}else{
		return true;
	}
}
