// JavaScript Document
var homeCarousel = null;
winArr = new Array();

function checkWin() {
	for(var i = 0; i < winArr.length; i++) {
		var win = winArr[i];
		if(win.visible == true) {
			win.hide();
		}
	}
	
	if((winArr['testdrive'] != undefined) && (winArr['testdrive'].visible == true)) {
		winArr['testdrive'].hide();
	}
	if((winArr['price'] != undefined) && (winArr['price'].visible == true)) {
		winArr['price'].hide();
	}
	if((winArr['financing'] != undefined) && (winArr['financing'].visible == true)) {
		winArr['financing'].hide();
	}
	if((winArr['features'] != undefined) && (winArr['features'].visible == true)) {
		winArr['features'].hide();
	}
	if((winArr['bizlink'] != undefined) && (winArr['bizlink'].visible == true)) {
		winArr['bizlink'].hide();
	}
	if((winArr['bestprice'] != undefined) && (winArr['bestprice'].visible == true)) {
		winArr['bestprice'].hide();
	}
}

function navWindowOnClose() {
	if(homeCarousel != null)
		homeCarouselInt = setInterval('homeCarousel.next()', homeCarouselDuration);
}

function onNavWindowExpand() {
	if(homeCarousel != null)
		clearInterval(homeCarouselInt);
}

function calcPos(num) {
	var viewportwidth;
	
	if (typeof window.innerWidth != 'undefined')
	{
		viewportwidth = window.innerWidth;
	}
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	{
		viewportwidth = document.documentElement.clientWidth;
	}
	
	// older versions of IE
	
	else
	{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
	}
	return ((viewportwidth - 960) / 2) + num;
}

var updateWindowPos = function() {
	if(winArr['testdrive'] != undefined) {
		winArr['testdrive'].setLocation(240, calcPos(506));
	}
	if(winArr['price'] != undefined) {
		winArr['price'].setLocation(240, calcPos(344));
	}
	if(winArr['financing'] != undefined) {
		winArr['financing'].setLocation(240, calcPos(506));
	}
	if(winArr['features'] != undefined) {
		winArr['features'].setLocation(260, calcPos(198));
	}
	if(winArr['bizlink'] != undefined) {
		winArr['bizlink'].setLocation(105, calcPos(266));
	}
	
	for(var i = 0; i < winArr.length; i++) {
		if(winArr[i] != undefined) {
			if(winArr[i].getId() == 'features_expanded') {
				winArr[i].setLocation(260, calcPos(198));
			} else if(winArr[i].getId() == 'price_expanded') {
				winArr[i].setLocation(240, calcPos(382));
			} else if((winArr[i].getId() == 'financing_expanded') || (winArr[i].getId() == 'testdrive_expanded')) {
				winArr[i].setLocation(240, calcPos(506));
			}
		}
	}
}

Event.observe(window, 'resize', updateWindowPos);