﻿// JavaScript Document
var $ov = jQuery.noConflict();

$ov(document).ready(function(){
	model13_nav_bind_events();
	model13_nav_dom_inserts();
});

function model13_nav_bind_events(){
	$ov('.model13_nav_tier1_li').mouseenter(model13_nav_tier1_li_MOUSE_ENTER);
	$ov('.model13_nav_tier1_li').mouseleave(model13_nav_tier1_li_MOUSE_LEAVE);
	$ov('.model13_nav_tier2_li').mouseenter(model13_nav_tier2_li_MOUSE_ENTER);
	$ov('.model13_nav_tier2_li').mouseleave(model13_nav_tier2_li_MOUSE_LEAVE);
	$ov('.model13_nav_tier2_a').mouseenter(model13_nav_tier2_a_MOUSE_ENTER);
	$ov('.model13_nav_tier1_a').mouseenter(model13_nav_tier1_a_MOUSE_ENTER);
	$ov('.model13_nav_tier3_a').mouseenter(model13_nav_tier3_a_MOUSE_ENTER);
	$ov('.model13_nav_tier3_a').mouseleave(model13_nav_tier3_a_MOUSE_LEAVE);
}

function model13_nav_dom_inserts(){
	if(browserCheck(8)){
				$ov('.model13_nav_tier1_a').before(model13_nav_tier1_li_cap);
		
		var model13_nav_tier1_li_corner_img = '';
		$ov('.model13_nav_tier2_ul').after(model13_nav_tier1_li_corner_img);
	}else{
		$ov('.model13_nav_tier2_a').width(12);
	}
	
	var model13_nav_tier1_li_divider = '';
	$ov('.model13_nav_tier1_li:not(:last-child)').after(model13_nav_tier1_li_divider);
	
	var model13_nav_tier1_ul_cap_left = '';
	$ov('.model13_nav_tier1_li:first-child').before(model13_nav_tier1_ul_cap_left);
	
	var model13_nav_tier1_ul_cap_right = '';
	$ov('.model13_nav_tier1_li:last-child').before(model13_nav_tier1_ul_cap_right);
}

function model13_nav_tier2_li_MOUSE_ENTER(){
	var myWidth = $ov(this).parent().width();
	$ov('.model13_nav_tier3_ul', this).css("left", myWidth);
	var numChildren = $ov('.model13_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(".model13_nav_tier3_a").css("width"));
	childWidth += parseInt($ov(".model13_nav_tier3_li").css("padding-right"));
	childWidth += 2; //borders must be entered manually
	var finalWidth = childWidth * colWidth;
	//var offsetHeight = $ov(this).index() * 10;
	$ov('.model13_nav_tier3_ul', this).css({width: finalWidth});
	$ov('.model13_nav_tier3_ul', this).stop(true, true);
	$ov('.model13_nav_tier3_ul', this).fadeIn("fast");
	
	// Added below
	$ov(".model13_nav_tier3_img", this).each(function(index){
		var newSource = $ov(this).attr("imageSrc");
		//alert(newSource);
		$ov(this).attr("src", newSource);
	});
	//
	
}

function model13_nav_tier2_li_MOUSE_LEAVE(){
	$ov('.model13_nav_tier3_ul', this).stop(true, true);
	$ov('.model13_nav_tier3_ul', this).fadeOut("fast");
}

function model13_nav_tier1_li_MOUSE_ENTER(){
	$ov('#topNavDiv').css({zIndex: 1000});
	$ov('.model13_nav_tier1_a', this).addClass('model13_nav_tier1_a_hover');
	$ov('.model13_nav_tier1_li_cap', this).show();
	$ov('.model13_nav_tier1_li_corner_img', this).show();
	$ov('.model13_nav_tier2_ul', this).stop(true, true);
	if($ov('.model13_nav_tier2_ul', this).children().length){
		$ov('.model13_nav_tier2_ul', this).fadeIn("fast");
	}
}

function model13_nav_tier1_li_MOUSE_LEAVE(){
	$ov('#topNavDiv').css({zIndex: 5});
	$ov('.model13_nav_tier1_a', this).removeClass('model13_nav_tier1_a_hover');
	$ov('.model13_nav_tier1_li_cap', this).hide();
	$ov('.model13_nav_tier1_li_corner_img', this).hide();
	$ov('.model13_nav_tier2_ul', this).stop(true, true);
	$ov('.model13_nav_tier2_ul', this).fadeOut("fast");
}

function model13_nav_tier2_a_MOUSE_ENTER(){
	$ov(".model13_nav_tier2_a").removeClass("model13_nav_tier2_a_hover");
	$ov(this).addClass('model13_nav_tier2_a_hover');
}

function model13_nav_tier1_a_MOUSE_ENTER(){
	$ov(".model13_nav_tier2_a").removeClass("model13_nav_tier2_a_hover");
}

function model13_nav_tier3_a_MOUSE_ENTER(){
	$ov(this).addClass('model13_nav_tier3_a_hover');
}

function model13_nav_tier3_a_MOUSE_LEAVE(){
	$ov(this).removeClass('model13_nav_tier3_a_hover');
}

function browserCheck(ieVersion){
	if($ov.browser.msie && $ov.browser.version < ieVersion){
		return false;
	}else{
		return true;
	}
}
