(function () {
    var newPage = document.querySelector("#new-page");
    if (newPage) {
        newPage.onclick = function () {
            selectedtype=0;
            loaddevices();
            toggleTransition('#menupage', '#devicespage', 17, 1);
        }
    }
 
    var popularPage = document.querySelector("#popular-page");
    if (popularPage) {
        popularPage.onclick = function () {
             selectedtype=1;
             loaddevices();
             toggleTransition('#menupage', '#devicespage', 17, 1);
         }
     }
 
     var randomPage = document.querySelector("#random-page");
     if (randomPage) {
         randomPage.onclick = function () {
            selectedtype=3;
            loadrandomcomparisons();
            toggleTransition('#menupage', '#randomcomparepage', 17, 1);
         }
     }
 
     var brandsPage = document.querySelector("#brands-page");
     if (brandsPage) {
         brandsPage.onclick = function () {
            loadbrands();
            toggleTransition('#menupage', '#brandpage', 17, 1);
         }
     }
 
     var searchPage = document.querySelector("#search-page");
     if (searchPage) {
         searchPage.onclick = function () {
             toggleTransition('#menupage', '#searchpage', 53, 1);
         }
     }
	 
	 var historyPage = document.querySelector("#history-page");
     if (historyPage) {
         historyPage.onclick = function () {
             selectedtype=3;
			 loaddevices();
			 toggleTransition('#menupage', '#devicespage', 17, 1);
         }
     }
 
     var searchPage1 = document.querySelector("#search-page1");
     if (searchPage1) {
        searchPage1.onclick = function () {
            toggleTransition('#devicespage', '#searchpage', 53, 1);
        }
     }
 
     var searchPage2 = document.querySelector("#search-page2");
     if (searchPage2) {
         searchPage2.onclick = function () {
            toggleTransition('#brandpage', '#searchpage', 53, 1);
         }
     }
	 
	 var backPage1 = document.querySelector("#back-page1");
     if (backPage1) {
         backPage1.onclick = function () {
         	toggleTransition('#devicespage', '#menupage', 24, 0);
         }
     }
 
    var backPage2 = document.querySelector("#back-page2");
     if (backPage2) {
         backPage2.onclick = function () {
         	toggleTransition('#brandpage', '#menupage', 24, 0);
         }
     }
	 
	 var backPage3 = document.querySelector("#back-page3");
     if (backPage3) {
         backPage3.onclick = function () {
         	toggleTransition('#searchpage', '#menupage', 52, 0);
         }
     }
	 
	 var backPage4 = document.querySelector("#back-page4");
     if (backPage4) {
         backPage4.onclick = function () {
         	 toggleTransition('#specpage', '#devicespage', 24, 0);
         }
     }
	 
	 var backPage5 = document.querySelector("#back-page5");
     if (backPage5) {
         backPage5.onclick = function () {
         	 toggleTransition('#gallerypage', '#specpage', 2, 0);
			 clearGallery();
         }
     }
	 
	 var backPage6 = document.querySelector("#back-page6");
     if (backPage6) {
         backPage6.onclick = function () {
         	 toggleTransition('#comparepage', '#menupage', 24, 0);
         }
     }
	 
	 var backPage7 = document.querySelector("#back-page7");
     if (backPage7) {
         backPage7.onclick = function () {
         	 toggleTransition('#randomcomparepage', '#menupage', 24, 0);
         }
     }
	 
	 var backPage8 = document.querySelector("#back-page8");
     if (backPage8) {
         backPage8.onclick = function () {
         	 toggleTransition('#contactpage', '#menupage', 24, 0);
         }
     }
	
	var sharePage1 = document.querySelector("#share-page1");
     if (sharePage1) {
         sharePage1.onclick = function () {
         	 loadsharedialog();
			 toggleTransition('#specpage', '#sharedialog', 30, 1);
         }
     }
	 
	 var sharePage2 = document.querySelector("#share-page2");
     if (sharePage2) {
         sharePage2.onclick = function () {
         	 loadsharedialog();
			 toggleTransition('#comparepage', '#sharedialog', 30, 1);toggleTransition('#specpage', '#sharedialog', 30, 1);
         }
     }
	 
	 var refreshRandom = document.querySelector("#refresh-random");
     if (refreshRandom) {
         refreshRandom.onclick = function () {
         	 loadrandomcomparisons();
         }
     }
	 
	 var closePrompt = document.querySelector("#close-prompt");
     if (closePrompt) {
         closePrompt.onclick = function () {
         	hidePrompt('#compareprompt');
			return false;
         }
     }
	 
	 var searchKeypress = document.querySelector("#q");
     if (searchKeypress) {
         searchKeypress.onkeyup = function () {
         	onSearch(this.value);
         }
     }
	 
	 var shareEmail = document.querySelector("#share-email");
     if (shareEmail) {
         shareEmail.onclick = function () {
         	emaillink();
         }
     }
	 
	 var shareTwitter = document.querySelector("#share-twitter");
     if (shareTwitter) {
         shareTwitter.onclick = function () {
         	tweetlink();
         }
     }
	 
	 var shareFacebook = document.querySelector("#share-facebook");
     if (shareFacebook) {
         shareFacebook.onclick = function () {
         	facebooklink();
         }
     }
	 
	 var shareClose = document.querySelector("#share-close");
     if (shareClose) {
         shareClose.onclick = function () {
         	toggleTransition('#sharedialog', '#specpage', 31, 0);
         }
     }
	 
	 
 
})();