//
// mainNav animation
//

var site = function() {
	this.navLi = $('#mainNav li').children('ul').hide().end();
	this.init();
};

site.prototype = {

 	init : function() {
 		this.setMenu();
 	},

 	// Enables the slidedown menu, and adds support for IE6

 	setMenu : function() {

 	$.each(this.navLi, function() {
 		if ( $(this).children('ul')[0] ) {
 			$(this).append('<span class="hasChildren" />');
 		}
 	});

    $.each(this.navLi, function() {
 		if ( $(this).children('ul')[0] ) {
 			$(this).addClass('wide');
 		}
 	});

 		this.navLi.hover(function() {
 			// mouseover
			$(this).find('> ul').stop(true, true).slideDown(1500, 'easeOutBounce');
 		}, function() {
 			// mouseout
 			$(this).find('> ul').stop(true, true).hide();
		});

 	}

}


new site();


//////
// z-index fix for IE 6 & 7
//////

$(document).ready(function(){

        $("#mainNav").parents().each(function() {
            var p = $(this);
            var pos = p.css("position");
 
            // If it's positioned,
            if(pos == "relative" ||
               pos == "absolute" ||
               pos == "fixed")
            {
                /*
                ** Add the "on-top" class name when the
                ** mouse is hovering over it, and remove
                ** it when the mouse leaves.
                */
                p.hover(function() {
                        $(this).addClass("on-top");
                    },
                    function() {
                        //$(this).removeClass("on-top");
                    });
            }
        });

});

//
// Featured Slider
//
        $(function() {
            $('#featured_image').cycle({
            fx:     'fade',
            speed:	3000,
            timeout: 10000,
            delay:  -2000,
            next:   '#featured_btn_next',
            prev:   '#featured_btn_prev',
            pause:   1
            });
        });





// GOOGLEMAPS

/* jQuery googleMap Copyright Dylan Verheul <dylan@dyve.net>
 * Licensed like jQuery, see http://docs.jquery.com/License
 */

$(document).ready(function() {
    $("#googlemaps").googleMap(52.062168, 4.269476, 15, {
        controls: ["GSmallMapControl", "GMapTypeControl"],
        markers: $(".geo")
    });
    // Example to access the map object is below:
    // $.googleMap.maps["map1"].setMapType(G_SATELLITE_TYPE);
});

$.googleMap = {
maps: {},
marker: function(m) {
    if (!m) {
        return null;
    } else if (m.lat == null && m.lng == null) {
        return $.googleMap.marker($.googleMap.readFromGeo(m));
    } else {
        var marker = new GMarker(new GLatLng(m.lat, m.lng));
        if (m.txt) {
            GEvent.addListener(marker, "click", function() {
                marker.openInfoWindowHtml(m.txt);
              });
        }
        return marker;
    }
},
readFromGeo: function(elem) {
    var latElem = $(".latitude", elem)[0];
    var lngElem = $(".longitude", elem)[0];
    if (latElem && lngElem) {
        return { lat:parseFloat($(latElem).attr("title")), lng:parseFloat($(lngElem).attr("title")), txt:$(elem).attr("title") }
    } else {
        return null;
    }
},
mapNum: 1
};

$.fn.googleMap = function(lat, lng, zoom, options) {

// If we aren't supported, we're done
if (!window.GBrowserIsCompatible || !GBrowserIsCompatible()) return this;

// Default values make for easy debugging
if (lat == null) lat = 52.062168;
if (lng == null) lng = 4.269476 ;
if (!zoom) zoom = 12;

// Sanitize options
if (!options || typeof options != 'object')	options = {};
options.mapOptions = options.mapOptions || {};
options.markers = options.markers || [];
options.controls = options.controls || {};

// Map all our elements
return this.each(function() {
    // Make sure we have a valid id
    if (!this.id) this.id = "gMap" + $.googleMap.mapNum++;
    // Create a map and a shortcut to it at the same time
    var map = $.googleMap.maps[this.id] = new GMap2(this, options.mapOptions);
    // Center and zoom the map
       map.setCenter(new GLatLng(lat, lng), zoom);
       // Add controls to our map
       for (var i = 0; i < options.controls.length; i++) {
           var c = options.controls[i];
           eval("map.addControl(new " + c + "());");
       }
       // If we have markers, put them on the map
       var marker = null;
       for (var i = 0; i < options.markers.length; i++) {
           if (marker = $.googleMap.marker(options.markers[i])) map.addOverlay(marker);
       }
});

};

