﻿/// <reference path="jquery-1.3.2-vsdoc.js" />
/// VS2010 Intellisense Support for jQuery

function pageLoadFunctions() {
    jQuery(function () {
        jQuery('.staticClock').remove();
        jQuery('.blankTargetLink').attr("target", "_blank");
    });

    displayTime();
    //externalLinks();
    javascriptPageModifications();
    //initializeMap();
    jargonHover();
    mouseTrack();
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_pageLoaded(AdslLineCheckClient);
}

function AdslLineCheckClient() {
    var checkBtn = jQuery('.adsllinecheck input[class=checkBtn]');

    checkBtn.bind('click', function () {
        jQuery('.adsllinecheck .prog-indicator').css('height', 32);
        jQuery('.adsllinecheck .result').children().remove();
    });

    var inputTb = jQuery('.adsllinecheck input[class=inputTb]');
    inputTb.val('Postcode/Telephone...');
    inputTb.bind('focus blur', function () {
        if (inputTb.val() == 'Postcode/Telephone...') {
            inputTb.val('');
        } else if (inputTb.val() == '') {
            inputTb.val('Postcode/Telephone...');
        }
    });
    inputTb.bind("keyup", function (e) {
        if (e.keyCode == 13) {
            checkBtn.click();
        }
    });
}

var mouseX = 0;
var mouseY = 0;

function jargonHover() {
    jQuery(function () {
        jQuery('.jargonDetail').hover(
        function () {
            jQuery(this).find('span').css("width", "300px");
            jQuery(this).find('span').css("left", mouseX);
            jQuery(this).find('span').css("top", mouseY);
        }
        );
    });
    jQuery(function () {
        jQuery('.jargonDetail').mousemove(
        mouseTrack());
    });
}

function mouseTrack() {
    jQuery(document).ready(function () {
        jQuery().mousemove(function (e) {
            mouseX = e.pageX;
            mouseY = e.pageY;
        });
    })
}


// Function for returning the value of a css style.
// You would expect getElementById("id").style.someAttrib.value to return a value but it only does with inline styles
// ripped from 
function getStyle(oElm, strCssRule) {
    var strValue = "";
    if (document.defaultView && document.defaultView.getComputedStyle) {
        strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
    }
    else if (oElm.currentStyle) {
        strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1) {
            return p1.toUpperCase();
        });
        strValue = oElm.currentStyle[strCssRule];
    }
    return strValue;
}

//to provide XHTML strict with ability to open link in new window IF the anchor specifies rel="external"
// strictly (pun) this is bad form but hey
function externalLinks() {

    if (!document.getElementsByTagName) return;

    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
        var anchor = anchors[i];
        var relvalue = anchor.getAttribute("rel");

        if (anchor.getAttribute("href")) {
            var external = /external/;
            var relvalue = anchor.getAttribute("rel");
            if (external.test(relvalue)) { anchor.target = "_blank"; }
        }
    }
}

function javascriptPageModifications() {
    var panels = document.getElementsByName("cp");
    for (var i = 0; i < panels.length; i++) {
        panels[i].style = "height:0px; visibility:collapsed;";
    }
}

//set map global so we can access it from other functions
var map;
//center co-ords
var lat = 37.4419;
var lon = -122.1419;
// map zoom between 0 and 20 ish where 0 is far out man! ;)
var zoom = 15;
//marker options - name:value pairs

//main hook called from the html body onload event Charlie
function initializeMap() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(lat, lon), zoom);
        map.setUIToDefault();
        setMapMarker(lat, lon);
    }
}

function setMapMarker(lt, ln) {

    //here you can setup a custom icon for your customer

    /*var icon = new GIcon(); //constructor
    icon.image = 'red_marker.png'; //change to reference a 256 colour alpha transparency image with shadow at 45 deg towards top right
    icon.iconSize = new GSize(32, 32); //not sure but probably a translation size for the image
    icon.iconAnchor = new GPoint(16, 16); //this is the point in your image that appears at the co-ords
    icon.infoWindowAnchor = new GPoint(25, 7);*/
    //the anchor point that the balloon appears at

    var opts = {
        //"icon": icon, //over-ride this if you want the custom icon
        "clickable": true,
        "labelText": "A",
        "labelOffset": new GSize(-6, -10)
    };

    var point = new GLatLng(lt, ln);
    var marker = new LabeledMarker(point, opts);

    GEvent.addListener(marker, "click", function () {
        marker.openInfoWindowHtml("<p>Hi Charlie! <b>:)</b></p>"); //the string in here can be any html i.e. some images etc
    });
    map.addOverlay(marker);
}

function getMenuDiv(elem) {
    alert(elem);
}

