/*****************************\
   Custom JS for Comox Valley
\*****************************/


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


var ComoxValley = {};

ComoxValley.popupdata = {
	'black-creek':	{ x:175, y: 95, w:40, h:35 },
	'comox':		{ x:555, y:325, w:50, h:20 },
	'courtenay':	{ x:355, y:355, w:75, h:20 },
	'cumberland':	{ x:415, y:492, w:85, h:20 },
	'denman-island':{ x:695, y:490, w:50, h:35 },
	'fanny-bay':	{ x:765, y:635, w:40, h:35 },
	'hornby-island':{ x:893, y:555, w:45, h:35 },
	'merville':		{ x:330, y:210, w:55, h:20 },
	'royston':		{ x:510, y:437, w:52, h:20 },
	'union-bay':	{ x:650, y:510, w:40, h:35 }
}; 

GSSI.Environment.onDOMReady ( function() {

	ComoxValley.LeftContainer = GSSI.$("container-left");
	ComoxValley.MainContainer = GSSI.$("main-container");
	var map = ComoxValley.Map = GSSI.DOM.createElement( "div", {id:"ComoxValleyGrandMap"},{
								 height:ComoxValley.LeftContainer.offsetHeight + "px",
								 width: "160px",
								 top: "0",
								 left: (ComoxValley.LeftContainer.offsetWidth - 2)  + "px"
					  } );
	document.body.appendChild(ComoxValley.Map);
	
	map.closedwidth = 160;
	map.closedleft = (ComoxValley.LeftContainer.offsetWidth - 2);
	map.openingleft = ComoxValley.Map.closedleft;
	map.openwidth = 1062;
	map.openleft = 185;
	map.isopen = false;

	var toggle = GSSI.DOM.createElement( "a", {href:"javascript:ComoxValley.Map.toggle();"}, 
		{ left:"13px", top:"118px", height:"121px", width:"122px", background: "transparent url(/images/right/mapbutton_open.gif) 0 0 no-repeat" } );
	toggle._closeimage = new Image();
	toggle._closeimage.src = "/images/right/mapbutton_close.gif";
	
	map.appendChild(toggle);

	map.openmorpher = new GSSI.Effects.Morpher( map, 
			{ left:map.openingleft },
			{ left:map.openleft },
			{ callback: function(){
					map.isopen = true;
					map.style.width = map.openwidth + "px";
					map.style.left = map.openleft + "px";
					toggle.style.background = "transparent url(/images/right/mapbutton_close.gif) 0 0 no-repeat";
			}, fps:30, duration:1.0 }// 90x90 30,130
	);

	map.closemorpher = new GSSI.Effects.Morpher( map, 
			{ left:map.openleft },
			{ left:map.openingleft },
			{ callback: function(){									
					ComoxValley.MainContainer.style.background = "url(../images/right/grandmap.jpg) no-repeat 838px 0";
					map.isopen = false;
					map.style.width = map.closedwidth + "px";
					map.style.left = map.closedleft + "px";
					toggle.style.background = "transparent url(/images/right/mapbutton_open.gif) 0 0 no-repeat";					
			}, fps:30, duration:1.0 }
	);


	ComoxValley.Map.toggle = function() {
		if (map.isopen) {
			map.closemorpher.run();
		} else {
			map.style.width = map.openwidth + "px";
			map.style.height = ComoxValley.LeftContainer.offsetHeight + "px";
			ComoxValley.MainContainer.style.background = "none";
			map.openmorpher.run();
		}
	};

	inst = GSSI.DOM.createElement( "div", { }, 
			{ position:"absolute", left: "320px", top: "15px", width:"277px", height:"12px",
				background:"transparent url(/images/right/rolloverandclick.gif) top left no-repeat" }
		);

	map.appendChild( inst );

	function makeshow( p ) {
		return function() {
			p.style.display = "block";
		};
	}

	function makehide( p ) {
		return function() {
			p.style.display = "none";
		};
	}

	var filterprop;
	var backgroundprop;
	var pd, pa, ppop; //  /about-comox-valley/<name>.htm	
	for( var name in ComoxValley.popupdata ) {
		pd = ComoxValley.popupdata[name];

		filterprop = (GSSI.Environment.Browser.IE6) ? ("progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/right/" + name + ".png', sizingMethod='scale')") : null;
		backgroundprop = (GSSI.Environment.Browser.IE6) ? null : ("transparent url(/images/right/" + name +".png) bottom left no-repeat");

		ppop = GSSI.DOM.createElement( "div",
			{ 'class':"grandmappopup" }, 
			{ left: (pd.x + (pd.w * 0.7)) + "px", top: (pd.y - 80) + "px", zoom:"1", filter:filterprop, background:backgroundprop }
		);
		pa = GSSI.DOM.createElement( "a",
			{ href:"/about-comox-valley/" + name + ".htm" }, 
			{ left: pd.x + "px", top: pd.y + "px", height: pd.h + "px", width:pd.w + "px" }
		);

		map.appendChild(pa);
		map.appendChild(ppop);
		
		pa.onmouseover = makeshow(ppop);
		pa.onmouseout = makehide(ppop);
	}
} );


