﻿/**
* Copyright 2009 SamynReid 
*/

//hovers
$(document).ready(function() {
    $(".hover").imghover({ prefix: '/hover' });
    
    //preload navigation hovers
    //@TODO: create this list dynamically on build time?
    $.preloadImages(
	      "/i/nav/hover/about.gif"
	    , "/i/nav/hover/comment.gif"
	    , "/i/nav/hover/contact.gif"
	    , "/i/nav/hover/home.gif"
	    , "/i/nav/hover/investments.gif"
	    , "/i/nav/hover/news.gif"
	    , "/i/nav/hover/team.gif"
	    , "/i/nav/hover/work.gif"
	    );
});

jQuery.preloadImages = function() {
    for (var i = 0; i < arguments.length; i++) {
        jQuery("<img>").attr("src", arguments[i]);
    }
}

//Google maps stuff copied from Speeed: @TODO: move in generic lib
function LocationPoint(name, gLatLng, html) {
    this.Name = name;
    this.GLatLng = gLatLng;
    this.Html = html;
}
function CreateMarker(map, number) {
    var loc = locations[number];
    var pin = new GIcon();
    pin.image = '/i/google_pin.gif';
    pin.iconSize = new GSize(20, 34);
    pin.shadow = "/i/google_pin_shadow.png";
    pin.shadowSize = new GSize(31, 35);
    pin.iconAnchor = new GPoint(5, 34);
    pin.infoWindowAnchor = new GPoint(5, 2);
    pin.transparent = "/i/google_pin_trans.png";
    pin.imageMap = [9, 0, 6, 1, 4, 2, 2, 4, 0, 8, 0, 12, 1, 14, 2, 16, 5, 19, 7, 23, 8, 26, 9, 30, 9, 34, 11, 34, 11, 30, 12, 26, 13, 24, 14, 21, 16, 18, 18, 16, 20, 12, 20, 8, 18, 4, 16, 2, 15, 1, 13, 0];

    var options;
    if (loc.Html) {
        options = { title: loc.Name/*, icon: pin*/ };
    } else {
        options = { title: loc.Name/*, icon: pin*/,clickable: false };
    }
    var marker = new GMarker(loc.GLatLng, options);
    marker.value = number;
    if (loc.Html) {
        GEvent.addListener(marker, "click", function() {
            jQuery('#addressContent').html(loc.Html);
        });
    }
    return marker;
}
function GoogleMapInit(mapId, locations, mapCenter, mapZoom) {
    //initialise map
    jQuery(mapId).jmap(
		'init', {
		    'mapType': 'map'
			, 'mapCenter': mapCenter
			, 'mapZoom': mapZoom
			, 'mapEnableType': true
			, 'mapEnableOverview': false
			, 'mapEnableScaleControl': true
			, 'mapShowjMapsIcon': false
			, 'mapControl': 'large'
		},
		function(map, element, options) {
		    for (i in locations) {
		        map.addOverlay(CreateMarker(map, i));
		    }
		});
}
