﻿var pid="";
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2625325-5']);
_gaq.push(['_trackPageview']);

(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


function BiggerMap() {
    a = "http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=34+Vestey+Drive+Auckland+New+Zealand&amp;sll=37.0625,-95.677068&amp;sspn=35.082817,67.060547&amp;ie=UTF8&amp;hq=&amp;hnear=34+Vestey+Dr,+Westfield,+Auckland+1060,+New+Zealand&amp;ll=-36.917097,174.837799&amp;spn=0.024018,0.036478&amp;z=14&amp;iwloc=A";
    window.open(a, "_blank");
}

function doMap() {
    var a = "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=34+Vestey+Drive,+Mount+Wellington+Auckland+1060,+New+Zealand&sll=37.0625,-95.677068&sspn=50.51141,114.169922&ie=UTF8&hq=&hnear=34+Vestey+Dr,+Westfield,+Auckland+1060,+New+Zealand&ll=-36.924337,174.83767&spn=0.025113,0.055747&z=15";
    window.open(a, "_blank");
}


////The following is to display the layers on the retailers page

function RetailersMap(CitySelected) {

    //First Hide all the other layers
    hideIt('Northland');
    hideIt('BayOfPlenty');
    hideIt('Waikato');
    hideIt('Rotorua');
    hideIt('EastCoast');
    hideIt('LakeTaupo');
    hideIt('Taranaki');
    hideIt('HawkesBay');
    hideIt('Wanganui');
    hideIt('Wellington');
    hideIt('Wairarapa');
    hideIt('Nelson');
    hideIt('WestCoast');
    hideIt('Canterbury');
    hideIt('Queentown');
    hideIt('Otago');
    hideIt('Southland');

    //Show the one they wanted
    showIt(CitySelected);

    //Change the height of the transparent tag
    switch (CitySelected) {
        case 'Northland':
            document.getElementById('PlaceFrame').style.height = '260px'; //
            document.getElementById('PlaceFrame').style.top = '50px'; //
            document.getElementById(CitySelected).style.top = '50px'; //
            break
        case 'BayOfPlenty':
            document.getElementById('PlaceFrame').style.height = '430px'; //
            document.getElementById('PlaceFrame').style.top = '100px'; //
            document.getElementById(CitySelected).style.top = '100px'; //
            break
        case 'Waikato':
            document.getElementById('PlaceFrame').style.height = '480px'; //
            document.getElementById('PlaceFrame').style.top = '100px'; //
            document.getElementById(CitySelected).style.top = '100px'; //
            break
        case 'Rotorua':
            document.getElementById('PlaceFrame').style.height = '340px'; //
            document.getElementById('PlaceFrame').style.top = '100px'; //
            document.getElementById(CitySelected).style.top = '100px'; //
            break
        case 'EastCoast':
            document.getElementById('PlaceFrame').style.height = '150px'; //
            document.getElementById('PlaceFrame').style.top = '100px'; //
            document.getElementById(CitySelected).style.top = '100px'; //
            break
        case 'LakeTaupo':
            document.getElementById('PlaceFrame').style.height = '150px'; //
            document.getElementById('PlaceFrame').style.top = '150px'; //
            document.getElementById(CitySelected).style.top = '150px'; //
            break
        case 'Taranaki':
            document.getElementById('PlaceFrame').style.height = '320px'; //
            document.getElementById('PlaceFrame').style.top = '150px'; //
            document.getElementById(CitySelected).style.top = '150px'; //
            break
        case 'HawkesBay':
            document.getElementById('PlaceFrame').style.height = '380px'; //
            document.getElementById('PlaceFrame').style.top = '100px'; //
            document.getElementById(CitySelected).style.top = '100px'; //
            break
        case 'Wanganui':
            document.getElementById('PlaceFrame').style.height = '410px'; //
            document.getElementById('PlaceFrame').style.top = '100px'; //
            document.getElementById(CitySelected).style.top = '100px'; //
            break
        case 'Wellington':
            document.getElementById('PlaceFrame').style.height = '880px'; //
            document.getElementById('PlaceFrame').style.top = '50px'; //
            document.getElementById(CitySelected).style.top = '50px'; //
            break
        case 'Wairarapa':
            document.getElementById('PlaceFrame').style.height = '220px'; //
            document.getElementById('PlaceFrame').style.top = '250px'; //
            document.getElementById(CitySelected).style.top = '250px'; //
            break
        case 'Nelson':
            document.getElementById('PlaceFrame').style.height = '480px'; //
            document.getElementById('PlaceFrame').style.top = '200px'; //
            document.getElementById(CitySelected).style.top = '200px'; //
            break
        case 'WestCoast':
            document.getElementById('PlaceFrame').style.height = '200px'; //
            document.getElementById('PlaceFrame').style.top = '300px'; //
            document.getElementById(CitySelected).style.top = '300px'; //
            break
        case 'Canterbury':
            document.getElementById('PlaceFrame').style.height = '900px'; //
            document.getElementById('PlaceFrame').style.top = '50px'; //
            document.getElementById(CitySelected).style.top = '50px'; //
            break
        case 'Queentown':
            document.getElementById('PlaceFrame').style.height = '400px'; //
            document.getElementById('PlaceFrame').style.top = '350px'; //
            document.getElementById(CitySelected).style.top = '350px'; //
            break
        case 'Otago':
            document.getElementById('PlaceFrame').style.height = '460px'; //
            document.getElementById('PlaceFrame').style.top = '200px'; //
            document.getElementById(CitySelected).style.top = '200px'; //
            break
        case 'Southland':
            document.getElementById('PlaceFrame').style.height = '380px'; //
            document.getElementById('PlaceFrame').style.top = '300px'; //
            document.getElementById(CitySelected).style.top = '300px'; //
            break
    }
}



function CloseWin(event) {

    //Get position of cursor
    pos_x = event.offsetX ? (event.offsetX) : event.pageX - document.getElementById("content").offsetLeft;
    pos_y = event.offsetY ? (event.offsetY) : event.pageY - document.getElementById("content").offsetTop;

    //Get coordinates of rectangle for layer if one is open
    if ((IsOpen != 'N') && (IsOpen != '') && (IsOpen != null)) {
        var LayerNm = IsOpen + 'Mp';
        var LayerCordinates = document.getElementById(LayerNm).getAttribute('coords').split(',', 4);
        var x1 = LayerCordinates[0];
        var x2 = LayerCordinates[2];
        var y1 = LayerCordinates[1];
        var y2 = LayerCordinates[3];
        var Clked;
        //Find out where they have clicked on the page
        if ((pos_x < x1) || (pos_x > x2)) {
            Clked = 'N';
        } else {
            if ((pos_y < y1) || (pos_y > y2)) {
                Clked = 'N';
            } else {
                Clked = 'Y';
            }
        }
        //Make sure they have clicked somewhere outside of the map rectangle, if they have then close the layers
        if (Clked == 'N') {
            hideIt(IsOpen);
        }
    }  
}


function PlaceCities() {

    //Place all the layers when the page loads

    placeIt('Northland');
    placeIt('BayOfPlenty');
    placeIt('Waikato');
    placeIt('Rotorua');
    placeIt('EastCoast');
    placeIt('LakeTaupo');
    placeIt('Taranaki');
    placeIt('HawkesBay');
    placeIt('Wanganui');
    placeIt('Wellington');
    placeIt('Wairarapa');
    placeIt('Nelson');
    placeIt('WestCoast');
    placeIt('Canterbury');
    placeIt('Queentown');
    placeIt('Otago');
    placeIt('Southland');
}

var IsOpen;
var y1 = 300;   // change the # on the left to adjuct the Y co-ordinate
(document.getElementById) ? dom = true : dom = false;

function hideIt(InTag) {
    IsOpen = 'N'
    if (dom) {
        document.getElementById(InTag).style.visibility = 'hidden';
        document.getElementById('PlaceFrame').style.visibility = 'hidden'; 
    }
}

function showIt(InTag) {
    IsOpen = InTag
    if (dom) {
        document.getElementById(InTag).style.visibility = 'visible';
        document.getElementById('PlaceFrame').style.visibility = 'visible';     
    }
}

function placeIt(InTag) {

    ////This part moves the frame so it stays in the same position when scrolling
    //if (dom && !document.all) { document.getElementById(InTag).style.top = window.pageYOffset + (window.innerHeight - (window.innerHeight - y1)) + "px"; }
    //if (document.all) { document.all[InTag].style.top = document.documentElement.scrollTop + (document.documentElement.clientHeight - (document.documentElement.clientHeight - y1)) + "px"; }
    //if (dom && !document.all) { document.getElementById('PlaceFrame').style.top = window.pageYOffset + (window.innerHeight - (window.innerHeight - y1)) + "px"; }
    //if (document.all) { document.all['PlaceFrame'].style.top = document.documentElement.scrollTop + (document.documentElement.clientHeight - (document.documentElement.clientHeight - y1)) + "px"; }
    
    window.setTimeout("placeIt('" + InTag + "')", 10);

}

function HeaderHighlight(btnName) {
    document.getElementById(btnName).className = "current";
}
