var activeNodeID = "";

function loadMap(whichMap) {
	if(whichMap.className == "regMap"){
		if (GBrowserIsCompatible()) {
			
			whichMap.className = "google";
			whichMap.innerHTML = "View Regular Map";
		
			var map = new GMap2(document.getElementById("imgset"));
			map.addControl(new GSmallMapControl());
			map.setCenter(new GLatLng(40.9451,-73.042485), 13);
			var point = new GLatLng(40.921401,-73.042485);
			
			var marker = new GMarker(point);
			
			GEvent.addListener(marker, "click", function() {
				if(infoWinCurOpen==true){
					infoWinCurOpen = false;
					marker.closeInfoWindow();
				} else {	
					infoWinCurOpen = true;
					marker.openInfoWindowHtml("<span class='gpopup'><h5>The Meadow Club<"+"/h5>1147 Rte. 112, Port Jefferson Station, NY 11776<br />Tel: 631-928-3800<br />Fax: 631-928-4404<br /><a href=\"http:/"+"/maps.google.com/maps?f=q&hl=en&geocode=&time=&date=&ttype=&q=1147+Rte.+112,+Port+Jefferson+Station,+NY+11776&sll=37.0625,-95.677068&sspn=42.310334,59.765625&ie=UTF8&z=16&iwloc=addr&om=1\" target=\"_blank\">Go To This Google Map<"+"/a><"+"/span>");
				}
			});
			
			map.addOverlay(marker);
			marker.openInfoWindowHtml("<span class='gpopup'><h5>The Meadow Club<"+"/h5>1147 Rte. 112, Port Jefferson Station, NY 11776<br />Tel: 631-928-3800<br />Fax: 631-928-4404<br /><a href=\"http:/"+"/maps.google.com/maps?f=q&hl=en&geocode=&time=&date=&ttype=&q=1147+Rte.+112,+Port+Jefferson+Station,+NY+11776&sll=37.0625,-95.677068&sspn=42.310334,59.765625&ie=UTF8&z=16&iwloc=addr&om=1\" target=\"_blank\">Go To This Google Map<"+"/a><"+"/span>");
			//GEvent.addListener(marker, "click", alert("open"));
			
		}
	} else {
		
		var imgArea = document.getElementById("imgset");
		while (imgArea.lastChild) imgArea.removeChild(imgArea.lastChild);
		
		whichMap.className = "regMap";
		whichMap.innerHTML = "View Google Map";
		var imgAdd = document.createElement( 'img' );
		imgAdd.src = imgArray[0]; 
		imgAdd.width = 666;
		imgAdd.height = 457;
		imgArea.appendChild(imgAdd);

		//document.getElementById("imgset")
	}
}

function getDims() {
	var winW = 0;
	var winH = 0;
	
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		}
	}
	
	return(Array(winW, winH));
}


function setImgs() {
	if(imgArray.length >1){
		var imgstrip = document.getElementById('imgstrip');
		for (var i = 1; i<imgArray.length; i++) { // Loop through the a elements
			var imgAdd = document.createElement( 'img' );
			imgAdd.src = imgArray[i]; 
			imgAdd.width = 666;
			imgAdd.height = 457;
			imgstrip.appendChild(imgAdd);
		}
		var imgAdd = document.createElement( 'img' );
		imgAdd.src = imgArray[0]; 
		imgAdd.width = 666;
		imgAdd.height = 457;
		imgstrip.appendChild(imgAdd);
	
		var imgAdd = document.createElement( 'img' );
		imgAdd.src = imgArray[(imgArray.length-1)]; 
		imgAdd.width = 666;
		imgAdd.height = 457;
		imgAdd.id = "negativeImg";
		imgstrip.appendChild(imgAdd);
	}
}
function setImgSet() {
	setTimeout(setImgs,500);
	setTimeout(setButtons,500);
}

function externalLinks() {
	var links = document.getElementsByTagName('a');// Fetch all the anchor elements in the document.
	for (var i = links.length; i != 0; i--) { // Loop through the a elements
		var a = links[i-1]; // Pull out the element for this iteration.
		if (!a.href) continue; // If the element doesn't have an href, skip it.
		if (a.className && a.className.indexOf('external') != -1){
				a.target = '_blank';
		}
	}
}


function browserCheck() {
	if(navigator.vendor){
		tmpVend = navigator.vendor;
		browserUsed = (tmpVend.indexOf("Apple")==-1) ? "" : "Safari";
	} else {
		browserUsed = "";
	}
}

function slideImg() {

	if (document.getElementById) {

		var imgstrip = document.getElementById('imgstrip');
		curX += Math.round(((curImg*imgWidth*-1)-curX)/3);
		imgstrip.style.left = curX+'px';

		if( Math.abs(curX-(curImg*imgWidth*-1)) >= 5 ){
			window.setTimeout("slideImg()", 50);
		} else {
			if(curImg < 0){ curImg = (imgNumber-1); }
			if(curImg == imgNumber){ curImg = 0; }
			curX = (curImg*imgWidth*-1);
			imgstrip.style.left = curX + 'px';
			document.getElementById('nxtlnk').className = "fwdactive";
			document.getElementById('prvlnk').className = "bckactive";
		}
	}
}
function setTextset(){
	w = getDims();
	winWidth = (w[1]<=720) ? w[0]-686 : w[0]-666;
	document.getElementById('textset').style.width = winWidth + 'px';
	if(activeNodeID!=""){
		document.getElementById(activeNodeID).style.width = winWidth + 'px';
	}
	if(baseNodeID!=""){
		document.getElementById(baseNodeID).style.width = winWidth + 'px';
	}
}

function slideText() {
	if (document.getElementById) {
		var aNode = document.getElementById(activeNodeID);
		var bNode = document.getElementById(baseNodeID);
		curLeft += Math.round((0-curLeft)/3);
		aNode.style.left = curLeft+'px';
		bNode.style.left = (curLeft-parseInt(aNode.style.width))+"px";
		
		if( Math.abs(curLeft) >= 5 ){
			window.setTimeout("slideText()", 50);
		} else {
			aNode.style.left = '0px';
		}
		/* document.getElementById('imgset').style.zIndex = 4;
		document.getElementById('textset').style.zIndex = 1;
		document.getElementById('textset').style.overflow = "hidden"; */
	}
}

function lstImg(node) {
	if(node.className.indexOf("inactive") == -1){
		document.getElementById('nxtlnk').className = "fwdinactive";
		document.getElementById('prvlnk').className = "bckinactive";
		curImg--;
		slideImg();
	}
}

function nxtImg(node) {
	if(node.className.indexOf("inactive") == -1){
		document.getElementById('nxtlnk').className = "fwdinactive";
		document.getElementById('prvlnk').className = "bckinactive";
		curImg++;
		slideImg();
	}
}

function setButtons() {
	if (imgNumber>1) {
	var imgNode = document.getElementById('imglinks');
	linkMarkup = '<a href="#" onclick="lstImg(this); return false;" title="" id="prvlnk" class="bckactive"><span>Previous<'+'/'+'span><'+'/'+'a><a href="#" onclick="nxtImg(this); return false;" title="" id="nxtlnk" class="fwdactive"><span>Next<'+'/'+'span><'+'/'+'a>';
	imgNode.innerHTML = linkMarkup;
	}
}

function print_element(nodeNum, nodeCount){
	for (var i = 0; i<nodeCount; i++) { 
		document.getElementById('slot'+i).className = "menucard noprint";
		}
	document.getElementById('slot'+nodeNum).className = "menucard";
	window.print();
	}


function slideNode(active){
	
	w = getDims();
	//winWidth = w[0]-666;
	winWidth = (w[1]<=720) ? w[0]-686 : w[0]-666;
	activeNodeID = active;
	
	var aNode = document.getElementById(activeNodeID);
	aNode.style.width = winWidth + 'px';
	aNode.style.left = winWidth + 'px';
	document.getElementById(baseNodeID).style.width = winWidth + 'px';
	curLeft = winWidth;
	slideText();
	}

function slideBack(){
	w = getDims();
	wWidth = w[0]-666;
	
	if (document.getElementById) {
		var aNode = document.getElementById(activeNodeID);
		var bNode = document.getElementById(baseNodeID);
		curLeft += Math.round((wWidth-curLeft)/3);
		aNode.style.left = curLeft+'px';
		bNode.style.left = (curLeft-parseInt(aNode.style.width))+"px";
		document.getElementById(baseNodeID).style.width = winWidth + 'px';
		
		if( Math.abs(curLeft-wWidth) >= 5 ){
			window.setTimeout("slideBack()", 50);
		} else {
			aNode.style.left = '1000px';
		}
	}
}

function init(){
	externalLinks();
	setTextset();

	//setButtons();
	setImgSet();
	browserCheck();
}