var google_ad_client = "pub-0790470164329359";
var google_ad_slot = "4179536937";
var google_ad_width = 468;
var google_ad_height = 60;

$(function($){
	window['$'] = $;
	if (document.location.hostname != 'devserver')
	$.getScript('http://www.google-analytics.com/ga.js',function(){ _gat._getTracker('UA-15105678-1')._trackPageview(); });
	$('#page-rite .content h1').each(function(){
		if ($(this).find('a').length == 0) $(this).wrapInner('<span/>');
	});
	//COLLAPSE LINK LISTS INTO DROP-DOWN MENUS
	//$link2sel($('.categories ul'),'Select Category',$('<p/>'));
	//$link2sel($('.archives ul'),'Select Month',$('<p/>'));
	
	//PAYPAL SUBSCRIPTION STUFF
	var fn_paypal_upd = function() {
		var $sel = $(this), $opt = $sel.find('option:selected'), str_txt = $opt.text(), re_amt = /: \$([\d\.]+) \/yr/;
		var res = re_amt.exec(str_txt), amt = (res && res[1]) ? res[1] : '0.00';
		$sel.closest('form').find('input[name=amount]').val('$' + amt);
	}
	$('#pay_subscribe select[name=item_name]').bind('change',fn_paypal_upd);
	//FORM AUTOFILL
	$('.autofill').each(function(){
		var val = $(this).attr('fill');
		$(this).val(val);
		$(this)
		.addClass('empty')
		.bind('focus',function(){
			if ($(this).val() == $(this).attr('fill')) $(this).val(''); $(this).removeClass('empty').addClass('focus');
		})
		.bind('blur',function(){
			if ($(this).val() == '') $(this).val($(this).attr('fill')); $(this).removeClass('focus').addClass('empty');
		});
	});
});

function $link2sel($list,str_title,$wrap) {
	var str_title = str_title || 'Go To:';
	var str_id = 'sel_' + Math.ceil(Math.random() * 100000);
	var $sel = $('<select/>').attr({id:str_id});
	$sel.append($('<option/>').attr({'value':'0'}).text(str_title));
	$list.find('a').each(function(i){
		$sel.append($('<option/>').attr({'value':(i+1),'href':this.href}).text($(this).text()));
	});
	if ($wrap) $sel = $wrap.append($sel);
	$list.replaceWith($sel);
	$('#' + str_id).change(function(){
		$self = $(this.options[this.selectedIndex]);
		if ($self.val() > 0) document.location.href = $self.attr('href');
	});
}
