$(document).ready(function() {
    /*SLIDESHOW*/
    $("#bp_nav").empty();
    $('#bigpush .bp_content').cycle({
        fx: 'scrollHorz',
        speed: 500,
        timeout: 10000,
        pager: '#bp_nav',
        pagerAnchorBuilder: function(idx, slide) {
            // return selector string for existing anchor
            return '<li><a href="#"></a></li>';
        }
    });

    /*If IE7+, inject top-corners on subpages*/
    if ($.browser.msie && (parseInt(jQuery.browser.version)) > 6) {
        $('#top_subpage').append('<div id="bp_nw_corner"></div><div id="bp_ne_corner"></div>');
        $('#footer').append('<div id="bp_sw_corner"></div><div id="bp_se_corner"></div>');
    }

    $('#news-slide').cycle({
        fx: 'scrollVert',
        prev: '.news-nav .next',
        next: '.news-nav .prev',
        speed: 200,
        //    after: onAfter,
        timeout: 0
    });
    /*  function onAfter(curr, next, opts) {
    var index = opts.currSlide;
    $('.news-nav .prev')[index == 0 ? 'hide' : 'show']();
    $('.news-nav .next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
    } */

    $(".reference a").hover(function() {
        image = $(this).find("img").attr("src");
        image2 = $(this).find("img").attr("ref");
        imgExt = image.match(".jpg|.gif|.png")
        imgSrc = image.split(imgExt)[0];
        $(this).find("img").attr("src", image2); //imgSrc + '_1' + imgExt);
    }, function() {
        $(this).find("img").attr("src", imgSrc + imgExt);
    });

    // Google Map Coords
    // Start Cords
    if ($('#map').length) {
        $('#map').googleMaps({
            latitude: 59.316325, //std "nacka" = 59.316325-18.16083
            longitude: 18.16083, //std "nacka"
            depth: 14,
            markers: {
                latitude: 59.316325, //std "nacka"
                longitude: 18.16083 //std "nacka"
            }
        });

        /*Cords onClick */
        $("a.map_pos").click(function() {
            map_pos = $(this).attr("id");
            map_cords = map_pos.split("-");
            map_lat = map_cords[0];
            map_long = map_cords[1];

            $('#map').googleMaps({
                depth: 14,
                latitude: map_lat,
                longitude: map_long,
                markers: {
                    latitude: map_lat,
                    longitude: map_long
                }
            });
        });
    }
});
