// JavaScript Document

var currentProductID = "SG_QBPREMIER2010ACCOUNTANT_1_4";
var currentProduct = "";
var currentProductName = "";
var currentEdition = "";

$(function() {
	
	$('#products').hide();
	
	$('#prod_selector_header_select a')
		.click(function(event){
			currentProductID = "";
			currentProduct = "";
			currentProductName = "";
			currentEdition = "";
			$('#prod_selector_content_shell').slideDown();
			$('#first_column, #second_column, #third_column').show();
			return false;
	});
	

	
	$('#products li:has(ul)').not('[class=prod_edition]').appendTo('#first_column');
	
	$('#first_column li:has(ul)')
		.children().hide().end()
		.click(function(event){
			// turn background color of all li siblings white
			$(this).siblings().css('background-color','#ffffff');
			// check if li goes to external page, if yes load that page in the current window
			if ($(this).is('[name=external]')) {
				window.open(this.childNodes[1].href,"_self");
				return false;
			}	
		
		
			// check if li has title attribute of prod_name (level 1), if yes, always put children in second column
			if ($(this).is('[class=prod_name]')) {
				$('#second_column, #third_column').empty();
				if (this == event.target) {
						currentProductName = this.id;
						currentProduct = this.id + " ";
						$(this)
							.css('list-style','none')
							.css('background-color','#fff3ce');
							$('#second_column').empty();
							if ($(this).children().is('[title=editions]')) {
								$('#second_column').html("<span class=\"prod_title\">Edition</span><br /><br />");
//								$('#second_column').append(currentProductName);
							} else {
								$('#second_column').html("<span class=\"prod_title\">Version</span><br /><br />");
//								$('#second_column').append(currentProduct);
							}
							event.target = null;
							var $myClone = $(this).children().clone();
							$myClone.appendTo('#second_column').fadeIn();
							$('#second_column li:has(ul)')
							.click(function(event){  // else put li's children in third column
								if (this == event.target) {
									currentEdition = this.id + " ";
									$(this).css('background-color','#fff3ce');
									$(this).siblings().css('background-color','#ffffff');
									$('#third_column').html("<span class=\"prod_title\">Version</span><br /><br />");
//									$('#third_column').append(currentProduct);
									event.target = null;
									var $thirdClone = $(this).children().clone();
									$thirdClone.appendTo('#third_column').fadeIn();
									$('#third_column li:not(:has(ul))')
										.css({'list-style':'none', cursor : 'pointer'})
										.click(function(event){  // else put li's children in third column
											if (this == event.target) {
												// check if li goes to external page, if yes load that page in the current window
												if ($(this).is('[name=external]')) {
													window.open(this.childNodes[1].href,"_self");
													return false;
												}
												currentProduct = currentProduct + currentEdition + this.title + " ";
												currentProductID = this.id;
												$('#first_column li').css('background-color','#ffffff');
												$('#first_column').hide();
												$('#second_column, #third_column').empty().hide();
												$('#prod_selector_content_shell').slideUp();
												$('#prod_selector_header_image').css("background-image", getHeader(currentProductName));
												$('#prod_selector_header_image .product_full').text(currentProduct);
												$('#prod_selector_header_select a').css("background-image","url(/images/selector/pgHead_tabclick_changeproduct.gif)");
											}
											return false;
										});	 // ends third column li (versions) click handler
								}
							return false;
							}); // ends second column li with children (editions) click handler
							$('#second_column li:not(:has(ul))')
							.css({'list-style':'none', cursor : 'pointer'})
							.click(function(event){  // else put li's children in third column
								if (this == event.target) {
									// check if li goes to external page, if yes load that page in the current window
									if ($(this).is('[name=external]')) {
										window.open(this.childNodes[1].href,"_self");
									return false;
									}
									currentProduct = currentProduct + this.title + " ";
									currentProductID = this.id;
									$('#first_column li').css('background-color','#ffffff');
									$('#first_column').hide();
									$('#second_column').html(" ");
									$('#second_column, #third_column').hide();
									$('#prod_selector_content_shell').slideUp();
									$('#prod_selector_header_image').css("background-image", getHeader(currentProductName));
									$('#prod_selector_header_image .product_full').text(currentProduct);
									$('#prod_selector_header_select a').css("background-image","url(/images/selector/pgHead_tabclick_changeproduct.gif)");

								}
							return false;
							}); // ends second column li without children (versions) click handler					
							
				} // close if this == event.target
			} // close if title=prod_name
			return false;	
			})
		.css('cursor','pointer');


	
});



function getHeader (name) {
	
	switch (name) {
		case "Simple Start Edition":
			return "url(/images/selector/pageHeaderQBgreen.jpg)";
		case "Pro Edition":
			return "url(/images/selector/pageHeaderQBgreen.jpg)";
		case "for Mac":
			return "url(/images/selector/pageHeaderQBgreen.jpg)";
		case "Premier":
			return "url(/images/selector/pageHeaderQBgreen.jpg)";
		case "Enterprise Solutions":
			return "url(/images/selector/pageHeaderEntLegacy.jpg)";
		case "Intuit Statement Writer":
			return "url(/images/selector//pageHeaderOnline.jpg)";
		case "Point of Sale":
			return "url(/images/selector/pageHeaderQBgreen.jpg)";
		case "Cash Register Plus":
			return "url(/images/selector/pageHeaderQBgreen.jpg)";
		case "Payroll":
			return "url(/images/selector/pageHeaderQBgreen.jpg)";
		case "Quickbooks Online Basic or Online Plus":
			return "url(/images/selector/pageHeaderQBgreen.jpg)";
		case "Customer Manager":
			return "url(/images/selector/pageHeaderQBgreen.jpg)";
		case "Other Products":
			return "url(/images/selector/pageHeaderQBgreen.jpg)";
		case "Customer Service":
			return "url(/images/selector/pageHeaderQBgreen.jpg)";
		break;
	}
}