var documentOriginalHeight;
var documentExpandedHeight;

$(document).ready(function() {

    /* JS replace href="#" with javascript:void(0) */

    $('a').each(function() {
        if($(this).attr('href') == '#') {
            $(this).attr('href', 'javascript:void(0);');
        }
    });

    $('.slideToggle').toggle(function() {
        $('#moreCourseInfo').slideDown('fast', function() {
            $('.slideToggle').html('Dölj');
            //resizePageElements('expand');
        });
    }, function() {
        $('#moreCourseInfo').slideUp('fast', function() {
            $('.slideToggle').html('Läs mer');
            //resizePageElements('restore');
        });
    });

    $('#top #menu ul li').hover(function() {
        $(this).addClass('hoverIn');
    }, function () {
        $(this).removeClass('hoverIn');
    });

    $('#registerEmail').click(function() {
        if($(this).val() === 'E-postadress') {
            $(this).val('');
        }
    });

    $('#registerEmail').blur(function() {
        if($(this).val() == '') {
            $(this).val('E-postadress');
        }
    })

    $('.popup').live('click', function() {
        var url = $(this).attr('url');
        var size = $(this).attr('size').split('x');
        var title = "Bild";
	var posx = (screen.width - size[0]) / 2;
	var posy = (screen.height - size[1]) / 2;
        window.open(url, title, 'toolbars=0,scrollbars=1,location=0,statusbars=0,menubars=0,resizable=0,width='+size[0]+',height='+size[1]+',left='+posx+',top='+posy);
    });

    $('#citySelector').change(function() {
        $('#citySelectorForm').submit();
    });

    documentOriginalHeight = $(document).height();
    documentExpandedHeight = 0;
    //resizePageElements();

});

function center_elem(id, offsetX, offsetY)
{
    var w = $('#'+id).width();
    var h = $('#'+id).height();
    var top = ($(window).height() - h) / 2 + $(window).scrollTop() - offsetY;
    var left = ($(window).width() - w) / 2 + $(window).scrollLeft() - offsetX;
    $('#'+id).css({ 'left' : left, 'top' : top});
}

