+// Google Street View Gun (GSVG) 0.2 Javascript
+// Created by Brian Flowers
+//
+// javascript:{{ var svjs=document.createElement("script"); svjs.src = "http://personal.psu.edu/bsf5033/shootview/shootview.js"; svjs.type="text/javascript"; document.getElementsByTagName("body")[0].appendChild(svjs);} stub(); }
+// M9 Gunshot sound effect from: http://soundbible.com/1906-Barreta-M9.html
+
+var svXscale = 1;
+var svYscale = 1;
+var hitNum = 0;
+var selectedGun = "m9";
+
+function run()
+{
+ document.body.style.cursor = "none";
+
+ var overlay = document.createElement("img");
+ overlay.setAttribute("src", "http://www.personal.psu.edu/bsf5033/gsvg/guns/"+selectedGun+"/crosshair.png");
+ overlay.setAttribute("id", "crosshair");
+ overlay.style.width = "50px";
+ overlay.style.height = "50px";
+ overlay.style.position = "absolute";
+ overlay.style.left = "100px";
+ overlay.style.top = "100px";
+ overlay.style.zIndex = "1000";
+ overlay.onclick = fire;
+ document.body.appendChild(overlay);
+
+ var gunImage = document.createElement("img");
+ gunImage.setAttribute("src", "http://www.personal.psu.edu/bsf5033/gsvg/guns/"+selectedGun+"/gun.png");
+ gunImage.setAttribute("id", "gunImage");
+ gunImage.style.width = "400px";
+ gunImage.style.height = "300px";
+ gunImage.style.position = "absolute";
+ gunImage.style.right = "0px";
+ gunImage.style.bottom = "0px";
+ gunImage.style.zIndex = "1000";
+ document.body.appendChild(gunImage);
+
+ document.onmousemove = UpdateCrosshairPosition;
+
+ fire(null);
+ reFocus();
+}
+
+function UpdateCrosshairPosition(e)
+{
+ document.getElementById("crosshair").style.left = (e.pageX-25)+"px";
+ document.getElementById("crosshair").style.top = (e.pageY-25)+"px";
+
+ var gunImage = document.getElementById("gunImage");
+
+ xDist = (window.innerWidth - parseInt(gunImage.style.width)) - e.pageX;
+ svXscale = xDist*2 / window.innerWidth;
+
+ yDist = window.innerHeight - e.pageY;
+ svYscale = yDist / window.innerHeight;
+
+ gunImage.style.width = (150+250*svXscale)+"px";
+ gunImage.style.bottom = (-100+100*svYscale)+"px";
+}
+
+function drawMuzzleFlash()
+{
+ var flash = document.createElement("img");
+ flash.setAttribute("src", "http://www.personal.psu.edu/bsf5033/gsvg/guns/"+selectedGun+"/muzzleFlash.png");
+ flash.setAttribute("id", "muzzleFlash");
+ flash.style.width = (800*(svXscale/2))+"px";
+ flash.style.height = (200)+"px";
+ flash.style.position = "absolute";
+ flash.style.right = ((150+225*svXscale)-(400*(svXscale/2)))+"px";
+ flash.style.bottom = ((75+100*svYscale))+"px";
+ flash.style.zIndex = "900";
+ document.body.appendChild(flash);
+ setTimeout("remove('muzzleFlash');", 25);
+}
+
+function fire(e)
+{
+ var hitDiv = document.createElement("div")
+ var hitDivId = "hitDiv"+hitNum;
+ var hitImgId = "hitImg"+hitNum
+ hitNum++;
+ hitDiv.setAttribute("id", hitDivId);
+
+ var shotSound = document.createElement("embed");
+ shotSound.setAttribute("src", "http://www.personal.psu.edu/bsf5033/gsvg/guns/"+selectedGun+"/fire.mp3");
+ shotSound.setAttribute ("autostart", "true");
+ shotSound.setAttribute("id", "shotSound");
+ shotSound.setAttribute("enablejavascript", "true");
+ hitDiv.appendChild(shotSound);
+
+ var hitImage = document.createElement("img");
+ hitImage.setAttribute("src", "http://www.personal.psu.edu/bsf5033/gsvg/guns/"+selectedGun+"/hit.gif");
+ hitImage.setAttribute("id", hitImgId);
+ hitImage.style.width = "15px";
+ hitImage.style.height = "15px";
+ hitImage.style.position = "absolute";
+ hitImage.style.top = (e.pageY-7)+"px";
+ hitImage.style.left = (e.pageX-10)+"px";
+ hitImage.style.zIndex = "1000";
+ hitDiv.appendChild(hitImage);
+ document.body.appendChild(hitDiv);
+ drawMuzzleFlash();
+ hitNum++;
+
+ setTimeout("remove('"+hitImgId+"')", 350);
+ setTimeout("remove('"+hitDivId+"')", 1000);
+
+ reFocus();
+}
+
+function reFocus()
+{
+ document.getElementById("panoflash1").focus()
+}
+
+function remove(id)
+{
+ element = document.getElementById(id);
+ element.parentNode.removeChild(element);
+}
+
+function stub()
+{}
+
+//alert("GSVG will start in 5 seconds -- take this time to hide the maps side pane. And if you haven't selected your street view location yet, better hurry up!");
+//setTimeout("run();", 5000);
+run();
\ No newline at end of file