/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function initializeMap() {
    var aachen = new google.maps.LatLng(50.7679519653, 6.09187602997);
    var mapOptions = {
        zoom: 14,
        scrollwheel: false,
        center: aachen,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById('map'), mapOptions);
    
    var marker = new google.maps.Marker({
        position: aachen,
        map: map,
        title: 'STAWAG Wettersäule'
    });
}

var wasOpen = false;

$(document).ready(function(){
  $('#logo').click(function(){
    var href = $(this).parent().attr('href');
    window.open(href);
    return false;
  });
    $('#parallax').parallax({
        'elements': [
        {
            'selector': 'div.cloud1',
            'properties': {
                'x': {
                    'background-position-x': {
                        'initial': 150,
                        'multiplier': 0.01,
                        'invert': true
                    }
                }
            }
        },
        {
            'selector': 'div.cloud2',
            'properties': {
                'x': {
                    'background-position-x': {
                        'initial': 0,
                        'multiplier': 0.02,
                        'invert': true
                    }
                }
            }
        },
        {
            'selector': 'div.cloud3',
            'properties': {
                'x': {
                    'background-position-x': {
                        'initial': 150,
                        'multiplier': 0.03,
                        'invert': true
                    }
                }
            }
        },
        {
            'selector': 'div.cloud4',
            'properties': {
                'x': {
                    'background-position-x': {
                        'initial': 0,
                        'multiplier': 0.04,
                        'invert': true
                    }
                }
            }
        }
        ]
    });
    
    $('div#header-outer ul li:first, div#marginal ul li:first').addClass('first');
    $('div#header-outer ul li:last, div#marginal ul li:last').addClass('last');

    $('p#place span, #close-map').click(function(){
        $('#map').slideToggle('fast', function(){
            if(wasOpen == false) {
                wasOpen = true;
                initializeMap();
            }
            $('#close-map-outer').fadeToggle();
        });
        
        $('#page-overlay').fadeToggle();
    });

    $('div.image-tabs').each(function(){
        $(this).children('span.title').each(function(){
            var tabTitle = $(this).text();
            $(this).parent().children('ul.image-tabs-navi').append('<li>'+tabTitle+'</li>');
            $(this).remove();
        });
    });

    $('ul.image-tabs-navi li:first').addClass('active');

    $('div.image-tabs img').hide();
    $('div.image-tabs img:first').show();

    $('.image-tabs-navi li').click(function(){
        var index = $(this).index();
        $('div.image-tabs img').hide();
        $('div.image-tabs img').eq(index).show();

        $('ul.image-tabs-navi li').removeClass('active');
        $(this).addClass('active');
    });

    $('table tr:first').addClass('head');
    $('table tr:even:not(.head)').addClass('odd');

    $('.open-today').click(function(){
        $(this).toggleClass('open');
        $('#more-forecast').toggle();
        $(this).parent().toggleClass('large');
        $(this).parent().toggleClass('medium');
    });
});

