/***************************************************************
 * JavaScript effects for http://raphael.kallensee.name        *
 *                                                             *
 * (c) 2009 Raphael Kallensee                                  *
 *                                                             *
 * This site uses the mootools framework (http://mootools.net) *
 * which is available under the MIT license.                   *
 *                                                             *
 * Feel free to use my code under the CC-BY-SA license         *
 * http://creativecommons.org/licenses/by-sa/3.0/deed.de       *
 ***************************************************************/

$(document).ready(function() {
    
    // navigation overglow
    $("#navigation li").each( function( i ) {
        if( !$(this).hasClass('active') ) {
            $(this).children('a').mouseover( function() {
                $(this).css('background-color', '#333333');
                $(this).animate({
                    backgroundColor: '#666666'
                }, 300, 'swing' );
            }).mouseout( function() {
                $(this).animate({
                    backgroundColor: '#333333'
                }, 300, 'swing', function() {
                    $(this).css('background-color', 'transparent');
                });
            });
        }
    });
    
    // noticebox shake effect
    $('#content .noticebox').each( function( i ) {
        $(this).effect( 'shake', {}, 100, function() {} );
    });
});

$(window).load( function() {
    
    if( $('#osmapWrapper').size() > 0 
     && $('#osmap').size() > 0 
    ) {
        var lat=49.48135;
        var lon=8.480419999999999;
        var mlat=49.479645;
        var mlon=8.483941;
        var zoom=15;

        var map;
        
        map = new OpenLayers.Map( "osmap", {
            controls:[
                new OpenLayers.Control.Navigation(),
                new OpenLayers.Control.PanZoomBar(),
                new OpenLayers.Control.Attribution()],
            maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
            maxResolution: 156543.0399,
            numZoomLevels: 19,
            units: 'm',
            projection: new OpenLayers.Projection("EPSG:900913"),
            displayProjection: new OpenLayers.Projection("EPSG:4326")
        } );

        layerTilesAtHome = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
        map.addLayer(layerTilesAtHome);
        
        layerMarkers = new OpenLayers.Layer.Markers("Markers");
	    map.addLayer(layerMarkers);

        var lonLat = new OpenLayers.LonLat(mlon, mlat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
	    map.setCenter (lonLat, zoom);

	    var size = new OpenLayers.Size(21,25);
	    var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
	    var icon = new OpenLayers.Icon('http://openlayers.org/api/img/marker-gold.png',size,offset);
	    layerMarkers.addMarker(new OpenLayers.Marker(lonLat,icon));
        
        
        // add slide effect to osm map
        
        $('#osmapWrapper').slideUp();
        
        if( $('#osmap-hint-open-link').size() > 0  ) {
            $('#osmap-hint-open-link').click( function( e ) {
                $('#osmapWrapper').slideDown();
                $('#osmap-hint-open-link').hide();
                
                if( $('#osmap-hint-close-link') != null ) {
                    $('#osmap-hint-close-link').show();
                }
                return false;
            });
        }
        
        if( $('#osmap-hint-close-link').size() > 0  ) {
            $('#osmap-hint-close-link').click( function( e ) {
                $('#osmapWrapper').slideUp();
                $('#osmap-hint-close-link').hide();
                
                if( $('#osmap-hint-open-link') != null ) {
                    $('#osmap-hint-open-link').show();
                }
                return false;
            });
        }
    }
    
});


