// Application Buttons //
var ISOCODE;
//Service & Body Shop
var imgOnAppointment = new Image(253,48);
imgOnAppointment.src = '/images/image.php?file=buttons/ENG/appointment2.gif';
var imgOffAppointment = new Image(253,48);
imgOffAppointment.src = '/images/image.php?file=buttons/ENG/appointment1.gif';

// MORE INFO BUTTON
var imgOnInfo = new Image(253,48);
imgOnInfo.src = '/images/image.php?file=buttons/ENG/more_info2.gif';
var imgOffInfo = new Image(253,48);
imgOffInfo.src = '/images/image.php?file=buttons/ENG/more_info1.gif';

//Parts
var imgOnPartsRequest = new Image(253,48);
imgOnPartsRequest.src = '/images/image.php?file=buttons/ENG/parts_request2.gif';
var imgOffPartsRequest = new Image(253,48);
imgOffPartsRequest.src = '/images/image.php?file=buttons/ENG/parts_request1.gif';

//Finance
var imgOnCreditApp = new Image(253,48);
imgOnCreditApp.src = '/images/image.php?file=buttons/ENG/credit_app2.gif';
var imgOffCreditApp = new Image(253,48);
imgOffCreditApp.src = '/images/image.php?file=buttons/ENG/credit_app1.gif';

sfHover = function() {
	if($("#topMenu").length > 0)
	{
		var timeout = 500;
		var cssClass = "sfhover";

		var queue = [];
		var reCSS = new RegExp("\\b" + cssClass + "\\b");
		var sfEls = document.getElementById("topMenu").getElementsByTagName("li");
		for (var i=0; i<sfEls.length; i++) {

			// mouseover and mouseout handlers for regular mouse based interface.
			sfEls[i].onmouseover = function() {
				queueFlush();
				this.className += " " + cssClass;
			}
			sfEls[i].onmouseout = function() {
				queue.push([setTimeout(queueTimeout, timeout), this]);
			}

			// focus and blur handlers for keyboard based navigation.
			sfEls[i].onfocus = function() {
				queueFlush();
				this.className += " " + cssClass;
			}
			sfEls[i].onblur = function() {
				queue.push([setTimeout(queueTimeout, timeout), this]);
			}

			// click event handler needed for tablet type interfaces (e.g. Apple iPhone).
			sfEls[i].onclick = function(e) {
				if (this.className.search(reCSS) == -1) {
					// CSS not set, so clear all sibling (and decendants) menus, and then set CSS on this menu...
					var elems = this.parentNode.getElementsByTagName("li");
					for (var i=0; i<elems.length; i++) {
						elems[i].className = elems[i].className.replace(reCSS, "");
					}
					this.className += " " + cssClass;
				} else {
					// CSS already set, so clear all decendant menus and then this menu...
					var elems = this.getElementsByTagName("li");
					for (var i=0; i<elems.length; i++) {
						elems[i].className = elems[i].className.replace(reCSS, "");
					}
					this.className = this.className.replace(reCSS, "");
				}
				if (e && e.stopPropagation)
					e.stopPropagation();
				else
					window.event.cancelBubble = true;
			}
		}

		queueFlush = function () {
			while (queue.length) {
				clearTimeout(queue[0][0]);
				queueTimeout();
			}
		}

		queueTimeout = function() {
			if (queue.length) {
				var el = queue.shift()[1];
				el.className = el.className.replace(reCSS, "");
			}
		}
	}
}
//if (window.attachEvent) window.attachEvent("onload", sfHover);

function init() {//function call required as part of body onload event when google map used on a page
		sfHover();
		
		loadGoogleMap();
	}
addLoadEvent(sfHover);
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function showStatus(sMsg) {//used often
	//setTimeout("window.status = \'" + sMsg + "\';", 0);
    window.status = sMsg ;
    return true ;
}
function openWindow(url,width,height){
	newWin = window.open(url, 'viewWin', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,left='+(screen.width-width)/2+',top='+(screen.height-height)/2+',width=' + width + ',height=' + height + '');
}		

function changeImg(imgName,imgPre) {
	if(document.images){
		document.images[imgName].src = eval(imgPre + '.src');
	}
}

function changeStyle(obj, new_style) {
    obj.className = new_style;
}
function expandableContent(callObj, obj, expandedStyle, collapsedStyle) {//used for collapsable content only (include only when necessary)
		var element = document.getElementById(obj);
		$(callObj+" img").toggle();
		if	(callObj.className == 'expanded')
		{
			element.className = expandedStyle;
			callObj.className = 'collapsed';
			callObj.innerHTML = 'More...';
		}
		else
		{
			element.className = collapsedStyle;
			callObj.className = 'expanded';
			callObj.innerHTML = 'Less...';
		}
			
}
