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;
    }
};

jQuery(function(){
	jQuery('#sitetour_toggle').click(function(){
		if (jQuery('#sitetour div.content_max:visible').length > 0) {
			jQuery('#sitetour div.content_max').hide();
			jQuery('#sitetour div.content_min').show();
			jQuery(this).text('+');
		} else {
			jQuery('#sitetour div.content_min').hide();
			jQuery('#sitetour div.content_max').show();
			jQuery(this).text('x');
		}
		return false;
	});
	jQuery('#sitetour_fathersdaycard #sitetour_toggle').click(function(){
		jQuery('#sitetour').hide();
		var date = new Date();
		date.setTime(date.getTime() + (7 * 24 * 60 * 60 * 1000));
		jQuery.cookie('fathersdaycardTourStatus', 'closed', { 'path': '/', 'expires': date });
		return false;
	});
	jQuery('#sitetour_mothersdaycard #sitetour_toggle').click(function(){
		jQuery('#sitetour').hide();
		var date = new Date();
		date.setTime(date.getTime() + (7 * 24 * 60 * 60 * 1000));
		jQuery.cookie('mothersdaycardTourStatus', 'closed', { 'path': '/', 'expires': date });
		return false;
	});
	jQuery('#sitetour_mothersday #sitetour_toggle').click(function(){
		jQuery('#sitetour').hide();
		var date = new Date();
		date.setTime(date.getTime() + (7 * 24 * 60 * 60 * 1000));
		jQuery.cookie('mothersdayTourStatus', 'closed', { 'path': '/', 'expires': date });
		return false;
	});
	jQuery('#sitetour_valentinesday #sitetour_toggle').click(function(){
		jQuery('#sitetour').hide();
		jQuery.cookie('valentinesdayTourStatus', 'closed');
		return false;
	});
	jQuery('#sitetour_nonrenewal #sitetour_toggle').click(function(){
		jQuery('#sitetour').hide();
		jQuery.cookie('nonrenewalTourStatus', 'closed');
		return false;
	});
	jQuery('#sitetour_paymentUpdate #sitetour_toggle').click(function(){
		jQuery('#sitetour').hide();
		jQuery.cookie('paymentUpdateTourStatus', 'closed');
		return false;
	});
	if (jQuery.browser.msie && jQuery.browser.version < 7) {
		// no support for position: fixed
		jQuery('#sitetour').bind('updatePos', function(){
			var offset = jQuery(window).height() - jQuery(this).outerHeight() + jQuery(window).scrollTop();
			jQuery(this).stop().animate({'top': offset + 'px'}, 'fast');
		});
		jQuery('#sitetour').css('bottom', 'auto');
		jQuery('#sitetour').trigger('updatePos');
		jQuery(window).scroll(function(){
			jQuery('#sitetour').trigger('updatePos');
		});
	}
});
