// Whisky Map of Scotland. Copyright (c) 2009 Franc van den Heuvel, MIT Style License.

window.name='whiskymap';var scroll,scroll2,mapDrag,tips,map,mapWidth,mapHeight,mapRatio,screenWidth,screenHeight,screenRatio,maxPopinHeight,helpContentHeight,helpHeight,minimap,minimapWidth,minimapHeight,minimapScale,selectedLocation,mapEntry;var selectedMap='scotland.jpg';var locationURL='';var keyListen=false;var urlParams=window.location.search;if(urlParams!=''){urlParams=urlParams.split('&');for(var i=0;i<urlParams.length;i++){var param=urlParams[i].split('=');if(param[0]=="?maplocation"){locationURL=unescape(param[1]);}}}window.addEvent('domready',function(){screenWidth=$('mapviewer').getSize().x;screenHeight=$('mapviewer').getSize().y;screenRatio=screenWidth/screenHeight;maxPopinHeight=screenHeight-18;$('loadmessage').setStyle('margin-top', '' + (screenHeight - $('loadmessage').getSize().y)/2 + 'px');$('loadmessage').setStyle('color','#FFC631');$('anchors').setStyle('opacity','0.8');helpContentHeight=$('help').getScrollSize().y;if(helpContentHeight>maxPopinHeight){helpHeight=maxPopinHeight;}else{helpHeight=helpContentHeight;}$('help').setStyles({'opacity':'0.0','left':''+Math.round((screenWidth-$('help').getSize().x)/2)+'px','top':''+Math.round((screenHeight-helpHeight)/2)+'px','height':''+helpHeight+'px','overflow-y':'auto','display':'none'});$('help').addEvent('click',function(event){togglePop('help','0.8',$('togglehelp'));});map=new Image();map.onload=function(){mapWidth=this.width;mapHeight=this.height;mapRatio=mapWidth/mapHeight;var mapcontent=new Element('div',{id:'mapcontent',styles:{position:'relative',width:''+this.width+'px',height:''+this.height+'px','background-image':'url('+this.src+')'}}).inject('mapviewer');minimapWidth=$('minimap').getSize().x;minimapHeight=Math.round(minimapWidth/mapRatio);minimapScale=minimapWidth/mapWidth;$('minimap').setStyle('height',''+minimapHeight+'px');var minimap=new Element('img',{id:'mmap',width:minimapWidth,height:minimapHeight,src:this.src,styles:{width:minimapWidth,height:minimapHeight}}).inject($('minimap'));var positioner=new Element('div',{id:'positioner',styles:{position:'absolute',left:'0px',top:'0px',width:''+Math.round(minimapScale*screenWidth)+'px',height:''+Math.round(minimapScale*screenHeight)+'px',border:'1px solid #355355',margin:'-1px',cursor:'pointer','background-image':'url(gfx/x.gif)'},events:{'click':function (event){event.stop();}}}).inject($('minimap'));$('minimap').addEvent('click',function(event){event.stop();var mmapLeft=event.client.x-$('minimap').getCoordinates().left;var mmapTop=event.client.y-$('minimap').getCoordinates().top;scroll.start(Math.round((event.client.x-$('minimap').getCoordinates().left-$('positioner').getSize().x/2)/minimapScale),Math.round((event.client.y-$('minimap').getCoordinates().top-$('positioner').getSize().y/2)/minimapScale));});scroll=new Fx.Scroll('mapviewer',{link:'cancel',duration:2000,transition:Fx.Transitions.Quad.easeInOut,onComplete:function(){$('positioner').morph({left:''+Math.round(minimapScale*$('mapviewer').getScroll().x)+'px',top:''+Math.round(minimapScale*$('mapviewer').getScroll().y)+'px'});}});scroll2=new Fx.Scroll('mapviewer',{link:'cancel',duration:1000,transition:Fx.Transitions.Quad.easeInOut});mapDrag=new Drag('mapviewer',{style:false,invert:true,snap:8,modifiers:{x:'scrollLeft',y:'scrollTop'},onComplete:function(el){$('positioner').morph({left:''+Math.round(minimapScale*$('mapviewer').getScroll().x)+'px',top:''+Math.round(minimapScale*$('mapviewer').getScroll().y)+'px'});}});var myDrag=new Drag.Move('positioner',{container:$('minimap'),snap:4,onSnap:function(el){dragPositioner = true;el.addClass('dragging');},onComplete:function(el){var coords=el.getCoordinates($('minimap'));el.removeClass('dragging');scroll2.start(Math.round(coords.left/minimapScale),Math.round(coords.top/minimapScale));}});locations.each(function(item,index){item.pixel=new Element('div',{id:'loc'+index,'class':'loc',styles:{left:''+item.x+'px',top:''+item.y+'px',opacity:0.8}}).inject('mapcontent');item.pixel.store('location',item);var imgURL='gfx/alt-1.png';if((item.status.toLowerCase().indexOf('silent')!=-1)||(item.status.toLowerCase().indexOf('mothballed')!=-1)){imgURL='gfx/alt-2.png';}if(item.type.toLowerCase().indexOf('grain')!=-1){imgURL = 'gfx/alt-3.png';}item.pixelImage=new Element('img',{id:'img'+index,src:imgURL,width:'12',height:'12'}).inject(item.pixel);item.pixelImage.store('location', 'item');item.pixelImage.store('originalSource',imgURL);item.locationLabel=new Element('div',{id:'label'+index,'class':'locationlabel',styles:{position:'absolute',left:''+item.x+'px',top:''+item.y+'px',opacity:0.5},events:{mouseenter:function(event){var myLoc=this.retrieve('location');if(myLoc!=selectedLocation){this.addClass('locationlabelselected');myLoc.pixelImage.set('src','gfx/alt-4.png');myLoc.pixel.addClass('selectedpixel');}},mouseleave:function(event){var myLoc=this.retrieve('location');if(myLoc!=selectedLocation){this.removeClass('locationlabelselected');myLoc.pixelImage.set('src',myLoc.pixelImage.retrieve('originalSource'));myLoc.pixel.removeClass('selectedpixel');}}}}).inject('mapcontent');item.locationLabel.store('location', item);item.link=new Element('a',{text:''+item.name,href:''+item.url,target:'maltmadness',events:{click:function(event){if(this.retrieve('location')!=selectedLocation){selectedLocation.anchor.removeClass('selectedanchor');selectedLocation.locationLabel.removeClass('locationlabelselected');selectedLocation.pixelImage.set('src',selectedLocation.pixelImage.retrieve('originalSource'));selectedLocation.pixel.removeClass('selectedpixel');var newSelection=this.retrieve('location');newSelection.anchor.addClass('selectedanchor');newSelection.locationLabel.addClass('locationlabelselected');newSelection.pixelImage.set('src','gfx/alt-4.png');newSelection.pixel.addClass('selectedpixel');selectedLocation = newSelection;}scroll.start(item.x-Math.round(screenWidth/2),item.y-Math.round(screenHeight/2));if((window.opener)&&(!window.opener.closed)){event.stop();window.opener.location.href=this.href;window.opener.focus();}}}}).inject(item.locationLabel);item.link.store('location',item);if((item.label_x)&&(item.label_y)){item.locationLabel.setStyle('left',''+item.label_x+'px');item.locationLabel.setStyle('top',''+item.label_y+'px');}else{item.locationLabel.setStyle('left',''+(item.x-(item.locationLabel.getSize().x/2))+'px');item.locationLabel.setStyle('top',''+(item.y+6)+'px');}item.link.store('tip:title', item.name);item.link.store('tip:text','<b>Region:<\/b> '+item.region+'<br\/><b>Type:<\/b> '+item.type+'<br\/><b>Status:<\/b> '+item.status+'<br\/><b>Active:<\/b> '+item.year);item.anchor=new Element('div',{id:'link'+index,text:item.name,'class':'outpost',events:{click:function(event){event.stop();selectedLocation.anchor.removeClass('selectedanchor');selectedLocation.locationLabel.removeClass('locationlabelselected');selectedLocation.pixelImage.set('src',selectedLocation.pixelImage.retrieve('originalSource'));selectedLocation.pixel.removeClass('selectedpixel');var newSelection=this.retrieve('location');newSelection.anchor.addClass('selectedanchor');newSelection.locationLabel.addClass('locationlabelselected');newSelection.pixelImage.set('src','gfx/alt-4.png');newSelection.pixel.addClass('selectedpixel');selectedLocation=newSelection;scroll.start(item.x-Math.round(screenWidth/2),item.y-Math.round(screenHeight/2));}}}).inject('anchors');item.anchor.store('location',item);if((item.status.toLowerCase().indexOf('silent')!=-1)||(item.status.toLowerCase().indexOf('mothballed') != -1)){item.anchor.addClass('menusilent');}if(item.type.toLowerCase().indexOf('grain')!=-1){item.anchor.addClass('menugrain');}if(((item.mapEntry)&&(locationURL==""))||((locationURL==item.name))){mapEntry=item;item.pixel.addClass('selectedpixel');item.anchor.addClass('selectedanchor');item.locationLabel.addClass('locationlabelselected');item.pixelImage.set('src','gfx/alt-4.png');item.pixel.addClass('selectedpixel');}});var myTips=new Tips($$('.locationlabel a'));if(mapEntry){mapEntry.anchor.scrollIntoView();$('mapviewer').scrollTo(mapEntry.x-Math.round(screenWidth/2),mapEntry.y-Math.round(screenHeight/2));selectedLocation=mapEntry;}$('positioner').setStyles({left:''+Math.round(minimapScale*$('mapviewer').getScroll().x)+'px',top:''+Math.round(minimapScale*$('mapviewer').getScroll().y)+'px'});keyListen=true;var loadscreenfader=new Fx.Tween('loadscreen',{delay:1000,duration:2000});loadscreenfader.start('opacity','0');};var keyRef;if(Browser.Engine.trident){keyRef=$(document.body);}else{keyRef = $(window);}keyRef.addEvent('keydown',function(event){if (keyListen == false) {return;}if((event.key=='up')||(event.key=='down')||(event.key=='left')||(event.key=='right')){event.stop();if(event.key=='up'){scroll.set($('mapviewer').getScroll().x, $('mapviewer').getScroll().y - 16);}else if(event.key=='down'){scroll.set($('mapviewer').getScroll().x, $('mapviewer').getScroll().y + 16);}else if(event.key=='left'){scroll.set($('mapviewer').getScroll().x - 16, $('mapviewer').getScroll().y);}else if(event.key=='right'){ scroll.set($('mapviewer').getScroll().x + 16, $('mapviewer').getScroll().y);}$('positioner').setStyles({left:''+Math.round(minimapScale*$('mapviewer').getScroll().x)+'px',top:''+Math.round(minimapScale*$('mapviewer').getScroll().y)+'px'});}else if(event.key=='d'){event.stop();togglePop('anchors', 0.8, $('toggleanchors'));}else if (event.key == 'm'){event.stop();togglePop('minimap',1,$('toggleminimap'));}else if(event.key=='h'){event.stop();togglePop('help',0.8,$('togglehelp'));}});map.src = selectedMap;});function zoomLocation(locationName){for(var i=0;i<locations.length;i++){if(locations[i].name==locationName){selectedLocation.anchor.removeClass('selectedanchor');selectedLocation.locationLabel.removeClass('locationlabelselected');selectedLocation.pixelImage.set('src',selectedLocation.pixelImage.retrieve('originalSource'));selectedLocation.pixel.removeClass('selectedpixel');var newSelection=locations[i];newSelection.anchor.addClass('selectedanchor');newSelection.locationLabel.addClass('locationlabelselected');newSelection.pixelImage.set('src','gfx/alt-4.png');newSelection.pixel.addClass('selectedpixel');selectedLocation=newSelection;scroll.start(locations[i].x-Math.round(screenWidth/2),locations[i].y-Math.round(screenHeight/2));break;}}}function togglePop(div,value,elem){if ($(elem).hasClass('toggled')){$(elem).removeClass('toggled');$(div).tween('opacity', '0.0');setTimeout("$('"+div+"').setStyle('display','none')",500);}else{$(elem).addClass('toggled');$(div).setStyle('display','block');$(div).tween('opacity',value);}}
