/// <reference path="jquery-1.4.1-vsdoc.js" />
/// <reference path="swfobject-vsdoc.js" />

$(document).ready(function() {


    /* loop through a tags on page */
    $('a').each(function(idx, item) {
        /* if it is not a mailto tag */
        if (item.href.indexOf("mailto") == -1 && item.href.indexOf("default.aspx") != -1) {
            //var url = "javascript:delayedRedirect('" + item.href + "');"
            //item.href = url;
        }
    });

    /* loop through a tags on page */
    $('area').each(function(idx, item) {
        /* if it is not a mailto tag */
        if (item.href.indexOf("mailto") == -1 && item.href.indexOf("default.aspx") != -1) {
            //var url = "javascript:delayedRedirect('" + item.href + "');"
            //item.href = url;
        }
    });

/*
    $("a.iframe").fancybox({
        'width': 737,
        'height': 370,
        'scrolling': 'no',
        'transitionIn': 'none',
        'transitionOut': 'elastic',
        'type': 'iframe'

    });
    */

});

function setCookie(name, value, expires) {
    document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
}

function getCookie(name) {

    var dc = document.cookie;
    var cname = name + "=";

    if (dc.length > 0) {
        begin = dc.indexOf(cname);
        if (begin != -1) {
            begin += cname.length;
            end = dc.indexOf(";", begin);
            if (end == -1) end = dc.length;
            return unescape(dc.substring(begin, end));
        }
    }
    return null;
}

/* fade in loader and redirect */
function delayedRedirect(url) {
    $("#supersize_loading").fadeIn("200", function() { window.location = url });

}

/* Google Maps integration -------------------------------------------------------------------------------------- */
function AttachGMap(address, infobox, id, form_id) {

	var geocoder = null;
	var map = null;

	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById(id));

		// Add marker for store address
		var geocoder = new GClientGeocoder();
		var point = geocoder.getLatLng(address, function(point) {

			if (!point) {
				//alert(address + " not found");
				// address not found, make maps invisible
				$("#" + id).css("background", "#fff");

			} else {
				var marker0 = new GMarker(point);
				marker0.title = "";
				map.addOverlay(marker0);
				map.setCenter(point, 13);
				GEvent.addListener(marker0, "click", function() {
					// submit to maps.google.no
					document.getElementById(form_id).submit();
				});
			}

			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.addControl(new GScaleControl());
		});
	}

	// hide copyrightinfo on the bottom. I did this because it was too big and went outside designated area.
	//$("#" + id + " .gmnoprint,#" + id + " > div:last").css("display", "none");
}

