
var locations = {};
function addLoc(name,lat,lon,zoom,maptype,dirs){
    locations[name] = {'id':name,'lat':lat,'lon':lon,'zoom':zoom,'maptype':maptype,'dirs':dirs};
}

addLoc  ('sydney',          -33.824555,    151.198824,    14,    '',    '38 Oxley Street St Leonards NSW 2065 Sydney, Australia');
addLoc  ('perth',           -31.951238,    115.837108,    14,    '',    'Suite 7, 44 Kings Park Rd West Perth WA 6005 Australia');
addLoc  ('sydneyservice',   -33.927587,    150.93320,     14,    '',    '6 Bridges Road Moorebank NSW 2170 Australia');
addLoc  ('melbourne',       -38.352107,    144.289756,    14,    '',    '30 Ocean Blvd  Jan Juc VIC 3228 Australia');
addLoc  ('newcastle',       -32.928265,    151.784749,    14,    '',    '45 Hunter St Newcastle NSW 2300 Australia');
addLoc  ('belgium',          50.828697,    4.362388,      14,    '',    'Avenue Louise, 149/24 Brussels 1050 Belgium');
addLoc  ('beijing',          39.984585,    116.40152,14,  14,    '',    'No 33 Anding Rd, Chaoyang District Beijing 100029');
addLoc  ('qingdao',          36.31506,     120.41276,     14,    '',    '103 Chunyang Road Chengyang District Qingdao, 266109 China');
addLoc  ('baroda',           22.293097,    73.166514,     14,    '',    'Akota Garden Rd Vadodara, India');
addLoc  ('hyderabad',        17.443364,    78.482519,     14,    '',    'S.P. Road Begumpet 500016 Hyderabad , Andhra Pradesh India');
addLoc  ('seoul',            37.561044,    127.063236,    14,    '',    'sunae-dong 16-5,Bundang-Gu, Sungnam City Kyunggi-Do, Korea');
addLoc  ('cottrell',         36.951401,    127.279701,    14,    '',    'Anseong City, 456-853,Korea');
addLoc  ('dubai',            25.261658,    55.373454,     14,    '',    'Abu Hali Rd, United Arab Emirates');
addLoc  ('malaysia',         3.510508,     101.629951,    14,    '',    'No. 1, Jalan Zurah 5A/1 Pussat Perindustrian Zurah Rassa Selangor 4200 Darul Ehsan, Malaysia');
addLoc  ('singapore',        1.329677,     103.874316,    14,    '',    '190 MacPherson Road , 348548 Singapore');



$(function(){
        $(".location .map").click(function(e){
                var loc = locations[$(this).parent().parent().attr('id')];
                load2(loc);
                return false;
        }
    );
});



function switchto(item){
    //$("#placename").html(item.id);
    
    $("#placename").html($('#'+item.id +" .sub-title-org").html());
    var addrinf = $('#'+item.id ).not("a").html() + "<br/>"; 
    
    
    
    $("#addressinfo").html(addrinf);
    $("#addressinfo .icon-env").remove();
    $("#addressinfo .sub-title-org").remove();
    $("#addressinfo br:first,#addressinfo br:last").remove();
    
    if(item.id=="singapore")
    $("#addressinfo p:last").remove();
    
    
    $("#addressinfo .sub-title-org").css("color","blue");
    
    $("#d_daddr").val(item.dirs);
   
}







function switchid(id) {
    hideallids();
    showdiv(id);
}

function hideallids() {
    //loop through the array and hide each element by id
    for (var i = 0; i < ids.length; i++) {
        hidediv(ids[i]);
    }
}

function hidediv(id) {
    //safe function to hide an element with a specified id
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'none';
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = 'none';
        }
        else { // IE 4
            document.all.id.style.display = 'none';
        }
    }
}

function showdiv(id) {
    //safe function to show an element with a specified id

    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'block';
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = 'block';
        }
        else { // IE 4
            document.all.id.style.display = 'block';
        }
    }
}


//latitudes
var lat = new Array(
						-33.824555,
						-33.927587,
						0, //-33.933159, //hiding workshop
						-38.352107,
						-31.951238,
						-23.328878,  /*duplicates.. fix*/

						50.828697,
						39.984585,
						36.31506,
						22.293097,
						37.376906,
						0,
						1.329677,
						25.261658,
            					1.329677         //singapore second address
				);
//longitudes
var lng = new Array(
						151.198824,
						150.93320,
						0, //150.94084, //hiding workshop
						144.289756,
						115.837108,
						150.509219,  /*matching duplicates*/

						4.362388,
						116.40152,
						120.41276,
						73.166514,
						127.113517,
						0,
						103.874316,
						55.373454,
            					103.874316            //singapore second address
);

//names
var nm = new Array(
						'Sydney Head Office',
						'Sydney Service Centre',
						'Sydney Workshop',
						'Melbourne',
						'Perth',
						'Queensland',

						'Jord International s.p.r.l',
						'Beijing Office',
						'Qingdao Office',
						'Jord International Pvt Ltd',
						'Jord KC Co. Ltd',
						'Jord Malaysia Sdn Bhnd',
						'Jord International Pte Ltd',
						'Executive Suite Y-36',
						'Jord Asia Pte Ltd'
					);

//addresses
var adr = new Array(
						'38 Oxley Street<br/>St Leonards NSW 2065<br/>Sydney, Australia',
						'6 Bridges Road<br/>Moorebank NSW 2170<br/>Australia',
						'21 Iraking Avenue<br/>Moorebank NSW 2170<br/>Australia',
						'30 Ocean Blvd <br/>Jan Juc VIC 3228<br/>Australia',
						'Suite 7, 44 Kings Park Rd<br/>West PerthWA 6005<br/>Australia',
						'Shed 1/82 McLaughlin St<br/>North Rockhampton QLD 4701<br/>Australia',

						'Avenue Louise, 149/24<br/>Brussels 1050<br/>Belgium',
						'Jord International China Co. Ltd. Beijing Branch<br/>Room 308, Huaxin Mansion Block A, No. 33 Anding Rd<br/>Chaoyang District, Beijing 100029<br/>China',
						'103 Chunyang Road<br/>Chengyang District<br/>Qingdao, 266109<br/>China',
						'Nitya, Akota Garden Rd<br/>Vadoodara 390020<br/>India',
						'609 Owner`s Tower<br/>Soonae-Dong 16-5<br/>Bundang-Gu, Seongnam City<br/>Kyunggi-Do, Korea',
						'No. 1, Jalan Zurah 5A/1<br/>Pussat Perindustrian Zurah<br/>Rassa Selangor 4200<br/>Darul Ehsan, Malaysia',
						'Unit #09-02<br/>190 MacPherson Road<br/>Wisma Gulab, 348548<br/>Singapore',
						'Jord International Pte (Branch)<br/>P.O Box 54927<br/>Building 4W, A Block, G-01<br/>DAFZA (Dubai Airport Free Zone Authority)<br/>Dubai, U.A.E.',
						'Unit #09-02<br/>190 MacPherson Road<br/>Wisma Gulab, 348548<br/>Singapore'
					);


var dirs = new Array(
						'38 Oxley Street St Leonards NSW 2065 Sydney, Australia',
						'6 Bridges Road Moorebank NSW 2170 Australia',
						'21 Iraking Avenue Moorebank NSW 2170 Australia',
						'30 Ocean Blvd  Jan Juc VIC 3228 Australia',
						'Suite 7, 44 Kings Park Rd West PerthWA 6005 Australia',
						'82 McLaughlin St QLD 4701 Australia',

						'Avenue Louise, 149/24 Brussels 1050 Belgium',
						'No 33 Anding Rd, Chaoyang District Beijing 100029',
						'103 Chunyang Road Chengyang District Qingdao, 266109 China',
						'Nitya, Akota Garden Rd Vadoodara 390020 India',
						'',
						'No. 1, Jalan Zurah 5A/1 Pussat Perindustrian Zurah Rassa Selangor 4200 Darul Ehsan, Malaysia',
						'190 MacPherson Road , 348548 Singapore',
						'Abu Hali Rd, United Arab Emirates',
						'190 MacPherson Road , 348548 Singapore'
					);


var mapsloaded = 0;
var lastpoint;
var map;
var zoomlevel = 0;


function switchdetails(index) {

    document.getElementById('placename').innerHTML = nm[index];
    document.getElementById('addressinfo').innerHTML = nm[index] + " <br/> <br/>" + adr[index] + "<br/>";
    document.getElementById('d_daddr').value = dirs[index];
    if (dirs[index] == '') {
        hidediv('d_sub');
    } else {
        showdiv('d_sub');
    }
}
function load2(item){

    function placemarkers() {

            var point = new GLatLng(item.lat, item.lon);
            map.addOverlay(createMarker(point, 1));


    }
    if (GBrowserIsCompatible()) {
        if (!mapsloaded) {
            popup_show('gmap', 'gmap-drag', 'gmap-exit', 'screen-center', 10, 10);
        } else {
            popup_show('gmap', 'gmap-drag', 'gmap-exit', 'last-location', 10, 10);
        }
        var point = new GLatLng(item.lat,item.lon);
        if (!mapsloaded) {
            map = new GMap2(document.getElementById("map"));
            map.addControl(new GSmallZoomControl());
        }
        var baseIcon = new GIcon();
        baseIcon.shadow = "images/blueshadow.png";
        baseIcon.iconSize = new GSize(72, 60);
        baseIcon.shadowSize = new GSize(103, 60);
        baseIcon.iconAnchor = new GPoint(2, 60);
        baseIcon.infoWindowAnchor = new GPoint(29, 2);
        baseIcon.infoShadowAnchor = new GPoint(38, 2);
        baseIcon.image = "images/bluemarker.png";

        function createMarker(point, index) {
            var myIcon = new GIcon(baseIcon);
            // Set up our GMarkerOptions object
            markerOptions = { icon: myIcon };
            var marker = new GMarker(point, markerOptions);
            //GEvent.addListener(marker, "click", function () { marker.openInfoWindowHtml("<span style='color:#000;'>" + nm[index] + "</span>"); switchdetails(index); });
            return marker;
        }


        switchto(item);


        //map.returnToSavedPosition();


        if (mapsloaded) {
            //  zoomlevel = map.getZoom();
            //    if(zoomlevel > 13){zoomlevel = 13;}
            //     map.setZoom(zoomlevel);
            //     zoomlevel = goZoomOut(zoomlevel);
            if (item.maptype == "sat") {
                map.setMapType(G_HYBRID_MAP);
            } else {
                map.setMapType(G_NORMAL_MAP);
            }
            map.setZoom(item.zoom);
            map.panTo(point);

        }
    }
    if (!mapsloaded) {
        lastpoint = point;

        mapsloaded = 1;
        map.setCenter(lastpoint, item.zoom);

    }

        placemarkers();
        if (item.maptype == "sat") {
            map.setMapType(G_HYBRID_MAP);
        } else {
            map.setMapType(G_NORMAL_MAP);
        }
        zoomlevel = item.zoom;
        map.savePosition();




}

