/*
J  a  v  a  c a t  z

Description:

Tel: (852)29877951
Fax: (852)29879294
Email: office@javacatz.com
Website: www.javacatz.com

Created: 2006-08-23
*/

/* *** Home Page Slide Show *** */
var countArticle = 0;
var mySlideData = new Array();
var SlideShowPath = 'img/slideshow/';

var slideLeftOver = 0;
var idToShow = '';
var anchor='';
var clearTimer;
var urlAddress = "http://www.cwbgolf.org/login.aspx"; 
var pageName = "The Clearwater Bay Golf &amp; Country Club Hong Kong - Member Login"; 

var currentIter = 0;
var lastIter = 0;
var maxIter = 0;
var slideShowElement = "";
var slideShowData = new Array();
var slideShowInit = 1;
var slideShowDelayFirstTime = 1000;
var slideShowDelay = 2500;
var articleLink = "";
var stoppedSlideshow = false;
var storeOpenSection = "";

	mySlideData[countArticle++] = new Array(SlideShowPath + 'img01.jpg');
	mySlideData[countArticle++] = new Array(SlideShowPath + 'img01.jpg');
	mySlideData[countArticle++] = new Array(SlideShowPath + 'img02.jpg');
	mySlideData[countArticle++] = new Array(SlideShowPath + 'img03.jpg');
	mySlideData[countArticle++] = new Array(SlideShowPath + 'img04.jpg');
	mySlideData[countArticle++] = new Array(SlideShowPath + 'img05.jpg');
	mySlideData[countArticle++] = new Array(SlideShowPath + 'img06.jpg');
	mySlideData[countArticle++] = new Array(SlideShowPath + 'img07.jpg');
	mySlideData[countArticle++] = new Array(SlideShowPath + 'img08.jpg');
	// mySlideData[countArticle++] = new Array(SlideShowPath + 'img09.jpg');

function mouseOutRestartSlideShow(id){
	if (idToShow == 'main'){
		stoppedSlideshow = true;
		clearTimer = setTimeout("restartSlideshow()", 1000);
	}
}

function slideNavSelectImg(id){
	if (idToShow == 'main'){
		clearTimeout(clearTimer);

		Effect.Appear("mySlideshow2", {duration:0});
	
		switch(id){
			case "1": $('mySlideshow2').innerHTML = '<img src="' + SlideShowPath + 'img01.jpg" />'; return false;
			case "2": $('mySlideshow2').innerHTML = '<img src="' + SlideShowPath + 'img02.jpg" />'; return false;
			case "3": $('mySlideshow2').innerHTML = '<img src="' + SlideShowPath + 'img03.jpg" />'; return false;
			case "4": $('mySlideshow2').innerHTML = '<img src="' + SlideShowPath + 'img04.jpg" />'; return false;
			case "5": $('mySlideshow2').innerHTML = '<img src="' + SlideShowPath + 'img05.jpg" />'; return false;
			case "6": $('mySlideshow2').innerHTML = '<img src="' + SlideShowPath + 'img06.jpg" />'; return false;
			case "7": $('mySlideshow2').innerHTML = '<img src="' + SlideShowPath + 'img07.jpg" />'; return false;		
			case "8": $('mySlideshow2').innerHTML = '<img src="' + SlideShowPath + 'img08.jpg" />'; return false;		
			// case "9": $('mySlideshow2').innerHTML = '<img src="' + SlideShowPath + 'img09.jpg" />'; return false;		
	
		}
	}
}

function initSlideShow(element, data) {

	slideShowElement = element;
	slideShowData = data;
	element.style.display="block";
	
	articleLink = document.createElement('a');
	articleLink.className = 'global';
	element.appendChild(articleLink);
	
	maxIter = data.length;
	
	for(i=0;i<data.length;i++)
	{
		var currentImg = document.createElement('img');
		currentImg.setAttribute('id','slideElement' + parseInt(i));
		currentImg.style.position="absolute";
		currentImg.style.left="0px";
		currentImg.style.top="0px";
		currentImg.style.margin="0px";
		currentImg.style.border="0px";
		currentImg.src=data[i][0];
	
		articleLink.appendChild(currentImg);
		currentImg.currentOpacity = new fx.Opacity(currentImg, {duration: 300});
		currentImg.currentOpacity.setOpacity(0);
	}
	
	currentImg.currentOpacity = new fx.Opacity(currentImg, {duration: 300});
	currentImg.currentOpacity.setOpacity(0);
		
	doSlideShow();
}

function startSlideshow() {
	initSlideShow($('mySlideshow'), mySlideData);
}

function restartSlideshow() 
{
		Effect.Fade('mySlideshow2', {duration:0.2});
		stoppedSlideshow = false;
		setTimeout("nextSlideShow()", 1500);
}

function nextSlideShow() {
	if(stoppedSlideshow==true)
		return;		

		lastIter = currentIter;
		currentIter++;

		if (currentIter >= maxIter){
			currentIter = 0;
			lastIter = maxIter - 1;
		}
		slideShowInit = 0;
		doSlideShow();
}


function doSlideShow() {

	if (slideShowInit == 1)
	{
//		alert(currentIter);
		setTimeout(nextSlideShow,slideShowDelayFirstTime);
	} else {
		if (currentIter != 0) {
			$('slideElement' + parseInt(currentIter)).currentOpacity.options.onComplete = function() {
				$('slideElement' + parseInt(lastIter)).currentOpacity.setOpacity(0);
			}
			$('slideElement' + parseInt(currentIter)).currentOpacity.custom(0, 1);
		} else {
			$('slideElement' + parseInt(currentIter)).currentOpacity.setOpacity(1);
			$('slideElement' + parseInt(lastIter)).currentOpacity.custom(1, 0);
		}
		setTimeout(nextSlideShow,slideShowDelay);
	}	
}
/* *** Home Page Slide Show End *** */

/* *** IE Update for ActiveX click to activate *** */
function ieupdate() {
	objects = document.getElementsByTagName("object");
	for (var i = 0; i < objects.length; i++)
	{
		objects[i].outerHTML = objects[i].outerHTML;
	}
}

/* *** IE Update for ActiveX click to activate End *** */

/* *** Login *** */
var ie4 = (document.all);
var ns4 = (document.layers);

if (ns4) document.captureEvents(Event.KEYPRESS);
document.onkeypress = checkEnter;

function verifymember() {
	var frm = document.forms[0];
	frm.submit();
}

function checkEnter(e) {
	var charCode = (ns4)?e.which:event.keyCode;
	if (charCode==13) verifymember();
	return true;
}
/* *** Login End *** */

/* *** Careers Accordion *** */
function JobAccordion(id){
	// Get Job Vacancies Length
	var sAccordion = document.getElementById("sAccordion"); // Scan Start Under Class Name "sAccordion"
	// var JobVacancies = sAccordion.getElementsByTagName("a"); // Scan Class Name "jobVacancies"
	var JobVacancies = $$("#sAccordion .position a"); // Scan Class Name "jobVacancies"
	var joblength = JobVacancies.length; 
	for (var i = 0; i < joblength; i++){
		if(id != i){
			$("bDown"+i).style.display ='none'; // Right Side Mini Icon Down
			$("bRight"+i).style.display ='block'; // Right Side Mini Icon Right
			Effect.BlindUp('info'+i, {duration:0.6}); // Close all Information
		}
		else{
			$('bDown'+id).style.display ='block'; // Right Side Mini Icon Down
			$('bRight'+id).style.display ='none'; // Right Side Mini Icon Right
			 Effect.BlindDown('info'+id, {duration:1.3}); // Open Clicked Information
		}
	}
	return false;
}
function JobAccordion2(id)
{
// Get Job Vacancies Length
var sAccordion = document.getElementById("sAccordion"); // Scan Start Under Class Name "sAccordion"
// var JobVacancies = sAccordion.getElementsByTagName("a"); // Scan Class Name "jobVacancies"
var JobVacancies = $$("#sAccordion .position a"); // Scan Class Name "jobVacancies"
//alert(JobVacancies.length);
var joblength = JobVacancies.length; 
for (var i = 0; i < joblength; i++){
	if(id != i){
		$("repEventsTitle__ctl"+i+"_bDown").style.display ='none'; // Right Side Mini Icon Down
		$("repEventsTitle__ctl"+i+"_bRight").style.display ='block'; // Right Side Mini Icon Right
		Effect.BlindUp('repEventsTitle__ctl'+i+'_info', {duration:0.6}); // Close all Information
		
	}
	else{
		$('repEventsTitle__ctl'+id+'_bDown').style.display ='block'; // Right Side Mini Icon Down
		$('repEventsTitle__ctl'+id+'_bRight').style.display ='none'; // Right Side Mini Icon Right
		Effect.BlindDown('repEventsTitle__ctl'+id+'_info', {duration:1.3}); // Open Clicked Information
	}
}
return false;
}

/* *** Optima Flash Font *** */
/* *** Global Array storing all subpages id *** */

subpage_id = new Array();
subpage_color = new Array();

subpage_id[0] = "about_us"; subpage_color[0] = "7F8785";
subpage_id[1] = "golf_club"; subpage_color[1] = "118459";
subpage_id[2] = "country_club"; subpage_color[2] = "F7435E";
subpage_id[3] = "marina_club"; subpage_color[3] = "41AECF";
subpage_id[4] = "food_beverage"; subpage_color[4] = "F18916";
subpage_id[5] = "cwb_spa"; subpage_color[5] = "67C3B8";
subpage_id[6] = "membership"; subpage_color[6] = "998A6D";
subpage_id[7] = "events"; subpage_color[7] = "7F8785";
// subpage_id[8] = "photos"; subpage_color[8] = "7F8785";

/* *** end of Global Array storing all subpages id *** */

/* *** side nav menu flash *** */
function sideNavMenuFlash() {
	if(typeof sIFR == "function") {
	// ======= Side Nav Button non-selected Colors =======
		for( var i=0; i < subpage_id.length; i++ ) {
			sIFR.replaceElement(named({sSelector:".dc_"+subpage_id[i], sFlashSrc:"optima.swf", sColor:"#FFFFFF", sLinkColor:"#FFFFFF", sHoverColor:"#FFFFFF", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:3, nPaddingLeft:15, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=15&offsetBottom=0&link=true"}));
		}
	// ======= Side Nav Button selected Colors =======
		for( var i=0; i < subpage_id.length; i++ ) {
			sIFR.replaceElement(named({sSelector:".dc_"+subpage_id[i]+"-selected", sFlashSrc:"optima.swf", sColor:"#FFFFFF", sLinkColor:"#FFFFFF", sHoverColor:"#FFFFFF", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:3, nPaddingLeft:15, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=15&offsetBottom=0&link=true"}));
		}

	}
}
/* *** end of side nav menu flash *** */

/* *** Start Content Header flash *** */
function sIFRReplaceElements()
{

	if(typeof sIFR == "function") {
	// ======= Main Content main Header Colors =======
		sIFR.replaceElement(named({sSelector:".careers", sFlashSrc:"optima.swf", sColor:"#747474", sLinkColor:"#747474", sHoverColor:"#747474", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=0&offsetBottom=0"}));
		sIFR.replaceElement(named({sSelector:".corporate_days", sFlashSrc:"optima.swf", sColor:"#747474", sLinkColor:"#747474", sHoverColor:"#747474", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=0&offsetBottom=0"}));
		sIFR.replaceElement(named({sSelector:".press", sFlashSrc:"optima.swf", sColor:"#747474", sLinkColor:"#747474", sHoverColor:"#747474", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=0&offsetBottom=0"}));
		sIFR.replaceElement(named({sSelector:".sitemap", sFlashSrc:"optima.swf", sColor:"#747474", sLinkColor:"#747474", sHoverColor:"#747474", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=0&offsetBottom=0"}));
		sIFR.replaceElement(named({sSelector:".advertising", sFlashSrc:"optima.swf", sColor:"#747474", sLinkColor:"#747474", sHoverColor:"#747474", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=0&offsetBottom=0"}));

		sIFR.replaceElement(named({sSelector:".about_us", sFlashSrc:"optima.swf", sColor:"#717775", sLinkColor:"#717775", sHoverColor:"#717775", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=0&offsetBottom=0"}));
		if($$('body#photo_tour').length>0) {
			sIFR.replaceElement(named({sSelector:".golf_club", sFlashSrc:"optima.swf", sColor:"#118459", sLinkColor:"#118459", sHoverColor:"#118459", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=center&offsetTop=0&offsetLeft=0&offsetBottom=0"}));	
		} else {
			sIFR.replaceElement(named({sSelector:".golf_club", sFlashSrc:"optima.swf", sColor:"#118459", sLinkColor:"#118459", sHoverColor:"#118459", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=0&offsetBottom=0"}));	
		}
		sIFR.replaceElement(named({sSelector:".country_club", sFlashSrc:"optima.swf", sColor:"#F7435E", sLinkColor:"#F7435E", sHoverColor:"#F7435E", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=0&offsetBottom=0"}));
		sIFR.replaceElement(named({sSelector:".marina_club", sFlashSrc:"optima.swf", sColor:"#41AECF", sLinkColor:"#41AECF", sHoverColor:"#41AECF", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=0&offsetBottom=0"}));
		sIFR.replaceElement(named({sSelector:".spa", sFlashSrc:"optima.swf", sColor:"#67C3B8", sLinkColor:"#67C3B8", sHoverColor:"#67C3B8", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=0&offsetBottom=0"}));
		sIFR.replaceElement(named({sSelector:".membership", sFlashSrc:"optima.swf", sColor:"#998A6D", sLinkColor:"#998A6D", sHoverColor:"#998A6D", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=0&offsetBottom=0"}));
		sIFR.replaceElement(named({sSelector:".events", sFlashSrc:"optima.swf", sColor:"#717775", sLinkColor:"#717775", sHoverColor:"#717775", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=0&offsetBottom=0"}));
		// sIFR.replaceElement(named({sSelector:".photos", sFlashSrc:"optima.swf", sColor:"#717775", sLinkColor:"#717775", sHoverColor:"#717775", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sCase: "upper", sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0&offsetLeft=0&offsetBottom=0"}));
	// ======= Main Content Sub Header Colors =======
		sIFR.replaceElement(named({sSelector:"#mHeaderSubPadding", sFlashSrc:"optima.swf", sColor:"#FFFFFF", sLinkColor:"#FFFFFF", sHoverColor:"#FFFFFF", sBgColor: "transparent", nPaddingTop:0, nPaddingBottom:0, nPaddingLeft:0, nPaddingRight:0, sWmode:"transparent", sFlashVars:"textalign=right&offsetTop=0&offsetLeft=0&offsetBottom=0"}));
	};
}
/* *** End of Content Header flash *** */

/* *** Start Body Loader *** */
function bodyOnLoader(id, location, selected) { // (id) is section ID, (location) defind not under Slide Nav
	
	for( var i=0; i < subpage_id.length; i++ ) {
		if($('dct_'+subpage_id[i]) && subpage_id[i]!=id) new Effect.BlindUp('dct_'+subpage_id[i], {duration:0});
	}
	if($("dc_"+id)) {
		$("dc_"+id).className="dc_"+id+"-selected";
		if($("dct_"+id)) new Effect.BlindDown('dct_'+id, {duration: 0});
	}
    idToShow = id;

	// location 1 is not under the slidenav
	if (location != 1){
		if($("dc_"+id)) {
			$("dc_"+id).className="dc_"+id+"-selected"; // Highlight Selected Button
			
			if($('dct_'+idToShow)) setTimeout("new Effect.BlindDown('dct_'+idToShow, {duration:0.4})", 0);// Collapes Sub Level for fireFox
			slideNavHighlight(selected); // Underline Select Sub Level TextLink
		}
	}
	directGoAnchorLink(); // Directly Linking Anchor function
	
	setTimeout("$('LeftSlideMenuPreloader').style.display='none';$('LeftSlideMenu').style.display='block';", 10);
	setTimeout("sideNavMenuFlash(); sIFRReplaceElements();",800);
	setTimeout("ieupdate();", 110);
}
/* *** End of Body Loader *** */

/* *** Start Slide Left Button Hightligh *** */
function slideNavHighlight(selected){
	var LeftMenu = document.getElementById("LeftSlideMenu"); // Scan Under ID name "LeftSlideMenu"
	var LinkList = LeftMenu.getElementsByTagName("a"); // Scan All Links
	var getLocationUrl = document.location.href;
	var finalLocationUrl = getLocationUrl.split("#");


	if (selected != undefined){
		var getDomain = "http://"+document.domain;
		var folder = "/public/";
		var pathUrl = getDomain+folder;
		var selected = pathUrl+selected+".aspx";
				
		for (i=0; i < LinkList.length; i++)
		{
			if (LinkList[i].href == selected){
				LinkList[i].style.textDecoration = 'underline';	// Add Underline
			}
		}			
	}

	for (i=0; i < LinkList.length; i++)
	{
		if (LinkList[i].href == finalLocationUrl[0]){
			LinkList[i].style.textDecoration = 'underline';	// Add Underline
		}
	}							
}
/* *** End of Slide Left Button Hightligh *** */


function slideNavHideClickedBtn(id){
	var leftMenu = document.getElementById("LeftSlideMenu"); 
	var btn = leftMenu.getElementsByTagName("li");
	var menulength = btn.length; 

	for (var i = 0; i < menulength; i++){
		if(id != i){
			$("Selected"+i).style.display ='block'; // 
			$("Deselected"+i).style.display ='none'; // 
		}
		else{
			$('Selected'+id).style.display ='none'; // 
			$('Deselected'+id).style.display ='block'; // 
		}
	}
	return false;
}

/* *** Open up Side Nav Menu and set colorings *** */
function openMenu(id) {
	if(storeOpenSection != id) {
	    if($('dct_'+id)) new Effect.BlindDown('dct_'+id, {duration: 1.0});
		storeOpenSection = id;
		for( var i=0; i < subpage_id.length; i++ ) {
			if(id!=subpage_id[i] && $('dct_'+subpage_id[i])) { new Effect.BlindUp('dct_'+subpage_id[i], {duration: 0.6}); $('dc_'+subpage_id[i]).style.backgroundColor = ''; }
			else { $('dc_'+subpage_id[i]).style.backgroundColor = '#'+subpage_color[i]; }
		}
	}
}
/* *** end of Open up Side Nav Menu and set colorings *** */

/* *** Start Auto Selected Anchor Link on Sub Menu *** */
function autoSelectAnchorLink(){
/* *** Auto Select First Anchor Link *** */
var subMenu = document.getElementById("contentSubNav"); 
var strLink = "";
	if (subMenu!=null){
		var subLinkList = subMenu.getElementsByTagName("a"); 
		var textFound = -1;
		for (i=0; i < subLinkList.length; i++){
			strLink = subLinkList[0];
			// no need, now controlled in css
			//subLinkList[0].style.textDecoration = 'underline';
		}
	}
}
/* *** End of Auto Selected Anchor Link on Sub Menu *** */
	
/* *** Start Auto Redirect Anchor Link when the page load *** */
function directGoAnchorLink(){
var getLinkHash = window.location.hash;

	if (getLinkHash!=anchor){
		getLinkHash = getLinkHash.substring(1);
		linkSubCat(idToShow, getLinkHash);
	}else{
		autoSelectAnchorLink();
	}
}
/* *** End of Auto Redirect Anchor Link when the page load *** */

/* *** Start Add to Favorites *** */
function addToFavorites() {
	if (window.external) { 
		window.external.AddFavorite(urlAddress,pageName) 
	} else { 
		alert("Sorry! Your browser doesn't support this function."); 
	}
}
/* *** End of Add to Favorites *** */

/* Smooth scrolling start here
*/

var ss = {
  fixAllLinks: function() {
    // Get a list of all links in the page
    var allLinks = document.getElementsByTagName('a');
    // Walk through the list
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if ((lnk.href && lnk.href.indexOf('#') != -1) && 
          ( (lnk.pathname == location.pathname) ||
	    ('/'+lnk.pathname == location.pathname) ) && 
          (lnk.search == location.search)) {
        // If the link is internal to the page (begins in #)
        // then attach the smoothScroll function as an onclick
        // event handler
        ss.addEvent(lnk,'click',ss.smoothScroll);
      }
    }
  },

  smoothScroll: function(e) {
    // This is an event handler; get the clicked on element,
    // in a cross-browser fashion
    if (window.event) {
      target = window.event.srcElement;
    } else if (e) {
      target = e.target;
    } else return;

    // Make sure that the target is an element, not a text node
    // within an element
    if (target.nodeName.toLowerCase() != 'a') {
      target = target.parentNode;
    }
  
    // Paranoia; check this is an A tag
    if (target.nodeName.toLowerCase() != 'a') return;
  
    // Find the <a name> tag corresponding to this href
    // First strip off the hash (first character)
    anchor = target.hash.substr(1);
    // Now loop all A tags until we find one with that name
    var allLinks = document.getElementsByTagName('a');
    var destinationLink = null;
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if (lnk.name && (lnk.name == anchor)) {
        destinationLink = lnk;
        break;
      }
    }
  
    // If we didn't find a destination, give up and let the browser do
    // its thing
    if (!destinationLink) return true;
  
    // Find the destination's position
    var destx = destinationLink.offsetLeft; 
    var desty = destinationLink.offsetTop;
    var thisNode = destinationLink;
    while (thisNode.offsetParent && 
          (thisNode.offsetParent != document.body)) {
      thisNode = thisNode.offsetParent;
      destx += thisNode.offsetLeft;
      desty += thisNode.offsetTop;
    }
  
    // Stop any current scrolling
    clearInterval(ss.INTERVAL);
  
    cypos = ss.getCurrentYPos();
  
    ss_stepsize = parseInt((desty-cypos)/ss.STEPS);
    ss.INTERVAL =
setInterval('ss.scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
  
    // And stop the actual click happening
    if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.preventDefault && e.stopPropagation) {
      e.preventDefault();
      e.stopPropagation();
    }
  },

  scrollWindow: function(scramount,dest,anchor) {
    wascypos = ss.getCurrentYPos();
    isAbove = (wascypos < dest);
    window.scrollTo(0,wascypos + scramount);
    iscypos = ss.getCurrentYPos();
    isAboveNow = (iscypos < dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      // if we've just scrolled past the destination, or
      // we haven't moved from the last scroll (i.e., we're at the
      // bottom of the page) then scroll exactly to the link
      window.scrollTo(0,dest);
      // cancel the repeating timer
      clearInterval(ss.INTERVAL);
      // and jump to the link directly so the URL's right
      location.hash = anchor;
    }
  },

  getCurrentYPos: function() {
    if (document.body && document.body.scrollTop)
      return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
      return document.documentElement.scrollTop;
    if (window.pageYOffset)
      return window.pageYOffset;
    return 0;
  },

  addEvent: function(elm, evType, fn, useCapture) {
    // addEvent and removeEvent
    // cross-browser event handling for IE5+,  NS6 and Mozilla
    // By Scott Andrew
    if (elm.addEventListener){
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } else if (elm.attachEvent){
      var r = elm.attachEvent("on"+evType, fn);
      return r;
    } else {
      alert("Handler could not be removed");
    }
  } 
}

ss.STEPS = 40;

ss.addEvent(window,"load",ss.fixAllLinks);

/* Smooth scrolling end here
*/

var nHintType = -1;
var valid1 = false;
var valid2 = false;
var valid3 = false;
var valid4 = false;
var nTotal = 0;
function init() {
  showFee();
}

function showFee() {
  showFee(false);
}

function showFee(bLeaseOnClick) {
  sHintHTML = "";
  nHintType = -1;
  nTotal = 0;
  if (!bLeaseOnClick)
	showShortLongLease();
  showDryWetType();
  showManagementNRentalFee();
  showSubscriptionFee();
  document.getElementById('hint').innerHTML = "";
  document.getElementById('hint1').innerHTML = "";
  document.getElementById('hint2').innerHTML = "";
  document.getElementById('hint3').innerHTML = "";
  if (nHintType > 0) {
    document.getElementById('hint' + nHintType).innerHTML = sHintHTML;
  }
  if (valid1 && valid2 && valid3 && valid4) {
    document.getElementById('total_fee').innerHTML = "<span class='udouble'>" + addCommas(nTotal) + "</span>";
  }
  else {
    document.getElementById('total_fee').innerHTML = "--------";
  }
}

function showDryWetType() {
  var sHTML1 = "";
  var size = document.form.size_op[document.form.size_op.selectedIndex].value;
  if (size >= 20 && size <= 32) {
    sHTML1 = "Dry Stack";
  }
  else if (size >= 33 && size <= 110)  {
    sHTML1 = "Wet Berth";
  }
  document.getElementById('drywet_type').innerHTML = sHTML1;
}

function showShortLongLease() {
  var sTitle = "";
  var sHTML1 = "";
  var size = document.form.size_op[document.form.size_op.selectedIndex].value;
  if (size >= 40 && size <= 50) {
    sTitle = "c. Lease Type";
    sHTML1 = "<input type=radio name=leasetype_op value='1' onClick='showFee(true);' class='inputNoBorder'>" +
		"Long Term Lease" +
		"<br>" +
		"<input type=radio name=leasetype_op value='0' onClick='showFee(true);' class='inputNoBorder'>" +
		"Short Term Lease";
  }
  else if (size >= 55 && size <= 110)  {
    sTitle = "c. <span style='text-decoration: underline;'>Lease Type</span>";
    sHTML1 = "Long Term Lease";
  }
  document.getElementById('lease_type_title').innerHTML = sTitle;
  document.getElementById('lease_type').innerHTML = sHTML1;
}

function showSubscriptionFee() {
  valid1 = false;
  var sHTML = "--------";
  if (document.form.membershiptype_op[0].checked) {
    sHTML = "1,740";
    valid1 = true;
  }
  else if (document.form.membershiptype_op[1].checked) {
    sHTML = "1,840";
    valid1 = true;
  }

  document.getElementById('subscription_fee').innerHTML = sHTML;

  if (sHTML != "--------") {
    nTotal += parseInt(sHTML.replace(",", ""), 10);
  }
  else {
    nTotal = 0;
  }
  if (!valid1) {
    nHintType = 1;
    sHintHTML="(Hint: Please select your \"Membership Type\")";
  }
}

function showManagementNRentalFee() {
  valid2 = false;
  valid3 = true;
  valid4 = false;
  var sHTML1 = "--------";
  var sHTML2 = "--------";
  var size = document.form.size_op[document.form.size_op.selectedIndex].value;
  if (size >= 20 && size <= 110)
  	valid2 = true;

  if (size >= 40 && size <= 50 && document.form.leasetype_op != null)  {
	if (document.form.leasetype_op[0].checked ||
		document.form.leasetype_op[1].checked) {
    		valid4 = true;
  	}
  }
  if (document.form.leasetype_op == null) {
     valid4 = true;
  }
  switch(size) {
  	case "20":
  		sHTML1 = "790";
  		sHTML2 = "790";
  		break;
  	case "21":
  		sHTML1 = "790";
  		sHTML2 = "950";
  		break;
  	case "22":
  		sHTML1 = "790";
  		sHTML2 = "1,110";
  		break;
  	case "23":
  		sHTML1 = "790";
  		sHTML2 = "1,280";
  		break;
  	case "24":
  		sHTML1 = "790";
  		sHTML2 = "1,430";
  		break;
  	case "25":
  		sHTML1 = "790";
  		sHTML2 = "1,600";
  		break;
  	case "26":
  		sHTML1 = "790";
  		sHTML2 = "1,750";
  		break;
  	case "27":
  		sHTML1 = "790";
  		sHTML2 = "1,920";
  		break;
  	case "28":
  		sHTML1 = "790";
  		sHTML2 = "2,070";
  		break;
  	case "29":
  		sHTML1 = "790";
  		sHTML2 = "2,240";
  		break;
  	case "30":
  		sHTML1 = "790";
  		sHTML2 = "2,390";
  		break;
  	case "31":
  		sHTML1 = "790";
  		sHTML2 = "2,560";
  		break;
  	case "32":
  		sHTML1 = "790";
  		sHTML2 = "2,720";
  		break;
  	case "40":
		if (document.form.leasetype_op[0].checked) {
  			sHTML1 = "1,470";
  			sHTML2 = "N/A";
		}
		else if (document.form.leasetype_op[1].checked) {
  			sHTML1 = "2,130";
  			sHTML2 = "2,860";
		}
  		break;
  	case "45":
		if (document.form.leasetype_op[0].checked) {
  			sHTML1 = "1,730";
  			sHTML2 = "N/A";
		}
		else if (document.form.leasetype_op[1].checked) {
  			sHTML1 = "2,500";
  			sHTML2 = "3,410";
		}
  		break;
  	case "50":
		if (document.form.leasetype_op[0].checked) {
  			sHTML1 = "2,050";
  			sHTML2 = "N/A";
		}
		else if (document.form.leasetype_op[1].checked) {
  			sHTML1 = "2,890";
  			sHTML2 = "4,070";
		}
  		break;
  	case "55":
  		sHTML1 = "2,460";
  		sHTML2 = "N/A";
  		break;
  	case "60":
  		sHTML1 = "2,860";
  		sHTML2 = "N/A";
  		break;
  	case "70":
  		sHTML1 = "3,590";
  		sHTML2 = "N/A";
  		break;
  	case "75":
  		sHTML1 = "4,120";
  		sHTML2 = "N/A";
  		break;
  	case "100":
  		sHTML1 = "8,780";
  		sHTML2 = "N/A";
  		break;
  	case "110":
  		sHTML1 = "9,660";
  		sHTML2 = "N/A";
  		break;
  	default:
  	  valid3 = false;
  	  break;
  }

  document.getElementById('management_fee').innerHTML = sHTML1;
  document.getElementById('rental_fee').innerHTML = sHTML2;

  if (sHTML1 != "--------" && sHTML1 != "N/A") {
    nTotal += parseInt(sHTML1.replace(",", ""), 10);
  }
  else {
    nTotal += 0;
  }

  if (sHTML2 != "--------" && sHTML2 != "N/A") {
    nTotal += parseInt(sHTML2.replace(",", ""), 10);
  }
  else {
    nTotal += 0;
  }

  if (!valid2 || !valid3) {
    nHintType = 2;
    sHintHTML="(Hint: Please select your \"Boat Size\")";
  }
  else if (!valid4) {
    nHintType = 3;
    sHintHTML="(Hint: Please select the \"Lease Type\")";
  }
}

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}




// ***********************
// hacks and workarounds *
// ***********************

// setup an event handler to hide marinaCalculatorPopups for generic clicks on the document


function initializeHacks() {
  // this ugly little hack resizes a blank div to make sure you can click
  // anywhere in the window for Mac MSIE 5
  if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
  && (navigator.platform.indexOf('Mac') != -1)
  && getStyleObject('blankDiv')) {
    window.onresize = explorerMacResizeFix;
  }
  resizeBlankDiv();
  // this next function creates a placeholder object for older browsers
  createFakeEventObj();
}

function createFakeEventObj() {
  // create a fake event object for older browsers to avoid errors in function call
  // when we need to pass the event object to functions
  if (!window.event) {
    window.event = false;
  }
} // createFakeEventObj

function resizeBlankDiv() {
  // resize blank placeholder div so IE 5 on mac will get all clicks in window
  if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
  && (navigator.platform.indexOf('Mac') != -1)
  && getStyleObject('blankDiv')) {
    getStyleObject('blankDiv').width = document.body.clientWidth - 20;
    getStyleObject('blankDiv').height = document.body.clientHeight - 20;
  }
}

function explorerMacResizeFix () {
  location.reload(false);
}

function getStyleObject(objectId) {
  // cross-browser function to get an object's style object given its id
  if(document.getElementById && document.getElementById(objectId)) {
    // W3C DOM
    return document.getElementById(objectId).style;
  } else if (document.all && document.all(objectId)) {
    // MSIE 4 DOM
    return document.all(objectId).style;
  } else if (document.layers && document.layers[objectId]) {
    // NN 4 DOM.. note: this won't find nested layers
    return document.layers[objectId];
  } else {
    return false;
  }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
  // get a reference to the cross-browser style object and make sure the object exists
  var styleObject = getStyleObject(objectId);
  if(styleObject) {
    styleObject.visibility = newVisibility;
    return true;
  } else {
    // we couldn't find the object, so we can't change its visibility
    return false;
  }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) {
  // get a reference to the cross-browser style object and make sure the object exists
  var styleObject = getStyleObject(objectId);
  if(styleObject) {
    styleObject.left = newXCoordinate;
    styleObject.top = newYCoordinate;
    return true;
  } else {
    // we couldn't find the object, so we can't very well move it
    return false;
  }
} // moveObject

/* *** Login Box Auto Tab *** */
function autotab(original,destination){
	if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
	destination.focus();
}
/* *** End of Login Box Auto Tab *** */




/* ****************************** */
/* *** Header Image Slideshow *** */
/* ***     static layout      *** */
/* ****************************** */
var numberOfHeaderImageArray = new Array();
numberOfHeaderImageArray["golf_club/"] = 6;

/* *** header background *** */
var currentHeaderImageIndex;
function randomHeaderImage(imagePath, newNumberOfHeaderImage) {
	if(!imagePath) imagePath = "";
	if(newNumberOfHeaderImage) numberOfHeaderImage = newNumberOfHeaderImage;
	else if(imagePath != "" && numberOfHeaderImageArray[imagePath]) numberOfHeaderImage = numberOfHeaderImageArray[imagePath];
	currentHeaderImageIndex = parseInt(Math.random()*numberOfHeaderImage);
	for(var index=0; index<numberOfHeaderImage; index++) {
		$('headerImage').innerHTML += "<div id='headerImage"+index+"'><img src='img/header/"+imagePath+"headerImage"+index+".jpg' alt='' /></div>";
		if(index==currentHeaderImageIndex) {
			$('headerImage'+index).style.display = 'block';
		} else {
			new Effect.Fade('headerImage'+index,{duration:0});
		}
	}
	for(var index=0; index<numberOfHeaderImage; index++) {
		$$('#headerImage'+index+' img')[0].style.display = 'block';
	}
	if(numberOfHeaderImage>1) setInterval("rotateHeaderImage();",5000);
}
function rotateHeaderImage() {
	var previousHeaderImageIndex = currentHeaderImageIndex;
	currentHeaderImageIndex += 1;
	currentHeaderImageIndex = currentHeaderImageIndex % numberOfHeaderImage;
	$('headerImage'+previousHeaderImageIndex).style.zIndex = 2;
	$('headerImage'+currentHeaderImageIndex).style.zIndex = 1;
	$('headerImage'+currentHeaderImageIndex).style.display = "block";
	new Effect.Fade('headerImage'+previousHeaderImageIndex,
					{
						duration:2.0,
						afterFinish: function() {
							$('headerImage'+previousHeaderImageIndex).style.zIndex = 1;
						}
					}
	);
}
/* ************************************** */
/* *** End of Header Image Slideshow *** */
/* ************************************** */


//*** This code is copyright 2003 by Gavin Kistner, gavin@refinery.com
//*** It is covered under the license viewable at http://phrogz.net/JS/_ReuseLicense.txt
//*** Reuse or modification is free provided you abide by the terms of that license.
//*** (Including the first two lines above in your source code satisfies the conditions.)
	function FindXY(obj){
		var x=0,y=0;
		while (obj){
			x+=obj.offsetLeft - (obj.scrollLeft || 0);
			y+=obj.offsetTop - (obj.scrollTop || 0);
			obj=null;
		}
		return {x:x,y:y};
	}

	function FindXYWH(obj){
		if (!obj) return { x:0, y:0, w:0, h:0 };
		var objXY = FindXY(obj);
		return { x:objXY.x, y:objXY.y, w:obj.offsetWidth||0, h:obj.offsetHeight||0 };
	}

	function AttachEvent(obj,evt,fnc,useCapture){
		if (obj.addEventListener){
			obj.addEventListener(evt,fnc,useCapture);
			return true;
		} else if (obj.attachEvent) return obj.attachEvent("on"+evt,fnc);
		else obj['on'+evt]=fnc;
		return true;
	}

	function HasClass(obj,cName){ return (!obj || !obj.className)?false:(new RegExp("\\b"+cName+"\\b")).test(obj.className) }
	function AddClass(obj,cName){ if (!obj) return; if (obj.className==null) obj.className=''; return obj.className+=(obj.className.length>0?' ':'')+cName; }
	function KillClass(obj,cName){ if (!obj) return; return obj.className=obj.className.replace(RegExp("^"+cName+"\\b\\s*|\\s*\\b"+cName+"\\b",'g'),''); }



/* *** Replace Quote *** */
function replaceQuote(str, quotetype) {
	if(quotetype==null) {
		str = str.replace(/'/g, "\\\'");
		str = str.replace(/"/g, "\\\"");
	} else if(quotetype=="'") {
		str = str.replace(/'/g, "\\\'");
	} else if(quotetype=='"') {
		str = str.replace(/"/g, "\\\"");
	}
	return str;
}
function replaceQuote2(str, quotetype) {
	str = str.replace(/"/g, "&quot;");
	return str;
}



/* *** Pop Up Window *** */
function showGallery(path) {
	window.open(path, "photo_gallery", "width=800, height=685, channelmode=no, directories=no, fullscreen=no, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, titlebar=yes, toolbar=no");
}



/* *** get element style *** */
function getElementStyle2(elem, IEStyleAttr, CSSStyleAttr) {
    if (elem.currentStyle) {
		var value = elem.currentStyle[IEStyleAttr];
		if(IEStyleAttr.toLowerCase()=="height") return elem.offsetHeight + 'px';
		else if(IEStyleAttr.toLowerCase()=="width") return elem.offsetWidth + 'px';
        else return value;
    } else if (window.getComputedStyle) {
 		if(IEStyleAttr.toLowerCase()=="height") return elem.offsetHeight + 'px';
		else if(IEStyleAttr.toLowerCase()=="width") return elem.offsetWidth + 'px';
		else {
			var compStyle = window.getComputedStyle(elem, "");
			return compStyle.getPropertyValue(CSSStyleAttr);
		}
    }
    return "";
}

/* *** horizontally center element *** */
function horizontal_center(obj, border) {
	if(!border) border = 0;
	var parent_width = parseInt(getElementStyle2(obj.parentNode,'width','width')) - border;
	if(parent_width && parent_width > 0) {
		var obj_width = parseInt(getElementStyle2(obj,'width','width'));
		if(obj_width && obj_width < parent_width) {
			obj.style.marginLeft = parseInt((parent_width - obj_width) / 2) + 'px';
		}
	}
}



/* ******************************* */
/* *** Photo Gallery Slideshow *** */
/* ******************************* */
var current_photoGallery_photoIndex = 0;
var current_photoGallery_pageIndex = 0;
var photoGallery_slideInterval;
var photoGallery_slideIntervalSecond = 7.0;

function photoGallery_init() {
	if(photoGalleryList.length<=0) {
		alert("Warning: No photo is available in the gallery album.");
	} else {
		preview_photoGallery(current_photoGallery_photoIndex);
		photoGallery_buildThumbList(current_photoGallery_pageIndex);
		photoGallery_preview_play();
	}
}
var photoGallery_next_image;
var photoGallery_next_image_timer;
function preview_photoGallery(photoIndex) {
	KillClass($('gallery_slide_loading'),'hide');
	if(photoIndex==null) photoIndex = current_photoGallery_photoIndex;
	var titleText;
	if(photoGalleryList[photoIndex][1] && photoGalleryList[photoIndex][1]!="") {
		titleText = replaceQuote2(photoGalleryList[photoIndex][1]);
	} else {
		titleText = replaceQuote2(photoGalleryList[photoIndex][0]);
	}
	clearTimeout(photoGallery_next_image_timer);
	photoGallery_next_image = new Image();
	photoGallery_next_image.src = photoGalleryRoot + photoGalleryList[photoIndex][0];
	preview_photoGallery2(photoIndex, photoGallery_next_image.src, titleText);
}
function preview_photoGallery2(photoIndex, photoPath, titleText) {
	if(!photoGallery_next_image.complete) {
		photoGallery_next_image_timer = setTimeout("preview_photoGallery2("+photoIndex+", '"+photoPath+"', '"+titleText+"');", 500)
	} else {
		$('gallery_slide').src = photoPath;
		horizontal_center($('gallery_slide_shadow'));
		AddClass($('gallery_slide_loading'),'hide');
		KillClass($('photoGallery'+current_photoGallery_photoIndex),'current');
		current_photoGallery_photoIndex = photoIndex;
		AddClass($('photoGallery'+current_photoGallery_photoIndex),'current');
		if((photoIndex < (current_photoGallery_pageIndex) * numberOfAlbumThumbnailsPerPage) || (photoIndex >= (current_photoGallery_pageIndex + 1) * numberOfAlbumThumbnailsPerPage)) {
			photoGallery_buildThumbList(parseInt(current_photoGallery_photoIndex / numberOfAlbumThumbnailsPerPage));
		}
		clearTimeout(photoGallery_slideInterval);
		photoGallery_slideInterval = setTimeout('photoGallery_preview_next()',photoGallery_slideIntervalSecond*1000);
	}
}

function photoGallery_buildThumbList(pageIndex) {
	if(pageIndex==null) {
		pageIndex = current_photoGallery_pageIndex;
	} else if(pageIndex<0) {
		pageIndex = 0;
	}
	
	var titleText;
	
	var thumbListHTML = "";
	var indexStart = pageIndex * numberOfAlbumThumbnailsPerPage;
	if(pageIndex<=0) {
		AddClass($$('#gallery_carousel_prev a')[0],'invisible');
	} else {
		KillClass($$('#gallery_carousel_prev a')[0],'invisible');
	}
	var indexEnd;
	if(photoGalleryList.length <= (pageIndex + 1) * numberOfAlbumThumbnailsPerPage) {
		indexEnd = photoGalleryList.length;
		pageIndex = parseInt((photoGalleryList.length-1) / numberOfAlbumThumbnailsPerPage);
		AddClass($$('#gallery_carousel_next a')[0],'invisible');
	} else {
		indexEnd = (pageIndex + 1) * numberOfAlbumThumbnailsPerPage;
		KillClass($$('#gallery_carousel_next a')[0],'invisible');
	}
	for(var index=indexStart; index<indexEnd; index++) {
		if(photoGalleryList[index][1] && photoGalleryList[index][1]!="") {
			titleText = replaceQuote2(photoGalleryList[index][1]);
		} else {
			titleText = replaceQuote2(photoGalleryList[index][0]);
		}
		thumbListHTML += '<div class="thumbBorder"><a href="#" id="photoGallery' + index + '" onclick="preview_photoGallery(' + index + ');return false;" title="' + titleText + '" class="thumb" style="background-image:url(\'' + photoGalleryRoot + 'thumb_' + photoGalleryList[index][0] + '\');"><br /></a></div>';
	}
	$$('#gallery_carousel .thumbList')[0].innerHTML = thumbListHTML;

	AddClass($('photoGallery'+current_photoGallery_photoIndex),'current');

	current_photoGallery_pageIndex = pageIndex;
}

function photoGallery_listPrev() {
	current_photoGallery_pageIndex--;
	photoGallery_buildThumbList(current_photoGallery_pageIndex);
}
function photoGallery_listNext() {
	current_photoGallery_pageIndex++;
	photoGallery_buildThumbList(current_photoGallery_pageIndex);
}

function photoGallery_preview_prev() {
	var targetIndex = current_photoGallery_photoIndex - 1;
	if(targetIndex < 0) {
		targetIndex = photoGalleryList.length - 1;
	}
	preview_photoGallery(targetIndex);
}
function photoGallery_preview_next() {
	var targetIndex = current_photoGallery_photoIndex + 1;
	if(targetIndex >= photoGalleryList.length) {
		targetIndex = 0;
	}
	preview_photoGallery(targetIndex);
}
function photoGallery_preview_play() {
	/*
	AddClass($('preview_play'),'hide');
	KillClass($('preview_pause'),'hide');
	*/
	photoGallery_slideInterval = setTimeout('photoGallery_preview_next()',photoGallery_slideIntervalSecond*1000);
}
function photoGallery_preview_pause() {
	/*
	KillClass($('preview_play'),'hide');
	AddClass($('preview_pause'),'hide');
	*/
	clearInterval(photoGallery_slideInterval);
}
/* ************************************** */
/* *** End of Photo Gallery Slideshow *** */
/* ************************************** */

