/*****************************************************************************************************
*********	details/master.js -- javascript functions commonly used on details page only
*************************************************************************************************** */

function changeTab(activeTab) {

	var tabs = new Array("vsSpecs", "vsOptions", "vsExterior", "vsInterior", "vsMechanical", "vsTech", "vsInstalled");
	for (tab in tabs) {
		if (activeTab != tabs[tab]) {
			document.getElementById(tabs[tab] + 'Tab').className = activeTab + 'TabOff';
			document.getElementById(tabs[tab] + 'Content').style.display = 'none';
		}
		else {
			document.getElementById(tabs[tab] + 'Tab').className = activeTab + 'TabOn';
			document.getElementById(tabs[tab] + 'Content').style.display = 'block';
		}
	}

}

function changeTab2(activeTab, activeContent) {
	if($j("#specTabs").length) {
		var vsOptionsTab = false, vsExteriorTab = false, vsInteriorTab = false, vsMechanicalTab = false, vsInstalledTab = false;
		
		//see which exist - specs/tech always exist
		if(document.getElementById('vsInstalledTab') != null)
			vsInstalledTab = true;
		if(document.getElementById('vsOptionsTab') != null)
			vsOptionsTab = true;
		if(document.getElementById('vsExteriorTab') != null)
			vsExteriorTab = true;
		if(document.getElementById('vsInteriorTab') != null)
			vsInteriorTab = true;
		if(document.getElementById('vsMechanicalTab') != null)
			vsMechanicalTab = true;
			
		// Disable all tab content
		$j('#vsSpecsTab').attr("class","tab_wrapper not_selected");
		if(vsInstalledTab){$j('#vsInstalledTab').attr("class","tab_wrapper not_selected");}
		if(vsOptionsTab){$j('#vsOptionsTab').attr("class","tab_wrapper not_selected");}
		if(vsExteriorTab){$j('#vsExteriorTab').attr("class","tab_wrapper not_selected");}
		if(vsInteriorTab){$j('#vsInteriorTab').attr("class","tab_wrapper not_selected");}
		if(vsMechanicalTab){$j('#vsMechanicalTab').attr("class","tab_wrapper not_selected");}
		$j('#vsTechTab').attr("class","tab_wrapper not_selected");
		
		$j('#' + activeTab).attr("class","tab_wrapper_selected selected");
		
		// Enable correct tab content
		document.getElementById(activeContent).style.display = 'block';

		// Disable all tab content
		document.getElementById('vsSpecsContent').style.display = 'none';
		if(vsInstalledTab){document.getElementById('vsInstalledContent').style.display = 'none';}
		if(vsOptionsTab){document.getElementById('vsOptionsContent').style.display = 'none';}
		if(vsExteriorTab){document.getElementById('vsExteriorContent').style.display = 'none';}
		if(vsInteriorTab){document.getElementById('vsInteriorContent').style.display = 'none';}
		if(vsMechanicalTab){document.getElementById('vsMechanicalContent').style.display = 'none';}
		document.getElementById('vsTechContent').style.display = 'none';
		
		// Enable correct tab content
		document.getElementById(activeContent).style.display = 'block';
	}
}

function changePhoto(photoSrc) {
	
	document.getElementById('mainImg').src = photoSrc;
	
}

function show360(path){
	window.open("./360view.asp?mov=" + path, "_blank", "width=320,height=256");
}

function vnsRequest() {

	// purpose: addition to vns product itself to extend functionality with better post methods
	
	if (!isEmailValid($j('#vnsEmail').val())) {
		alert('Email Address is invalid');
		return false;
	}
	
	var vnsPost = new ajaxObject("/InventoryHosting2/Details/includes/products/VNS/vns_post.asp");
	var postStr = "domain=" + encodeURIComponent($j("#vnsDomain").val()) + "&email=" + encodeURIComponent($j("#vnsEmail").val()) + 
				  "&manufacturer=" + encodeURIComponent($j("#vMake").html()) + "&model=" + encodeURIComponent($j("#vModel").html());
	vnsPost.callback = function(responseText, responseStatus, responseXML) {
		if (responseStatus == 200){	
			$j("#vns_add_form").html('<strong style="font-size:12px;">' + responseText + '</strong>').fadeOut(3000);
		}
		else {
			alert('Error sending Notification');
		}
	}
	vnsPost.update(postStr, 'post');

}

function changePhotoPanel(panelID, PanelCount) {
	document.getElementById('ImageFrameCount' + panelID).style.display = 'block';
	for (i = 1; i <= PanelCount; i++)
	{
		if (i != panelID) {
			document.getElementById('ImageFrameCount' + i).style.display = 'none';
		}
	}
	
}

(function($) {

	// purpose: initialize all navigation headers

	$.fn.equalizeCols = function(){
		var height = 0,
			reset = $.browser.msie ? "1%" : "auto";
  
		return this
			.css("height", reset)
			.each(function() {
				height = Math.max(height, this.offsetHeight);
			})
			.css("height", height)
			.each(function() {
				var h = this.offsetHeight;
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
			
	};
	
	$.fn.equalizeColsWithin = function(){
		
		return this
			.each(function(){
				var self = $(this).children();
				if( self.length > 1 && self.find('.no-equalize').length == 0 )
					self.find('div.inside').equalizeCols();
			});
		
	};
	
})($j);


