﻿var haliInfo = null;
var latLongList = null;
var lat = null;
var lon = null;
var divMap = null;
var clientID = null;
var selectorImg = null;
var selectorObject = null;
var hasOffset = true;
var activeElement = null;
var center;
var myTimer = null;
var select = null;
var haliInfo = null;


var latMin = null; //get minimal latitude value from code behind
var latMax = null; //get minimal latitude value from code behind
var lonMin = null; //get minimal latitude value from code behind
var lonMax = null; //get minimal latitude value from code behind

//calculation for map ceter according to mLat i mLon formulas
var mLat = (latMax - latMin) / 2 + latMin;
var mLon = (lonMax - lonMin) / 2 + lonMin;
var splitBy = null;
var wrapper = null;
/**
slider startpage
**/
function startPageInit(selector, d, select) {
    $(document).ready(function () {
        //myTimer = window.setTimeout("startFadeOut()", 5000);

        resizeContainer($(selector).get(0).getElementsByTagName('div')[0]);
        $(selector).splitUp(1, '<div />').cycle({
            fx: 'scrollLeft',
            timeout: rotationTimeOut,
            pager: '#imgBtn',
            speed: 1500,
            cleartype: true,  // true if clearType corrections should be applied (for IE) 
            cleartypeNoBg: true,


            pagerAnchorBuilder: function (idx, slide) {
                return '<li><a href="#"><img src="' + imgPath + 'Transparent.gif" width="13" height="20" /></a></li>';
            },
            onPagerEvent: function (zeroBasedSlideIndex, slideElement) {
                $(select).css("overflow", "hidden");
                resizeContainer(slideElement, select)
                nextPrevSlideEvent(slideElement);
            },
            onPrevNextEvent: function (isNext, zeroBasedSlideIndex, slideElement) {
                $(select).css("overflow", "hidden");
                resizeContainer(slideElement, select)
                nextPrevSlideEvent(slideElement);
            },
            after: function (currSlideElement, nextSlideElement, options, forwardFlag) {
                $(select).css("overflow", "hidden");
                resizeContainer(nextSlideElement, select)
                nextPrevSlideEvent(nextSlideElement);
            }
        });
    });
}

/**
fade out
**/
function startFadeOut() {
    window.clearTimeout(myTimer);
    //$(selector).fadeOut(1000)
}

function resizeContainer(nextSlideElement, select) {
    if (nextSlideElement) {
        //image
        obj = nextSlideElement.getElementsByTagName("img")[0];
        addHeight = 0
        if (!obj) {
            //video
            obj = nextSlideElement.getElementsByTagName("object")[0];
            if (hasOffset)
                addHeight = 100;
        }

        if (obj) {
            newHeight = $(obj).height() + addHeight
            $(select).animate({ height: newHeight }, 'slow');
        }
    }
}

/**
call back for start page slider changed
**/
function nextPrevSlideEvent(slideElement) {
    //stop/start video
    stopPreviousVideo(activeElement)
    startVideo(slideElement)
    activeElement = slideElement;
}

/**
auto start for movie
**/
function startVideo(elem) {
    myPlayer = elem.getElementsByTagName("object")[0];
    if (myPlayer) {

        if (myPlayer != null && myPlayer.id.indexOf("_true") > -1) {
            jwplayer(myPlayer.id).play(true);
        }
    }
}

/**
if you slide elements than you have to stop previous video
**/
function stopPreviousVideo(elem) {
    if (elem != null) {
        myPlayer = elem.getElementsByTagName("object")[0];
        if (myPlayer != null) {
            jwplayer(myPlayer.id).stop();
        }
    }
}

/**
pager spliter
**/
if (splitBy !== null && wrapper !== null)
{
    $.fn.splitUp = function (splitBy, wrapper) {
    $all = $(this).find('>*');
    var fragment = Math.ceil($all.length / splitBy);
    for (i = 0; i < fragment; i++)
        $all.slice(splitBy * i, splitBy * (i + 1)).wrapAll(wrapper);
    return $(this);
    }
} 

function pageInit(selector, loadGoogleMaps) {
    $(document).ready(function () {
        if (loadGoogleMaps)
            load('1');
    });
}

function pageInit2(loadGoogleMaps, lat, lon) {
    $(document).ready(function () {
        if (loadGoogleMaps)
            load1('1', lat, lon, haliInfo);
    });
}

/**
Mobile highlight
**/
function highLight(el) {
    el.src = "/Images/Mobile/Navigation/arrow-right-on.gif";
    el.onmouseout = function () {
        el.src = "/Images/Mobile/Navigation/arrow-right.gif";
    }
}

function switchFantasticMobile(el, isActive) {
    el.src = (isActive)
        ? "/Images/Mobile/Fantastic/fantastic-" + el.id + "-on.gif"
        : "/Images/Mobile/Fantastic/fantastic-" + el.id + ".gif";
}

function switchLanguage(el, isActive, lng) {
    el.src = (isActive)
        ? "/Images/Navigation/" + el.id + lng + "-on.gif"
        : "/Images/Navigation/" + el.id + lng + ".gif";
}

function switchSocialImage(el, isActive) {
    el.src = (isActive)
        ? "/Images/Mobile/Social/icon-" + el.id + "-on.png"
        : "/Images/Mobile/Social/icon-" + el.id + ".png";
}

/**
Switch div
**/


function switchDivReferenze(showId, hideId) {
    switchDiv(showId, hideId);
    if (showId == "Image") {
        document.getElementById("lnkImg").className += ' active';
        document.getElementById("lnkList").className = 'listView referenze';
    }
    else {
        document.getElementById("lnkImg").className = 'imageView referenze';
        document.getElementById("lnkList").className += ' active';
    }
}

function switchDivKontakt(showId, hideId) {
    switchDiv(showId, hideId);
    if (showId == "mainRepeater") {
        document.getElementById("lnkImg").className += ' active';
        document.getElementById("lnkList").className = 'listView kontakt';
    }
    else {
        document.getElementById("lnkList").className += ' active';
        document.getElementById("lnkImg").className = 'imageView';
    }
}

function switchDivProdukt(showId, hideId) {
    switchDiv(showId, hideId);
    if (showId == "Image") {
        document.getElementById("lnkImg").className += ' active';
        document.getElementById("lnkList").className = 'listView';
    }
    else {
        document.getElementById("lnkList").className += ' active';
        document.getElementById("lnkImg").className = 'imageView produkt';
    }
}

/**
Toggle item
**/
function toggleItem(itemId) {
    var item = document.getElementById(itemId);
    if (item.className == 'hide') {
        item.className = 'show';
    }
    else {
        item.className = 'hide';
    }
}


/**
GOOGLE Maps one location
**/

var map1 = null;
var geocoder1 = null;
var contextmenu1;
function load1(loc1, lat, lon, haliInfo) {
    if (GBrowserIsCompatible()) {
        var point1;
        map1 = new GMap2(document.getElementById("map"));

        //map1.addControl(new GOverviewMapControl());
        map1.enableDoubleClickZoom();
        map1.enableScrollWheelZoom();
        map1.addControl(new GMapTypeControl());
        map1.addControl(new GLargeMapControl());
        createContextMenu1(map1);
        var address1 = haliInfo;
        point1 = new GLatLng(lat, lon);
        var center = new GLatLng(lat, lon);

        var myIcon1 = new GIcon();
        myIcon1.image = '/Images/googleMarker/icon.png';
        myIcon1.shadow = '/Images/googleMarker/icon_shadow.png';
        myIcon1.iconSize = new GSize(68, 95);
        myIcon1.shadowSize = new GSize(144, 97);
        myIcon1.iconAnchor = new GPoint(34, 95);
        myIcon1.infoWindowAnchor = new GPoint(34, 0);
        myIcon1.printImage = '/Images/googleMarker/icon_print.gif';
        myIcon1.printShadow = '/Images/googleMarker/icon_printShadow.gif';
        myIcon1.transparent = '/Images/googleMarker/icon_transparent.png';
        myIcon1.imageMap = [67, 0, 67, 1, 67, 2, 67, 3, 67, 4, 67, 5, 67, 6, 67, 7, 67, 8, 67, 9, 67, 10, 67, 11, 67, 12, 67, 13, 67, 14, 67, 15, 67, 16, 67, 17, 67, 18, 67, 19, 67, 20, 67, 21, 67, 22, 67, 23, 67, 24, 67, 25, 67, 26, 67, 27, 67, 28, 67, 29, 67, 30, 67, 31, 67, 32, 67, 33, 67, 34, 67, 35, 67, 36, 67, 37, 67, 38, 67, 39, 67, 40, 67, 41, 67, 42, 67, 43, 67, 44, 67, 45, 67, 46, 67, 47, 67, 48, 67, 49, 67, 50, 67, 51, 67, 52, 67, 53, 67, 54, 67, 55, 67, 56, 67, 57, 67, 58, 67, 59, 67, 60, 67, 61, 67, 62, 67, 63, 67, 64, 67, 65, 67, 66, 43, 67, 42, 68, 42, 69, 42, 70, 41, 71, 41, 72, 41, 73, 40, 74, 40, 75, 40, 76, 39, 77, 39, 78, 39, 79, 38, 80, 38, 81, 37, 82, 37, 83, 37, 84, 36, 85, 36, 86, 36, 87, 35, 88, 35, 89, 35, 90, 34, 91, 34, 92, 34, 93, 33, 94, 33, 94, 33, 93, 32, 92, 32, 91, 32, 90, 31, 89, 31, 88, 31, 87, 30, 86, 30, 85, 30, 84, 29, 83, 29, 82, 29, 81, 28, 80, 28, 79, 28, 78, 27, 77, 27, 76, 27, 75, 26, 74, 26, 73, 26, 72, 25, 71, 25, 70, 25, 69, 24, 68, 24, 67, 0, 66, 0, 65, 0, 64, 0, 63, 0, 62, 0, 61, 0, 60, 0, 59, 0, 58, 0, 57, 0, 56, 0, 55, 0, 54, 0, 53, 0, 52, 0, 51, 0, 50, 0, 49, 0, 48, 0, 47, 0, 46, 0, 45, 0, 44, 0, 43, 0, 42, 0, 41, 0, 40, 0, 39, 0, 38, 0, 37, 0, 36, 0, 35, 0, 34, 0, 33, 0, 32, 0, 31, 0, 30, 0, 29, 0, 28, 0, 27, 0, 26, 0, 25, 0, 24, 0, 23, 0, 22, 0, 21, 0, 20, 0, 19, 0, 18, 0, 17, 0, 16, 0, 15, 0, 14, 0, 13, 0, 12, 0, 11, 0, 10, 0, 9, 0, 8, 0, 7, 0, 6, 0, 5, 0, 4, 0, 3, 0, 2, 0, 1, 0, 0];

        var markerOptions1 = { icon: myIcon1, draggable: false }
        //var marker = new GMarker(center, markerOptions);
        var marker1 = new GMarker(point1, { icon: myIcon1, draggable: false, clickable: false });
        map1.setCenter(center, 17);
        map1.addOverlay(marker1);
        map1.setMapType(G_NORMAL_MAP);
        map1.removeMapType(G_SATELLITE_MAP);
        map1.removeMapType(G_HYBRID_MAP);
        //GEvent.addListener(marker1, "click", function () { marker1.openInfoWindowHtml(address1); });
        
        //marker.openInfoWindowHtml(address);

    }
}

function createContextMenu1(map1) {
    contextmenu1 = document.createElement("div");
    contextmenu1.style.visibility = "hidden";
    contextmenu1.style.background = "#ffffff";
    contextmenu1.style.border = "1px solid #8888FF";

    contextmenu1.innerHTML = '<a href="javascript:zoomIn1()"><div class="context">&nbsp;&nbsp;Zoom in&nbsp;&nbsp;</div></a>'
                    + '<a href="javascript:zoomOut1()"><div class="context">&nbsp;&nbsp;Zoom out&nbsp;&nbsp;</div></a>'
                    + '<a href="javascript:zoomInHere1()"><div class="context">&nbsp;&nbsp;Zoom in here&nbsp;&nbsp;</div></a>'
                    + '<a href="javascript:zoomOutHere1()"><div class="context">&nbsp;&nbsp;Zoom out here&nbsp;&nbsp;</div></a>'
                    + '<a href="javascript:centreMapHere1()"><div class="context">&nbsp;&nbsp;Centre map here&nbsp;&nbsp;</div></a>';

    map1.getContainer().appendChild(contextmenu1);
    GEvent.addListener(map1, "singlerightclick", function (pixel, tile) {
        clickedPixel = pixel;
        var x = pixel.x;
        var y = pixel.y;
        if (x > map1.getSize().width - 120) {
            x = map1.getSize().width - 120
        }
        if (y > map1.getSize().height - 100) {
            y = map1.getSize().height - 100
        }


        var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(x, y));
        pos.apply(contextmenu1);
        contextmenu1.style.visibility = "visible";
    });
    GEvent.addListener(map1, "click", function () {
        contextmenu1.style.visibility = "hidden";
    });
}
function zoomIn1() {
    map1.zoomIn();
    contextmenu1.style.visibility = "hidden";
}
function zoomOut1() {
    map1.zoomOut();
    contextmenu1.style.visibility = "hidden";
}
function zoomInHere1() {
    var point = map1.fromContainerPixelToLatLng(clickedPixel)
    map1.zoomIn(point, true);
    contextmenu1.style.visibility = "hidden";
}
function zoomOutHere1() {
    var point = map1.fromContainerPixelToLatLng(clickedPixel)
    map1.setCenter(point, map1.getZoom() - 1);
    contextmenu1.style.visibility = "hidden";
}
function centreMapHere1() {
    var point = map1.fromContainerPixelToLatLng(clickedPixel)
    map1.setCenter(point);
    contextmenu1.style.visibility = "hidden";
}

function showRightControl(flashPanelId, imagePanelId) {
    var flashOn = $.hayFlash()
    objFlash = document.getElementById(flashPanelId)
    objImage = document.getElementById(imagePanelId)

    if (objFlash)
        objFlash.style.display = flashOn ? "block" : "none";
    if (objImage)
        objImage.style.display = flashOn ? "none" : "block";
}


/**
Start page fantastic categories
**/


/* check fantastic category is valid  */
function isValidCategory(allcategories, querystringvalue) {
    for (var i = 0; i < allcategories.length; i++) {
        if (allcategories[i].toString() == querystringvalue) {
            return true;
        }
    }
    return false;
}

/* get category name from query string */
function getQueryString() {
    var querystring = window.location.search;
    var queryvalue = querystring.replace("?fantastic=", "");

    if (querystring.startsWith('?fantastic=') && isValidCategory(allcategories, queryvalue) == true) {
        return "fantastic " + queryvalue;
    }
    else {
        return "dummy";
    }
}

/* set active fantastic category */
function activeFavoriteIcon(category) {
    var result = category.split(" ");
    var categoryName = result[1];

    for (var i = 0; i < allcategories.length; i++) {
        var control = document.getElementById(allcategories[i]);

        if (control != null) {
            if (allcategories[i].toString() == categoryName) {
                control.src = "/Images/Fantastic/Fantastic-" + allcategories[i] + "-on.gif";
                control.onmouseover = null;
                control.onmouseout = null;
            }
            else {
                control.src = "/Images/Fantastic/Fantastic-" + allcategories[i] + ".gif";
                control.onmouseover = function onmouseover(event) { switchFantastic(this, true); }
                control.onmouseout = function onmouseout(event) { switchFantastic(this, false); }
            }
        }
    }
}


/* hover effect on category icons */
function switchFantastic(el, isActive) {
    el.src = (isActive)
        ? "/Images/Fantastic/Fantastic-" + el.id + "-on.gif"
        : "/Images/Fantastic/Fantastic-" + el.id + ".gif";
}
