﻿
$(document).ready(function() {

    $.each($(".hdn_youtube_embed"), function(i, obj) {
    
        width = $(this).parent().width();
        height = (width * 3) / 4;
        $vid_frame = $('<iframe></iframe>')
			.attr('width', width)
			.attr('height', height)
			.attr('src', 'http://www.youtube.com/embed/' + $(this).val())
			.attr('frameborder', 0)
			.addClass('youtube-player')
			.html(' ');
			
	    $(this).parent().append($vid_frame);
	    
    });

});

function toggleDiv(obj) {
    $("#" + obj).slideToggle('fast');
}

function loadMap(div, lat, lon, description) {

    var start = new google.maps.LatLng(lon, lon);

    var myOptions = {
        zoom: 15,
        draggableCursor: 'default',
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    map = new google.maps.Map(document.getElementById(div), myOptions);

    map.setCenter(start);

    google.maps.event.addListener(map, 'tilesloaded', function() {

        var marker = new google.maps.Marker({
            position: new google.maps.LatLng(lat, lon),
            cursor: 'default',
            clickable: true
        });

        infowindow = new google.maps.InfoWindow({
            content: "<div class='infowindow'>" + description + "</div>"
        });
        
        marker.setMap(map);
        infowindow.open(map, marker);
        
        // clear listener
        google.maps.event.clearListeners(map, 'tilesloaded');

    });   
}

function addMapMarker(lat, lon, info) {

    var icon = new GIcon();
    //icon.image = "/images/main/kajima_pointer_" + theme + ".png";
    icon.infoWindowAnchor = new GPoint(5, 1);

    var point = new GLatLng(lat, lon);
    var marker = new GMarker(point, markerOptions);

    if (info.toString().length > 1) {
        if (typeof (info) !== "undefined") {////////
            GEvent.addListener(marker, "click", function() {
                marker.openInfoWindowHtml(info);
            });
        }
    }
    map.addOverlay(marker);
}

// Call asp.net HttpHandler to process js requests
ajaxRequest = function(data, url, callback) {
    $.ajax({ url: url,
        type: "POST",
        cache: false,
        data: data,
        dataType: "json",
        success: function(result) {
            callback(result);
        },
        error: function(xmlhr, status, err) {
            console.error(err);
            var response = eval(err + ": (" + xmlhr.responseText + ")");
            console.log(response);
        }
    });
}


var gAutoPrint = true; // Flag for whether or not to automatically call the print function
function doPrint(tagName) {
    if (document.getElementById != null) {
        var html = '<html>\n<head>\n';

        html += '\n<link href="/css/print.css" rel="stylesheet" type="text/css">';

        html += '\n</head>\n<body>\n';

        var printReadyElem = document.getElementById(tagName);

        if (printReadyElem != null) {
            html += printReadyElem.innerHTML;
        }
        else {
            alert("Could not find the printReady section in the HTML");
            return;
        }
        html += '\n</body>\n</html>';

        var printWin = window.open("", "printSpecial", "toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes");
        printWin.document.open();
        printWin.document.write(html);
        printWin.document.close();
        if (gAutoPrint)
            printWin.print();
    }
    else {
        alert("Sorry, the print ready feature is only available in modern browsers.");
    }
}

// Required for I.E.
sfHover = function() {
    var topNavList = document.getElementById("topnav");
    if (topNavList) {
        var i;
        var sfEls = topNavList.getElementsByTagName("li");
        for (i = 0; i < sfEls.length; i++) {
            sfEls[i].onmouseover = function() {
                this.className += " sfhover";
            }
            sfEls[i].onmouseout = function() {
                this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
            }
        }
    }
    var sfEls2 = document.getElementById("mainnavList").getElementsByTagName("li");
    for (i = 0; i < sfEls2.length; i++) {
        sfEls2[i].onmouseover = function() {
            this.className += " sfhover";
        }
        sfEls2[i].onmouseout = function() {
            this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }

    var langList = document.getElementById("langList").getElementsByTagName("li");
    for (i = 0; i < langList.length; i++) {
        langList[i].onmouseover = function() {
            this.className += " sfhover";
        }
        langList[i].onmouseout = function() {

            this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
        }
    }

    var selectorList = document.getElementById("selectorList");
    if (selectorList) {
        var sfEls3 = selectorList.getElementsByTagName("li");
        for (i = 0; i < sfEls3.length; i++) {
            sfEls3[i].onmouseover = function() {
                this.className += " sfhover";
            }
            sfEls3[i].onmouseout = function() {
                this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
            }
        }
    }

    var lstOffices = document.getElementById("lstSpecialisms");
    if (lstOffices) {
        var sfEls3 = lstOffices.getElementsByTagName("li");
        for (i = 0; i < sfEls3.length; i++) {
            sfEls3[i].onmouseover = function() {
                this.className += " sfhover";
            }
            sfEls3[i].onmouseout = function() {
                this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
            }
        }
    }

    var lstOffices = document.getElementById("lstOffices");
    if (lstOffices) {
        var sfEls3 = lstOffices.getElementsByTagName("li");
        for (i = 0; i < sfEls3.length; i++) {
            sfEls3[i].onmouseover = function() {
                this.className += " sfhover";
            }
            sfEls3[i].onmouseout = function() {
                this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
            }
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


selectLink = function(sel) {

    if (sel.options.selectedIndex > 0) {
        window.location = sel.options[sel.options.selectedIndex].value;
    }
}

