$(document).ready(function () {
							
	var _host = document.location.host;
	var _url = document.location.href.substring(document.location.href.indexOf(_host)+_host.length).toLowerCase();
	var _anchor;
	var _parent;
	var _anchors = $(document).find('.decorate ul a');
	
	if (_url.indexOf('?') != -1) _url = _url.substring(0,_url.indexOf('?')); // must remove query variables
	
	$(".decorate ul").find("li:first-child").addClass('first');
	$(".decorate ul").find("li:last-child").addClass('last');

	for (var i=0;i<_anchors.length;i++) {
		_anchor = _anchors[i].href.substring(document.location.href.indexOf(_host)+_host.length).toLowerCase();
		_selected = (_anchor == _url);
		_parent = $(_anchors[i]);
		
		// remove mouse events
		_parent.parent('.decorate li').each(function (i) {
			this.onmouseover = null;
			this.onmouseout = null;
			
			if ($(this).children('ul').size() > 0) $(this).addClass('parent');
			
			_textClass = $(this).children('a').text().replace(/[ &]/g, "").toLowerCase();
			if (!$(this).hasClass(_textClass)) $(this).addClass(_textClass);
			
			if (_selected) {
				$(this).addClass('selected');
				$(this).addClass(_textClass + '-selected');
			}
			
			$(this).hover(
				function () { $(this).addClass('hover')},
				function () { $(this).removeClass('hover')}
			);
		});
	}
	
	// fixes for ie
	if ($.browser.msie) {
		var _selectedItem = $("#hd .decorate li.selected");
	
		if (_selectedItem.length > 0) {
			var _position = _selectedItem.position();
			_selectedItem.find('ul').css({'left': _position.left});
		}
	}
});

$(document).ready(function () {
	$("hr").wrap("<div class='hr'></div>");
});




/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/*
 * Login helper
 * http://etraction.co.nz/
 *
 * Copyright (c) 2009 Mark Haussmann
 * Dual licensed under the MIT and GPL licenses.
 *
 * Date: 2009-09-19 17:34:21 -0500 (Thu, 19 Sep 2009)
 */
 
// alters the logins so that they have labels as text in the boxes.
// password field alternates between a password box and a text box.
$(document).ready(function () {
	(function clientlogin() {
		var name = document.getElementById('SZUsername');
		var pword = document.getElementById('SZPassword');
		if (name == undefined || pword == undefined) {return;}
		var defaultNameText = "Name";
		var defaultPwordText = "Password";
		
		name.onblur = function () {  if (this.value == '') { this.value = defaultNameText; } }
		name.onfocus = function () { if (this.value == defaultNameText) { this.value = ''; } }
		pword.onblur = function () {  if (this.value == '') { this.value = defaultPwordText; ChangeInputType(this, 'text'); } }
		pword.onfocus = function () { if (this.value == defaultPwordText) { this.value = ''; ChangeInputType(this, 'password'); } }
		if (name.value == "") { name.value = defaultNameText; }
		if (pword.value == "") { pword.value = defaultPwordText; ChangeInputType(pword, 'text'); }
	}) ();
	
	function ChangeInputType(el, newType){
		if ($.browser.msie) {
			var input2 = document.createElement('input');
			input2.id = el.id;
			input2.value = el.value;
			input2.className = el.className;
			input2.name = el.name;
			input2.onblur = el.onblur;
			input2.onfocus = el.onfocus;
			input2.type = newType;
			
			if (newType == 'password') input2.focus();
			
			el.parentNode.replaceChild(input2,el);
		} else {
			el.type = newType;
		}
	}

	// secure zones are stored in a cookie for users that are logged in
	// they are retrieved once per session from the e360 server on login
	(function setSecureZones() {
		// get cookie
		var myZoneID = $.cookie('quantumsport_securezoneid');
		
		if (myZoneID == null) {
			return false;
		}
		
		$('.hasSecureZoneId a').each(function () {
			$(this).attr('href', $(this).attr('href').replace('[secure_zone_id]', myZoneID));
		});
	}) ();
	
	// booking form
	(function setBookingFormAmount() {
		if ($("div.booking-form").length > 0) {
			var booking_details = $(".booking-details");
			var price = booking_details.text().replace(/\n/g, "").replace(/.*\{price ([^\}]+)\}.*/, "$1").replace(/[^0-9.]+/g, "");
			
			booking_details.html(booking_details.html().replace(/.*\{price ([^\}]+)\}.*/, ""));
			
			$("#amount, #Amount").val(parseInt(price));
		}
	})();
});
	
window.setSecureZoneCookie = function (id) {
	if (id != null) {
		$.cookie('quantumsport_securezoneid', id);
	}
}




