jQuery(function($)
{
	$('#subscribe').click(function()
	{
		$('#subscribe_form').slideToggle();
	});

$('#submitcomment').click(function()
{
	var $form = $('#comments_form');
	if ($('#bakecookie').attr('checked'))
 		rememberMe(document.comments_form);
 	else
 		forgetMe(document.comments_form);

	var serial = $form.serialize();

	$('#progress').show();
	
	$.ajax({'type': 'post',
		'url': '/comments.php',
		'data': serial,
		'dataType': 'json',
		'success': function (resp)
			{
				$('#progress').hide();
				var z = $('<div style="background-color:#FF9933;">'+resp.msg+'</div>').animate({ 'backgroundColor':"#F7F6EE" }, 3000);

				// for errors, replace, for valid comments, append
				if (resp.error)
					$('#comment_posted').html(z);
				else
				{
					$('#comment_posted').html('');
					$('#comment_posted').before(z);
				}
				
				$('#scode').val('');
				$.ajax({'type': 'get',
 					'url': '../captcha.inc.php',
					'data': 'display=captcha',
					'cache': false,
					'success': function (r)
						{
							$('#captcha').html(r);
						}
					});
			}
		});

	return false;
});

});




/**************************
PLUGINS
**************************/

/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

(function(jQuery){

	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}

	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break;

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};

})(jQuery);


/* old MT stuff */

//var HOST = '';
// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.

function setCookie (name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
	document.cookie = curCookie;
	// alert("setting cookie "+ curCookie)
}

function getCookie (name) {
	var prefix = name + '=';
	var c = document.cookie;
	// alert ("getting "+document.cookie);
	var nullstring = '';
	var cookieStartIndex = c.indexOf(prefix);
	if (cookieStartIndex == -1)
	return nullstring;
	var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
	if (cookieEndIndex == -1)
	cookieEndIndex = c.length;
	return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
	if (getCookie(name))
	document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
	date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
	var now = new Date();
	fixDate(now);
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	// function setCookie (name, value, expires, path, domain, secure)
	setCookie('cmtauth', f.author.value, now, '/', '', '');
	setCookie('cmtmail', f.email.value, now, '/', '', '');
	setCookie('cmthome', f.url.value, now, '/', '', '');
}

function forgetMe (f) {
	deleteCookie('cmtmail', '/', '');
	deleteCookie('cmthome', '/', '');
	deleteCookie('cmtauth', '/', '');
/*	    f.email.value = '';
	f.author.value = '';
	f.url.value = '';
*/	}


function rememberemail (f) {
	var now = new Date();
	fixDate(now);
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	// function setCookie (name, value, expires, path, domain, secure)

	setCookie('cmtmail', f.email.value, now, '/', '', '');

}

