/*****************************************************************************
The sIFR configuration should typically go in `sifr-config.js`, but in order to
keep the config file clean, and to give a quick overview, it's done here instead.
*****************************************************************************/

// sIFR

var neva = {
    src: '/flash/WaterClub/neva.swf'
};

var credo = {
    src: '/flash/WaterClub/RTFCredoPro.swf'
};

sIFR.activate(neva);

sIFR.replace(neva, {
    selector: '.scfForm h1'
	, wmode: 'transparent'
	, css: { '.sIFR-root': { 'margin': '0px', 'font-style': 'normal', 'font-size': '17px', 'color': '#8e8064'} }
});

sIFR.replace(neva, {
    selector: '#section-content-left h1'
	, wmode: 'transparent'
	, css: ['.sIFR-root { margin: 0px; font-style: normal; font-size: 35px; color: #8e8064; }']
});

sIFR.replace(neva, {
    selector: 'h1'
	, wmode: 'transparent'
	, css: ['.sIFR-root { margin: 0px; font-style: normal; font-size: 26px; color: #8e8064; }']
});

sIFR.replace(neva, {
    selector: 'h4'
  , css: [
    '.sIFR-root { margin: 0px; font-style: normal; font-size: 14px; color: #8e8064; }'
  ]
});

sIFR.replace(neva, {
    selector: '#hero-banner-bottom h2'
	, wmode: 'transparent'
	, css: { '.sIFR-root': { 'margin': '0px', 'font-style': 'normal', 'font-size': '19px', 'color': '#ad9a7f', 'text-transform': 'lowercase'} }
});

sIFR.replace(credo, {
    selector: 'h3'
	, wmode: 'transparent'
	, css: { '.sIFR-root': { 'margin': '0px', 'font-style': 'normal', 'font-size': '17px', 'color': '#8e8064'} }
});

sIFR.replace(neva, {
    selector: '#events-title h2'
	, wmode: 'transparent'
	, css: { '.sIFR-root': { 'margin': '0px', 'font-style': 'normal', 'font-size': '17px', 'color': '#8e8064'} }
});




jQuery(function () {

	// Datepicker
	jQuery(".datepicker").datepicker({
		showOn: "both",
		buttonImage: "/images/WaterClub/bkg-date-picker.gif",
		buttonImageOnly: true
	});


	var todayDate = new Date();
	var todayDay = todayDate.getDate();
	var todayMonth = todayDate.getMonth() + 1;
	var todayYear = todayDate.getFullYear();

	jQuery(".datepicker").attr("value", todayMonth + "/" + todayDay + "/" + todayYear);

	// QA
	jQuery(".q-a > a").click(function () {
		jQuery('.answer').slideUp(200);
		if (jQuery(this).next().is(':hidden') == true) {
			jQuery(this).next().slideDown(200);
		} 
		return false;
	});

	/*
	// Event table modal
	jQuery(".event-table tr").hover(
	function () { jQuery(this).addClass("hover"); },
	function () { jQuery(this).removeClass("hover"); }
	);

	jQuery(".event-table tr").click(function () {
	jQuery(".event-modal").hide();
	jQuery(this).children().children(".event-modal").show();
	return false;
	});

	jQuery("a.more-info").click(function () {
	jQuery(".event-modal").hide();
	jQuery(this).parent().parent().children().children(".event-modal").show();
	return false;
	});

	jQuery(".modal-close").click(function () {
	jQuery(".event-modal").hide();
	return false;
	});

	*/
	// collapsable rows
	jQuery(".collapse-anchor").toggle(
		function () {
			jQuery(".collapse-anchor:not('this')").siblings(".collapse-content").slideUp();
			jQuery(this).siblings(".collapse-content").slideDown();
			return false;
		},
		function () {
			jQuery(this).siblings(".collapse-content").slideUp();
			return false;
		}
	);

	// collapsable location rows
	$(".location-show-hide-last a, .location-show-hide a").toggle(
		function () {
			$(".show-hide-ul").slideUp("fast");
			$(this).siblings(".show-hide-ul").slideDown("fast");
			return false;
		},
		function () {
			$(this).siblings(".show-hide-ul").slideUp("fast");
			return false;
		}
	);
});







/* ====================================== */
/* HERO IMAGE                             */
/* ====================================== */

var isIE = (navigator.userAgent.indexOf("MSIE") != -1);
var isIE = /MSIE ((5\.5)|[6789])/.test(navigator.userAgent) &&
				navigator.platform == "Win32";

var selfClosingTags = /br|img|hr|div/;
var condenseWhite = /[\s]+/g;
var trimWhite = /(^\s|\s$)+/g;

function getSource(elem) {

    if (elem.nodeType == 3) {
        return elem.nodeValue.replace(condenseWhite, ' ').replace(trimWhite, '');
    } else if (elem.nodeType != 1) {
        return "";
    }

    var name = elem.nodeName.toLowerCase();
    var str = "<" + name;

    var a = elem.attributes;
    var i = 0;
    var attr, attrn, attrv;
    while (attr = a[i++]) {
        attrn = attr.nodeName;
        attrv = attr.nodeValue;
        if (!attr.specified || attrv == '') { continue };
        if (isIE && attrn == 'style') {
            str += ' style="' + elem.style.cssText.toLowerCase() + '"';
        } else {
            str += ' ' + attrn + '="' + attrv + '"';
        }
    }

    if (!elem.hasChildNodes()) {
        if (selfClosingTags.test(name)) {
            str += ' />';
        } else {
            str += '>';
        }
    } else {
        str += '>'
        var child = elem.firstChild;
        for (child; child != null; child = child.nextSibling) {
            str += getSource(child);
            getSource(child);
        }
        str += '</' + name + '>';
    }

    return str;

}

function getSourceById(id) {
    return getSource(document.getElementById(id));
}




/*------------- Flash Wave --------------------------*/

jQuery(window).load(function () {
    var waveAttributes
    var waveParams = { menu: false, wmode: "opaque", base: "." };
    swfobject.embedSWF("/flash/WaterClub/wave_slow_v2.swf", "footer-wave", "100%", "150", "8.0.0", "/js/expressInstall.swf", false, waveParams, waveAttributes, hideShowWave);

    function hideShowWave(e) {
        if (e.success) {
        } else {
            jQuery("#footer-wave img").show();
        }
    }
});











/*------------- Popups --------------------------*/

function popupWindow(url, name, width, height, properties) {
    if (!name) name = "popWin";
    if (!width) width = "700";
    if (!height) height = "480";
    var features = "width=" + width + ",height=" + height;

    if (!properties || properties == false) {
        features += ",left=100,top=100,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,scrollbars=1";
    } else {
        features += properties;
    }
    var popWin = window.open(url, name, features);
    checkPopped(popWin);
}
function checkPopped(winName) {
    if (winName)
        winName.focus();
    else {
        var popupWarning = "Pop-up blocking software in your browser has prevented us from opening a new window. In order for this site to function properly please disable your Pop-up blocking software for this site.";
        alert(popupWarning);
    }
}

jQuery(document).ready(function ($) {
    $("a").not(".popup").each(function (i, d) {
        var href = $(d).attr("href");
        if (href == null) return;
        if (href.indexOf("?") != -1 && href.indexOf("javascript:popupWindow") == -1) {
            var query = href.substring(href.indexOf("?") + 1);
            var isPopup = href.indexOf("popupWidth=") != -1 || href.indexOf("popupHeight=") != -1;
            if (isPopup) {
                $(d).addClass("popup");
            }
        }

        if (href.indexOf("javascript:popupWindow") == 0) {
            $(d).removeAttr("target");
        }
    });

    $("a.popup").each(function (i, d) {
        $(d).removeAttr("target");
    });

    $("a.popup").click(function (e) {
        return callPopup($(this));
    });
});

function callPopup(anchor) {
    var href = anchor.attr("href");
    if (href.indexOf("?") != -1) {
        var query = href.substring(href.indexOf("?") + 1);
        var width, height;
        if (query.indexOf("popupWidth") != -1) {
            var split = query.split("&");
            for (var i = 0; i < split.length; i++) {
                var nameVal = split[i].split("=");
                if (nameVal[0] == "popupWidth") width = parseInt(nameVal[1]);
                if (nameVal[0] == "popupHeight") height = parseInt(nameVal[1]);
            }
        }
    }

    if (isNaN(width)) width = 750;
    if (isNaN(height)) height = 650;
    popupWindow(href, "popupWindow", width, height);
    return false;
}
