﻿/// <reference path="~/Themes/Shared/Scripts/jquery.min.js" />
var appointmentList = new Array();

$(document).ready(function () {
	//calendar specific vars
	var month, year, cal;

	//handle search request
	var defaultSearchValue = $(".search-form input").val();
	$(".search-form input").focus(function () {
		if ($(this).val() == defaultSearchValue) {
			$(this).addClass("focused").val("");
		}
	})
	$(".search-form input").blur(function () {
		if ($(this).val() == "") {
			$(this).removeClass("focused").val(defaultSearchValue);
		}
	});

	//handle newsletter request
	var defaultNewsletterValue = $(".newsletter-form input").val();
	$(".newsletter-form input").focus(function () {
		if ($(this).val() == defaultNewsletterValue) {
			$(this).addClass("focused").val("");
		}
	})
	$(".newsletter-form input").blur(function () {
		if ($(this).val() == "") {
			$(this).removeClass("focused").val(defaultNewsletterValue);
		}
	});

	//donate widget
	if ($("#donate").length) {
		var scrollable = $("#donate").scrollable({ circular: true });
	}

	//homepage tabs
	if ($(".tabs").length) {
		$(".tabs").tabs(".panes div");
	}

	/*	if($("#accordion").length){
	$("#accordion").tabs("#accordion .pane", { tabs: 'h2', effect: 'slide', initialIndex: null });
	}*/

	if ($("#calendar").length) {
		setTimeout(function () {
			BuildCalendar("#calendar");
		}, 200);
	}

	//handle calendar popup
	$("div.calendar a").click(function (e) {
		e.preventDefault();
		if ($("#popup").hasClass("init")) {
			$("#popup").data("overlay").load();
		}
		else {
			BuildCalendar("#popup div");
			$("#popup").addClass("init");
			$("#popup").overlay({ load: true, mask: { color: '#dadada' }, left: "360px" });
		}
	});
	$("a.calendar").click(function (e) {
		e.preventDefault();
		if ($("#popup").hasClass("init")) {
			$("#popup").data("overlay").load();
		}
		else {
			BuildCalendar("#popup div");
			$("#popup").addClass("init");
			$("#popup").overlay({ load: true, mask: { color: '#dadada'} });
		}
	});

	//become-a-member 
	if ($("body.become-a-member").length) {
		$("#becomeamember form").submit(function (e) {
			if ($("#email").text() == "") {
				//not logged in - send to registration
				window.location = "/Users/Account/LogOn?ReturnURL=/get-involved/become-a-member";
				return false;
			}
		});
		//downtown bicycle station membership
		$("#rdoYearly").change(function () {
			$("#frmAnnual").show();
			$("#frmMonthly").hide();
			$("#frmMonthlynm").hide();
		});
		$("#rdoMonthly").change(function () {
			if ($("#rdoMonthly").is(":checked")) {
				if (IsMemberChecked()) {
					$("#frmMonthlynm").show();
					$("#frmMonthly").hide();
					$("#frmAnnual").hide();
				}
				else {
					$("#frmMonthly").show();
					$("#frmMonthlynm").hide();
					$("#frmAnnual").hide();
				}
			}
		});
		$("#chkDPMember").change(function () {
			if ($("#rdoMonthly").is(":checked")) {
				if (IsMemberChecked()) {
					$("#frmMonthlynm").show();
					$("#frmMonthly").hide();
					$("#frmAnnual").hide();
				}
				else {
					$("#frmMonthly").show();
					$("#frmMonthlynm").hide();
					$("#frmAnnual").hide();
				}
			}
		});
		$("#chkTnMember").change(function () {
			if ($("#rdoMonthly").is(":checked")) {
				if (IsMemberChecked()) {
					$("#frmMonthlynm").show();
					$("#frmMonthly").hide();
					$("#frmAnnual").hide();
				}
				else {
					$("#frmMonthly").show();
					$("#frmMonthlynm").hide();
					$("#frmAnnual").hide();
				}
			}
		});
	}

	//handle biography overlays
	$("a[rel]").overlay();

	//rotate background - maintain same wallpaper during session
	var wallpaperCount = 4;
	if (!$.cookie("wallpaper")) {
		$.cookie("wallpaper", "bg" + Math.floor(Math.random() * wallpaperCount));
	}
	$("body").addClass($.cookie("wallpaper"));

	//flickr
	if ($(".flickr").length) {
		var count = 12;
		$(".flickr .flickrFeed div a").hide();
		$.getJSON($(".flickr .flickrFeed div a").attr("href"), function (data) {
			$.each(data.items, function (i, item) {
				$("<img/>").attr("src", item.media.m).appendTo(".flickrFeed div")
						.wrap("<a target='_blank' href='" + item.link + "'></a>");
				if (i >= count - 1) return false;
			});
		});
	}

	//calendar filter menu
	// start page w/ filter menu closed
	openCloseMenu();

	// reorder filter menu event
	$('#calendarFilterMenu ul li:not(:first-child) a').click(
		function (event) {
			event.preventDefault();
			sortList(this);
			openCloseMenu();
		}
	);
	// open/close filter menu event
	$('#calendarFilterMenu ul li:first-child').click(
		function (event) {
			event.preventDefault();
			openCloseMenu();
		}
	);

	//donate page
	if ($("body.donate").length) {
		//validate form
		$("form#frmDonate").submit(function () {
			return ValidateForm($("#frmDonate"));
		});

		if ($("#email").text().length > 0) {
			$("#frmDonate .contact").hide();
		}
		else {
			$("#frmDonate .contact").val($("#email").text());
		}
		$("form#frmOneDonation").submit(function () {
			//todo
			//alert("one time");
			//$("#frmDonate").
			//return false;
		});
		$("form#frmSubscription").submit(function () {
			//todo
			//alert("subscription");
			//return false;
		});
		$("input[name=frequency]").change(function () {
			if ($("#onetime").is(":checked")) {
				$("#frmOneDonation").show();
				$("#frmSubscription").hide();
				$("#frmDonate button").hide();
			}
			else if ($("#isRecurring").is(":checked")) {
				$("#frmSubscription").show();
				$("#frmOneDonation").hide();
				$("#frmDonate button").hide();
			}
			else {
				$("#frmSubscription").hide();
				$("#frmOneDonation").hide();
				$("#frmDonate button").show();
			}
			//if ($("#isRecurring").is(":checked"))
			//	$(".isRecurring").show();
			//else
			//	$(".isRecurring").hide();
		});
		$("input[name=chkTribute]").change(function () {
			if ($(this).is(":checked")) {
				$("#isTribute").show();
			} else {
				$("#isTribute").hide();
			}
		});
		$("input[name=rdoTribute]").change(function () {
			if ($(this).val() == "honorOf") {
				$(".inhonorof").show();
				$("span.inmemoryof").hide();
			} else {
				$("span.inmemoryof").show();
				$(".inhonorof").hide();
			}
			//alert($(this).val());
		});
		//$("input[name=
		var defaultDonateValue = $("body.donate #content form input[type=text]").val();
		$("#content form input[type=text]").focus(function () {
			if ($(this).val() == defaultDonateValue) {
				$(this).addClass("focused").val("");
			}
		})
		$("#content form input[type=text]").blur(function () {
			if ($(this).val() == "") {
				$(this).removeClass("focused").val(defaultDonateValue);
			}
		});
	}

	//advocacy
	$("input.policy").change(function () {
		if ($(this).is(":checked")) {
			$("div.policy").show();
		} else {
			$("div.policy").hide();
		}
	});
	$("input.infrastructure").change(function () {
		if ($(this).is(":checked")) {
			$("div.infrastructure").show();
		} else {
			$("div.infrastructure").hide();
		}
	});
	$("form.advocacy-form").submit(function () {
		return ValidateForm($(".advocacy-form"));
	});

	//when logged in on member dashboard
	if ($("body.accessdenied").length > 0 && $("#email").text() != "") {
		$.ajax({
			type: "POST",
			url: "/themes/trailnet/webservice/dpws.aspx/MemberInformation",
			//data: '{"email":"gludius@aol.com"}', //test data
			data: '{"email":"' + $("#email").text() + '"}',
			contentType: "application/json; charset=utf-8",
			dataType: "json",
			success: function (msg) { ShowMemberInfo(msg.d, "memberInformation"); }
		});
	}
	$("#donationHistory").click(function (e) {
		$.ajax({
			type: "POST",
			url: "/themes/trailnet/webservice/dpws.aspx/GetDonationHistory",
			//data: '{"email":"gludius@aol.com"}', //test data
			data: '{"email":"' + $("#email").text() + '"}',
			contentType: "application/json; charset=utf-8",
			dataType: "json",
			success: function (msg) { BuildDonationTable(msg.d, "donationHistory"); }
		});
	});
	$("#eventHistory").click(function (e) {
		alert("2");
	});

	//handle forms
	//newsletter
	$("form.newsletter-form").submit(function (e) {
		e.preventDefault();
		var qs = $(this).serialize();
		alert("#1 " + qs);
		var where = $("form.newsletter-form").attr("action");
		alert("where " + where);
		$.post(where,
			qs); //,
		//function (data) { alert("#2 " + qs); alert("data " + data); });
		/*
		$.ajax({
		type: "POST",
		url: "/Themes/Trailnet/WebService/Newsletter.aspx/HandleNewsletterSubmit",
		data: $.toJSON($(this).serializeObject()),
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		success: function (msg) {
		$("#popup div").html(msg.d);
		$("#popup").overlay({ load: true });
		$("form.newsletter-form input[type=text]").val("");
		},
		error: function () { alert("web method request failed"); }
		});
		*/
		//$(this).slideUp();
		return false;
	});

	//advocacy
	//	$("form.advocacy-form").submit(function (e) {
	//		e.preventDefault();
	//		alert($.toJSON($(this).serializeObject()));
	//		$.ajax({
	//			type: "POST",
	//			url: "/Themes/Trailnet/WebService/Newsletter.aspx/HandleNewsletterSubmit",
	//			data: $.toJSON($(this).serializeObject()),
	//			contentType: "application/json; charset=utf-8",
	//			dataType: "json",
	//			success: function (msg) {
	//				$("#popup div").html(msg.d);
	//				$("#popup").overlay({ load: true });
	//				$("form.newsletter-form input[type=text]").val("");
	//			},
	//			error: function () { alert("web method request failed"); }
	//		});
	//		return false;
	//	});

	//handle flickr scrolling
	var timer; var timer2;
	var offset = 0;
	$("div.flickr a.prev, div.flickrBFC a.prev").hover(function () {
		var element = $(this).next("div.flickrFeed").find("div");
		offset = 3;
		timer = setInterval(function () { FlickrShift(element, offset); }, 30);
	}, function () {
		clearInterval(timer);
		offset = 0;
	}).mousedown(function () {
		var element = $(this).next("div.flickrFeed").find("div");
		offset = 16;
		timer2 = setInterval(function () { FlickrShift(element, offset); }, 30);
	}).mouseup(function () {
		clearInterval(timer2);
		offset = 0;
	});
	$("div.flickr a.next, div.flickrBFC a.next").hover(function () {
		var element = $(this).prev("div.flickrFeed").find("div");
		offset = -3;
		timer = setInterval(function () { FlickrShift(element, offset); }, 30);
	}, function () {
		clearInterval(timer);
		offset = 0;
	}).mousedown(function () {
		var element = $(this).next("div.flickrFeed").find("div");
		offset = -16;
		timer2 = setInterval(function () { FlickrShift(element, offset); }, 30);
	}).mouseup(function () {
		clearInterval(timer2);
		offset = 0;
	});

	//twitter feed
	getTwitters("twitter", {
		id: "trailnet",
		count: 8,
		enableLinks: true,
		ignoreReplies: true,
		clearContents: true,
		newwindow: true,
		template: '"%text%" <a class="status" target="_blank" href="http://twitter.com/%user_screen_name%/status/%id_str%">%time%</a>'
	});
});

/*flickr*/
function FlickrShift(element, offset){
	var left = element.css("left").replace("px","");
	left = parseInt(left) + offset;
	if(left < 0)
		element.css("left", left + "px");
}

/*Calendar Stuff*/
function BuildCalendar(selector) {
	var now = new Date();

	cal = new Calendar(now.getFullYear(), now.getMonth());
	cal.generateHtml();
	$(selector).html(cal.getHtml());

	selector = "table.calendar";
	//handle events
	$(selector + " a.prev").live("click", function (e) {
		e.preventDefault();
		$(selector).empty();
		cal.PreviousMonth();
		cal.generateHtml();
		$(selector).replaceWith(cal.getHtml());
		for (var i = 0; i < appointmentList.length; i++)
			PopulateCalendar(selector, appointmentList[i]);
		if ($("#calendarFilterMenu").length > 0) {
			filterCalendar($("#calendarFilterMenu ul li:first-child").text());
		}
	});
	$(selector + " a.next").live("click", function (e) {
		e.preventDefault();
		$(selector).empty();
		cal.NextMonth();
		cal.generateHtml();
		$(selector).replaceWith(cal.getHtml());
		for (var i = 0; i < appointmentList.length; i++)
			PopulateCalendar(selector, appointmentList[i]);
		if ($("#calendarFilterMenu").length > 0) {
			filterCalendar($("#calendarFilterMenu ul li:first-child").text());
		}
	});

	ShowApptsOnCalendar(selector);
}

function IsMemberChecked() {
	if ($("#chkDPMember").is(":checked") || $("#chkTnMember").is(":checked")) {
		return true;
	}
	return false;
}

function ShowApptsOnCalendar(element) {
	var calendarIds = new Array(5);
	calendarIds[0] = ["cj8k1ie8k7cpbfip7okdi0dtuo%40group.calendar.google.com", "Trailnet Community Rides", "Rides"];
	calendarIds[1] = ["08scnptl35b6hbsd482sr3bl3g%40group.calendar.google.com", "Partner Rides and Events", "PartnerEvents"];
	calendarIds[2] = ["1av06lgo93v8l521hqvn6tgcig%40group.calendar.google.com", "TravelGreen", "TravelGreen"];
	calendarIds[3] = ["j1dd1egsbumjjbc5s7etrsibq8%40group.calendar.google.com", "Community Engagement/Advocacy", "Advocacy"];
	calendarIds[4] = ["7l274injsl2orsas2n1u23cur4%40group.calendar.google.com", "Trailnet Special Events", "SpecialEvents"];
	calendarIds[5] = ["trailnet%40gmail.com", "Bicycle Fun Club Rides", "BFCRides"];

	for (var i = 0; i < calendarIds.length; i++) {
		GetGoogleCalendarFeed(calendarIds[i][0]);
	}

	setTimeout(function () {	//delay to allow ajax to complete
		for (var i = 0; i < appointmentList.length; i++)
			PopulateCalendar(element, appointmentList[i]);
	}, 3000);
}

var appointmentList = new Array();

function GetGoogleCalendarFeed(key) {
	var onlyFutureEvents = true;
	var feedUrl = "http://www.google.com/calendar/feeds/" + key + "/public/full?alt=jsonc&futureevents=" + onlyFutureEvents + "&callback=?";

	var appts = new Array();
	$.getJSON(feedUrl,
		function (msg) {	//onSuccess
			if (msg.error == undefined) {	//...and no errors
				if (msg.data.items != undefined) {
					var title = msg.data.title;
					//get each appointment
					$.each(msg.data.items, function () {
						if (this.when.length > 0) {
							var appt = new Appointment(this.title, this.details, this.location,
								this.when[0].start, this.when[0].end, title);
							appointmentList.push(appt);
						}
					});
				}
			}
		}
	);
}

function PopulateCalendar(element, appt) {
	//date format: 2010-12-15T12:00:00.000-06:00
	var cleanRegex = /\..+$/;
	var datetime = appt.Start().replace(cleanRegex, "");
	var newdate = new Date(getDateFromFormat(datetime, "y-M-dTH:m:s"));
	//get parts
	var itemMonth = newdate.getMonth();
	var itemDay = newdate.getDate();
	var itemYear = newdate.getFullYear();
	var itemMinute = newdate.getMinutes();
	var itemHour = newdate.getHours();
	var meridiam = "am";
	if (itemHour >= 12)
		meridiam = "pm";
	if (itemHour > 12)
		itemHour -= 12;
	//place on calendar
	if (itemYear == cal.Year() && itemMonth == cal.Month()) {
		//iterate through calendar days(cells)
		$(element + " td").each(
			function () {
				if ($(this).text() == itemDay) {
					//place calendar items
					var className = appt.Class().replace(/ /g, "").replace("/", "");
					$(this).append($("<a/>").attr('class', className).attr('title', appt.Title())
					.tooltip({
						effect: "slide",
						position: "center left",
						onBeforeShow: function () {
							$(".tooltip").empty();
							//format minutes to 2 digits
							itemMinute += "";
							if (itemMinute.length == 1)
							{ itemMinute = "0" + itemMinute; }
							//update tooltip text
							$(".tooltip").append("<strong>" + appt.Title() + "</strong><br />"
								+ "<b>Location:</b> " + appt.Location() + "<br />"
								+ appt.Details());// + "<br />"
								//+ "<b>Time:</b> " + itemHour + ":" + itemMinute + " " + meridiam);
						},
						onHide: function () { $(".tooltip").empty(); },
						click: function (e) { e.preventDefault(); }
					}).dynamic({ right: { direction: "right"} }));
				}
			}
		);
	}
}


//calendar filter menu
function sortList(selected) {
	filterCalendar($(selected).text());
	
	var MenuList = new Array();
	$('#calendarFilterMenu ul li').each(function() {
		MenuList.push($(this).text());
	});

	MenuList.splice(0, 0, $(selected).text());
	for(var i = 1; i <= MenuList.length; i++) {
		if( MenuList[0] == MenuList[i] ) {
            MenuList.splice(i, 1);
		}
    }

    for( var z=0; z <= MenuList.length; z++) {
        if( MenuList[z] == "Show All Events" && MenuList[0] != "Show All Events" ) {
            MenuList.splice(z,1);
            MenuList.splice(1,0, "Show All Events");
		}
	}
	for(var x=0; x < MenuList.length; x++) {
		$('#calendarFilterMenu ul li:eq('+x+') a').text(MenuList[x]);
	}
}

function filterCalendar(txt) {
	$(".calendar td a").hide();
	if (txt == "Trailnet Community Rides") {
		$(".TrailnetCommunityRides").show();
	} else if ( txt == "Partner Rides and Events") {
		$(".PartnerRidesandEvents").show();
	} else if ( txt == "TravelGreen") {
		$(".TravelGreen").show();
	} else if ( txt == "Community Engagement/Advocacy") {
		$(".CommunityEngagementAdvocacy").show();
	} else if ( txt == "Trailnet Special Events") {
		$(".TrailnetSpecialEvents").show();
	} else if ( txt == "Bicycle Fun Club Rides") {
		$(".BicycleFunClubRides").show();
	} else if ( txt == "Show All Events") {
		$(".calendar td a").show();
	}
}

function openCloseMenu() {
	if( $('#calendarFilterMenu ul li:not(:first-child)').css("display") == "none") {
		$('#calendarFilterMenu ul li:not(:first-child)').each( function() {
			$(this).css("display", "block");
			//open menu
		});
		$('#calendarFilterMenu ul').css("border-bottom", "2px solid #4C4440");
		$('#calendarFilterMenu ul li:first-child').css("background-position", "right -35px");
		$('#calendarFilterMenu ul li:last-child').css("border-bottom", "none");
	} else {
		$('#calendarFilterMenu ul li:not(:first-child)').each( function() {
			$(this).css("display", "none");
			// close menu
		});
		$('#calendarFilterMenu ul').css("border-bottom", "none");
		$('#calendarFilterMenu ul li:first-child').css("background-position", "right 0");
	}
}

function BuildDonationTable(data, tableId) {
	$("#report").empty();
	if (data == null) {
		$("<p />", { "text": "No donations found." }).appendTo($("#report"));
		return;
	}
	for (var i = 0; i < data.length; i++) {
		if (i == 0) {
			var container = $("<table />", { "id": tableId } );
			$(container).appendTo($("#report"));
			var header = $("<tr><th>Date</th><th>Campaign</th><th>Amount</th></tr>");
			$(header).appendTo($("#report table"));
		}
		var row = $("<tr />");
		$("<td />", { text: data[i].date }).appendTo(row);
		$("<td />", { text: data[i].campaign }).appendTo(row);
		$("<td />", { text: data[i].amount }).appendTo(row);
		$(row).appendTo($("#report table"));
		row = null;
	}
	$("#report").show().slideDown();
}

function ShowMemberInfo(data) {
	$("#status").empty();
	if (data == null) {
		$("<p />", { "text": "No membership information found." }).appendTo($("#status"));
		return;
	}
	//alert(data.expiration);
	//alert(Date.parseString(data.expiration).isAfter(new Date()));

	//if expired
	//if (Date.parse(data.expiration) < Date.today()) {
	//	alert("expired");
	//}
	//if near expiration
	//else if (Date.parse(data.expiration).add({ months: 1 }) > Date.today()){	//near expired
	//		alert("expiration is near");
	//}
	$("<p />", { "html": "<b>" + data.level + "</b><br />"
		+ "Expires: " + data.expiration
	}).appendTo($("#status"));
	switch (data.level) {
		case "Student / Senior":
			$("#frmStudent").show();
			break;
		case "Friend":
			$("#frmFriend").show();
			break;
		case "Explorer":
			$("#frmExplorer").show();
			break;
		case "Pathfinder":
			$("#frmPathfinder").show();
			break;
		case "Trail Blazer":
			$("#frmTrailBlazer").show();
			break;
		case "Peloton Society Bronze $1000":
			$("#frmPelotonBronze").show();
			break;
		case "Peloton Society Silver $2500":
			$("#frmPelotonSilver").show();
			break;
		case "Peloton Society Gold $5000":
			$("#frmPelotonGold").show();
			break;
		default:
			break;
	}
	$("#status").slideDown();
}

/* Accordion Menu */
/*
    with this you can link to a specific accordion tab from any page.
    each h2 in the accordion has a descriptive class attached to it
    each class uses camelCase. the syntax for the anchors is:
    
    #accordion-descriptive<h2>name
    
    description syntax currently in use:
    dates: january2011
    sentences: whatDoesTrailnetDo
    locations: franklinCounty (drop state)
*/


//open tabs from other pages__________________________________
var timer = null;
var aClick = false;
function getFilePath() {
    
    var filepath = window.location.href;
    var accordionClass = "";
    filepath = filepath.split("#").splice(1,1);
    filepath = filepath.toString().split("-");
    
    return filepath;
}

function accordionSetup() {
    var location = getFilePath();
    //open tab from another page
    if( location[0] == "accordion" ){
        accordionClass = location[1];
        openAnchor(accordionClass);
    
    } else if( aClick == false ) {
    
    // close accordion and open any specified tabs    
        $("#accordion .pane").hide();
        $("#accordion h2.current").next().next().slideDown("slow");
	}
    
    clearInterval(timer);
}

function openAnchor(anchor) {
    $("#accordion h2.current").removeClass("current").next().next().slideUp("slow");
    $("#accordion").find("h2."+anchor).addClass("current").next().next().slideDown("slow", function(){ $.scrollTo($(this).prev().prev(), 500, {offset:-10})});
}
//_____________________________________________________________



$(document).ready(function(){
    //accordion set-up
        accordionSetup();
    //__________________________________________________

    // open tab from anchor on same page________________
        $(".page a").click(function(){
            timer = setInterval(accordionSetup, 500); // no way to detect url change that I know of other than using a timer
            aClick = true;                            // functionality is to be implemented in HTML5 but not supported in IE7
        });                                           
    //__________________________________________________

    //standard accordion functionality__________________
        $("#accordion h2").click(function(){
            // find if the selected h2 is currently open
            var h2Class = $(this).attr("class").split(" ");
            for(i=0; i < h2Class.length; i++){
                if( h2Class[i] == "current"){
                    h2Class = "current";
                }
            }
            // if yes, close the tab
            if( h2Class == "current" ) {
            
            $(this).next().next().slideUp("slow", function(){$.scrollTo( $('body'), 1000)});
            $(this).removeClass("current");
            
            } else {
            // otherwise operate normally
            $("#accordion h2.current").removeClass("current").next().next().slideUp("slow");
            $(this).next().next().slideDown("slow", function(){$.scrollTo( $(this).prev().prev(), 500, {offset:-10})});
            $(this).addClass("current");
            
            }
            return false;
        });
    //_____________________________________________________
    
    // open accordions from anchors
    // a class is attached to h2 element in html and a matching
    // class is attached to the anchor that points to the accordion tab.
    // correct usage is city or county, state is omitted
    // use camel casing.  ex. "oldNorthStLouis"
    //
    // in FAQ sections use the first sentance to link to another faq tab.
    // ex. "whatDoesTrailnetDo"
    // if there are two tabs on the same page with the same heading, add a number
    // ex. "motorists2"
    //
    // for dates ex. "february2009"
    //
//    $("#accordion a.anchor").click(function(e){
//       
//        e.preventDefault();
//        var target = $(this).attr("class").split(" ");
//        target = target[1];
//        $("#accordion").find("h2."+target).addClass("current").next().next().slideDown("slow", function(){$.scrollTo( $(this).prev().prev(), 500, {offset:-10})});
//	});
});

$.fn.serializeObject = function () {
	var o = {};
	var a = this.serializeArray();
	$.each(a, function () {
		if (o[this.name]) {
			if (!o[this.name].push) {
				o[this.name] = [o[this.name]];
			}
			o[this.name].push(this.value || '');
		} else {
			o[this.name] = this.value || '';
		}
	//	alert(this.name + " | " + this.value);
	});
	//alert($(this).find("input[type=checkbox]").not(":checked").length);
	//$(this).find("input[type=checkbox]").not(":checked").each(function () {
		//alert($(this).attr("name"));
		//o[$(this).attr("name")].push("off");
	//});
	return o;
};


