﻿var inprog = false;
var swedishFlagSrc = "";
var englishFlagSrc = "";

$(document).ready(function () {
    swedishFlagSrc = $("#swedish img").attr("src");
    englishFlagSrc = $("#english img").attr("src");

    $("#swedish").mouseover(function () { $("#swedish img").attr("src", "/Assets/Images/Layout/swe-on.jpg"); });
    $("#swedish").mouseout(function () { $("#swedish img").attr("src", swedishFlagSrc); });

    $("#english").mouseover(function () { $("#english img").attr("src", "/Assets/Images/Layout/en-on.jpg"); });
    $("#english").mouseout(function () { $("#english img").attr("src", englishFlagSrc); });

//    $("#menu .HasChildren, #menu .HasChildren a").mouseover(function () {
//        if ($(this).not("animated")) {
//            $(this).find(".sub").eq(0).stop(true, true).slideDown(400, function () {
//            });
//        }
//    });


//    $("#menu .HasChildren, #menu .HasChildren a").mouseout(function () {
//        if ($(this).find(".sub").not("animated")) {
//            $(this).find(".sub").eq(0).stop(true, true).slideUp(400, function () {
//            });
//        }
//    });


//    $("#menu .HasChildren .sub").mouseover(function () {
//        $(this).eq(0).stop(true, true);
//        $(this).show();
//    });

//    $("#menu .HasChildren .sub").mouseout(function () {
//        $(this).eq(0).stop(true, true);
//        $(this).hide();
//    });

    //    $("#menu .HasChildren").hover(function () {
    //        if (inprog == false) {
    //            inprog = true;
    //            openSubMenu(this);
    //        }
    //    }, function () {
    //        closeSubMenu(this);
    //    });
    //    

    $(".OpenHiddenDetails").click(function () { $('.HiddenDetails').show('slow'); });
    $(".CloseBtn").click(function () { $('.HiddenDetails').hide('slow'); });

    var apiScrollElement = $(".scroller div").scrollable({ keyboard: true, clickable: false, next: '.nextPage', prev: '.prevPage' });
    var apiScroll = apiScrollElement.data("scrollable");

    $(".CloseBtn").click(function () { $('.HiddenDetails').hide('slow'); });
});

function openSubMenu(control) {
    $(control).find(".sub").eq(0).slideDown(400, function () { });
}

function closeSubMenu(control) {
    $(control).find(".sub").eq(0).slideUp('slow', function () { });
    inprog = false;
}

function changeLargeImage(anchor, path, image) {
    $("#LargePic").attr("src", path + image);
}

function changeImage(anchor, image) {
    var path = "/Assets/Upload/Files/";
    $("#LargePic").attr("src", path + image);
}

function setLargeImage(path, image, text) {
    $("#LargePic").attr("src", path + image);

    if (text != null) {
        $("#PicDescription").html(text);
    }
}

myHtmlSettings = {
    nameSpace: "html", // Useful to prevent multi-instances CSS conflict
    onShiftEnter: { keepDefault: false, replaceWith: '<br />\n' },
    onCtrlEnter: { keepDefault: false, openWith: '\n<p>', closeWith: '</p>\n' },
    onTab: { keepDefault: false, openWith: '     ' },
    markupSet: [
        { name: 'Linebreak', key: 'R', replaceWith: '<br />' },
        { name: 'Paragraph', openWith: '<p(!( class="[![Class]!]")!)>', closeWith: '</p>' },
        { separator: '---------------' },
        { name: 'Bold', key: 'B', openWith: '<strong>', closeWith: '</strong>' },
        { name: 'Italic', key: 'I', openWith: '<em>', closeWith: '</em>' },
        { separator: '---------------' },
        { name: 'Picture', key: 'P', beforeInsert: function (h) { openImages(); } },
        { name: 'PdfLink', key: 'Y', beforeInsert: function (h) { openPdf(); } },
        { name: 'Link', key: 'L', openWith: '<a href="[![Link:!:http://]!]"(!( title="[![Title]!]")!)>', closeWith: '</a>', placeHolder: 'Your text to link...' },
        { separator: '---------------' },
        { name: 'Clean', replaceWith: function (h) { return h.selection.replace(/<(.*?)>/g, "") } },
        { name: 'Preview', call: 'preview', className: 'preview' }
    ]
}

function initializeMap(lat, long, name, adress, postalcode, city, phone, email) {
    $('.HiddenDetails').show('slow');

    var myLatlng = new google.maps.LatLng(lat, long);

    var options = {
        zoom: 16,
        center: myLatlng,
        panControl: false,
        zoomControl: true,
        mapTypeControl: false,
        scaleControl: true,
        streetViewControl: false,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var contentString = '<div id="mapcontent">' +
    '<h3>' + name + '</h3>' +
    '<p>' + adress + '</p>' +
    '<p>' + postalcode + ' ' + city + '</p>' +
    '<p>' + phone + '</p>' +
    '<p><a href=\'mailto:' + email + '\'>' + email + '</a></p>' +
    '</div>';

    var infowindow = new google.maps.InfoWindow({
        content: contentString
    });

    var map = new google.maps.Map(document.getElementById("map"), options);
    var marker = new google.maps.Marker({ position: myLatlng, map: map });
    infowindow.open(map, marker);
    google.maps.event.trigger(map, 'resize');
    map.setZoom(map.getZoom());
}
