//---------------------------------------------------------------------------------------------------------------------------
// Converts <span class="address">anything_at_anydomain</span> to a valid email address - avoids spam.
// 
var Convert = {
    initialize: function() {
        var spans = document.getElementsByTagName("span");
        for (var i = 0; i < spans.length; i++) {
            if(DOMhelp.cssjs('check',spans[i],'address')){ 
                string = spans[i].childNodes[0].nodeValue;
                if(string.split("_")[1] != null){
                    email = string.split("_")[0] + "@" + string.split("_")[2];
                    spans[i].innerHTML = '<a href="mailto:' + email + '?subject=Enquiry">' + email + '</a>';
                }
            }
        }
    }
}
//window.onload = Convert.initialize
DOMhelp.addEvent(window, 'load', Convert.initialize, false);

//---------------------------------------------------------------------------------------------------------------------------
// Converts <span class="thisyear">2008</span> to current year - if user has disabled javascript it will show 2008.
// 
var ThisYear = {
    initialize: function() {
        var spans = document.getElementsByTagName("span");
        for (var i = 0; i < spans.length; i++) {
            if(DOMhelp.cssjs('check',spans[i],'thisyear')){ 
                if(spans[i].childNodes[0] != null){
                    string = spans[i].childNodes[0].nodeValue;
                    if(string == '2008'){
                        RightNow = new Date();
			thisYear= RightNow.getFullYear() - 2000;
                        spans[i].innerHTML = string + "-" + thisYear;
                    }
                }
            }
        }
    }
}
//window.onload = ThisYear.initialize;
DOMhelp.addEvent(window, 'load', ThisYear.initialize, false);

//---------------------------------------------------------------------------------------------------------------------------
// Converts <li id="menu_xxx"> <a href="xxx.htm">XXXX</a></li> to <li id="menu_xxx"> <a id="active_option" href="#">XXX</a></li>
// Courtesy of Steve Wright.
//
// What I've done is given the <body> tag an id attribute.
// I've then labelled the associated <li> element with an id that is the same as the <body> but prefixed by "menu_".
// So for the bespoke page, the body would have an id of "bespoke" and the associated menu option would have an id of "menu_bespoke".
//
// When the javascript routine runs it does the following:
// [1] Grab the id from the body tag (if there is one).
// [2] Find an element with an id of "menu_" + that id (if there is one). This should be an <li> tag.
// [3] Find the <a> elements within that <li>. There should only be one, but incase there are more, we will only be tweaking the first one.
// [4] Set the id to be "active_option" and overwrite the href with "#" on this <a> tag.

ThisMenu = {
	menu_prefix : "menu_",
	active_id : "active_option",
	
	initialize: function(){
		var bodyid = document.getElementsByTagName("body")[0].getAttribute("id");  // [1] Get the id for the <body> tag.

		if(bodyid != null){
			menuli = document.getElementById(ThisMenu.menu_prefix + bodyid);   // [2] Find an <li> element with an id related to the <body> id.

			if(menuli != null){
				var anchors = menuli.getElementsByTagName("a");            // [3] Find the <a> tags within the <li> tag.
				if(anchors.length){
				
					anchors[0].setAttribute("id", ThisMenu.active_id); // [4] Add an id attribute to the first <a> tag to indicate
                                                                                           //     this is the active menu option.
					
					anchors[0].setAttribute("href", "#");              // [4] Overwrite the href attribute for the first <a> tag with "#"
				}
			}
		}
	}
};
DOMhelp.addEvent(window, 'load', ThisMenu.initialize, false);

//---------------------------------------------------------------------------------------------------------------------------
// Detects hour of day and then uses style sheet dependant upon hour:
// 00-04 = Style 3
// 05-10 = Style 2
// 11-17 = Style 1
// 18-20 = Style 2
// 21-23 = Style 3
// 
// Style = {
// 	initialize: function(){
// alert("Hello");
// 		var currentTime = new Date()
// 		var hour = currentTime.getHours()
// 
// 		document.write(hour)
// 
// 		if(hour < 5){
// 			setActiveStyleSheet('style3');
// 				}else if(hour < 11){
// 				setActiveStyleSheet('style2');
// 				}else if(hour < 18){
// 				setActiveStyleSheet('style1');
// 				}else if(hour < 21){
// 				setActiveStyleSheet('style2');
// 				}else {
// 				setActiveStyleSheet('style3');
// };
// DOMhelp.addEvent(window, 'load', Style.initialize, false);
// 
//---------------------------------------------------------------------------------------------------------------------------
// Function displays current year (eg. 2007)
// REDUNDANT +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//function showyear() {
// RightNow = new Date();
// document.write(+ RightNow.getFullYear());
//}

//********************************************************************************
// Write cookie "screen_height (value will be say 1024)
//
function writeCookieSH()
{
 var the_cookie = "screen_height="+ screen.height;
 document.cookie=the_cookie;
}

//********************************************************************************
// Create a marker and corresponding information window in Google maps
// Passed the Lat, Long co-ords plus some text.

function createInfoMarker(point, text)
{
   var marker = new GMarker(point);

   GEvent.addListener(marker, "click",

      function() {

         marker.openInfoWindowHtml(text);

      }

   );

  return marker;
}


