﻿function pause() {
	jQuery('#control').html('PLAY').unbind('click').click(function () {
		gallery.play()
	});
}
function play() {
	jQuery('#control').html('PAUSE').unbind('click').click(function () {
		gallery.pause()
	});
}
function mouse_hover() {
	$('#control').stop(true, true).fadeIn();
}
function mouse_out() {
	$('#control').stop(true, true).fadeOut();
}

$(document).ready(function () {
	if ($('#example1').length) {
		gallery = $("#example1").featuredbox({ width: 629,
			height: 231,
			slidesAnimation: "fade",
			startPositionOffsetX: 0,
			startPositionOffsetY: 0,
			slidesSpeed: "slow",
			hParts: 1,
			vParts: 1,
			blocksWaitInterval: 10,
			descriptionAnimation: "fade",
			descriptionSpeed: "slow",
			rotateInterval: 5000,
			slidesReverseAnimation: false,
			slidesPattern: "sequential",
			previous: ".next",
			useFadeIn: true,
			pauseOnMouseHover: false,
			onPause: pause,
			onPlay: play,
			onMouseHover: mouse_hover,
			onMouseOut: mouse_out
		});
	}

	function show() {
		$(this).find('.drop-menu').slideDown();
	}

	function hide() {
		$(this).find('.drop-menu').slideUp();
	}

	$(".nav-div").hoverIntent({
		sensitivity: 1,
		interval: 50,
		over: show,
		timeout: 200,
		out: hide
	});



	$('.account').click(function () {
		if ($(this).parent().hasClass('active')) {
			$(this).parent().find('.login-box-inner').slideToggle(200);
			$(this).parent().removeClass('active');
		} else {
			$(this).parent().find('.login-box-inner').slideToggle(200);
			$(this).parent().addClass('active');
		}
		return false;
	});

	$('.profe').click(function () {
		if ($(this).parent().hasClass('active')) {
			$(this).parent().find('.top-form').slideToggle(200);
			$(this).parent().removeClass('active');
		} else {
			$(this).parent().find('.top-form').slideToggle(200);
			$(this).parent().addClass('active');
		}
		return false;
	});

	$('.printThisPageLink').attr('href', document.URL + '?print=Y');

	$('.emailThisPageLink').attr('href', 'javascript:EmailFriendPopUp("' + document.URL + '");');

});

function DivClick(rssURL, DivID, NumberOfRSSEntries, MoreEntriesLink, MoreEntriesText, ShowTitle, IsBlog) {
	var holder = $("#" + DivID);
	var currentDate = new Date();
	var HTML;
	HTML = "";
	if (IsBlog) {
		HTML += "<h1><span>NAPFA Personal Finance Blog</span><div class='figuide' style='float:none;'><a href='http://www.figuide.com/napfa' target='_blank'><img src='images/FiGuide.gif' alt=''/></a></div></h1>";
	}
	//check to see if if the last load happened in the last 1000*60*10 milliseconds (10 minutes)
	if (holder.attr("LastLoadedDate") == undefined || holder.attr("LastLoadedDate") < currentDate.getTime() - 1000 * 60 * 10) {
		holder.attr("LastLoadedDate", currentDate.getTime());
		holder.html("<img src='/styles/images/loading_gif.gif' alt='loading' width='100px' height=100px' style='padding-left:50px;padding-top:50px;' />");

		$.jGFeed(rssURL + '&t=' + holder.attr("LastLoadedDate").substring(0, 7),
						function (feeds) {
							// Check for errors
							if (!feeds) {
								// there was an error
								HTML = "Sorry, there are no items to display at this time, please come back soon.";
								if (IsBlog) {
									HTML += "<div class='figuide'><a href='http://www.figuide.com/napfa' target='_blank'><img src='images/FiGuide.gif' alt=''/></a></div>"
								}
								holder.html(HTML);
								return false;
							}
							if (IsBlog) {
								HTML += "<br />"
							}
							HTML += " <ul>";
							// do whatever you want with feeds here
							for (var i = 0; i < feeds.entries.length; i++) {
								HTML += " <li>";
								var entry = feeds.entries[i];
								var entrydate = Date.parse(entry.publishedDate);
								//alert(entry.publishedDate);
								// Entry title
								if (ShowTitle) {
									if (entry.title != "") {
										HTML += " <strong>" + entry.title + "</strong>";
									}
								}
								else {
									if (entry.publishedDate != "") {
										HTML += " <strong>" + dateFormat(entrydate, "ddd, mmm. d, yyyy") + "</strong>";
									}
								}
								if (entry.contentSnippet != undefined && entry.contentSnippet != "") {
									HTML += " " + entry.contentSnippet + "<br />";
								}
								if (ShowTitle && entry.author != "" && !IsBlog) {
									HTML += " <span style='color: #A0A0A0;' class='nobr'>" + entry.author + "</span>";
								}else if (ShowTitle && entry.publishedDate != "") {
									HTML += " <span style='color: #A0A0A0;' class='nobr'>" + dateFormat(entrydate, "ddd, mmm. d, yyyy") + "</span>";
								}
								if (entry.link != undefined) {
									HTML += " <a style='float:right;' target='_blank' href='" + entry.link + "'>More</a>";
								}
								HTML += " <br /><br /></li>";
							}
							if (MoreEntriesLink != "") {
								HTML += " <li><a href='" + MoreEntriesLink + "'>" + MoreEntriesText + "</a></li>"
							}
							HTML += " </ul>";
							if (IsBlog) {
								HTML += "<h1>Check out contributions from NAPFA members across the country on all things personal finance.</h1>";
							}
							holder.html(HTML);
						}, NumberOfRSSEntries);
	}
}

function setCookie(c_name, value, exdays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
	c_value = c_value + "; path=/"
	document.cookie = c_name + "=" + c_value;
}

function getCookie(c_name) {
	var i, x, y, ARRcookies = document.cookie.split(";");
	for (i = 0; i < ARRcookies.length; i++) {
		x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
		y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
		x = x.replace(/^\s+|\s+$/g, "");
		if (x == c_name) {
			return unescape(y);
		}
	}
}
