﻿/// <reference path="jquery-1.4.1-vsdoc.js" />

lw.AppendInit(function () {
	var lw = this.lw ? this.lw : {};

	var acc = lw.acc = {};
	acc.waitBeforeAnimate = 1;
	acc.container = $(".accordian");
	acc.containerWidth = acc.container.width();
	acc.containerHeight = acc.container.height();
	acc.items = $(".accordian div.item");

	acc.items.removeClass("_active");

	acc.items.each(function (i) {
		this._index = i;
	});

	acc.preOpen = function (obj, timeout) {
		acc.isOpen = true;

		var wait = 10000;
		if (timeout) {
			wait = timeout;
		}
		if (acc.closeTimeout)
			clearTimeout(acc.closeTimeout);

		if (acc.preOpenItem && acc.preOpenItem._index == this._index)
			return;

		acc.oldItem = acc.preOpenItem;
		acc.preOpenItem = this;

		if (acc.openTimeout)
			clearTimeout(acc.openTimeout);

		acc.openTimeout = setTimeout(acc.open, acc.waitBeforeAnimate * wait);
	};


	acc.disactivateHeader = function (item) {

		var duration = 400;
		var h = $(item).children("div.h");
		h.stop().animate({
			"border-color": "#bababa",
			"background-color": "#cacaca"
		}, duration);
		var h3 = h.children("h3");
		h3.stop().animate({
			color: "#494949"
		}, duration);
		var a = h.children("a");
		a.stop().animate({
			"background-color": "#a6a6a6",
			color: "#474747"
		}, duration);
		var arrow = h.children("span.arrow");
		arrow.animate({
			"background-color": "#dedede",
			"border-color": "#bababa"
		}, duration);
		arrow.removeClass("arrow_up");
	};
	acc.activateHeader = function (item) {
		var duration = 400;
		var h = $(item).children("div.h");
		h.stop().animate({
			"border-color": "#bababa",
			"background-color": "#474747"
		}, duration);
		var h3 = h.children("h3");
		h3.stop().animate({
			color: "#ffffff"
		}, duration);
		var a = h.children("a");
		a.stop().animate({
			"background-color": "#262626",
			color: "#ffffff"
		}, duration);
		var arrow = h.children("span.arrow");
		arrow.animate({
			"background-color": "#919191",
			"border-color": "#bababa"
		}, duration);
		arrow.addClass("arrow_up");
	};

	acc.open = function () {
		var item = acc.preOpenItem;

		for (var i = 0; i <= item._index; i++) {
			$(acc.items[i]).stop().animate({
				top: i * 17
			}, {
				duration: 400,
				easing: "easeOutSine"
			});
			//continue;
			if (i != item._index) {

				acc.disactivateHeader(acc.items[i]);
				$(acc.items[i]).children("div.b").stop().animate({ height: 0 }, { duration: 400 });
			} else {
				acc.activateHeader(acc.items[i]);
				$(acc.items[i]).children("div.b").stop().animate({ height: 94 }, { duration: 400 });
			}
		}

		for (var i = item._index + 1; i < acc.items.length; i++) {
			$(acc.items[i]).stop().animate({
				top: i * 17 + 94
			}, {
				duration: 400,
				easing: "easeOutSine"
			});
			acc.disactivateHeader(acc.items[i]);
			$(acc.items[i]).children("div.b").stop().animate({ height: 0 }, { duration: 400 });
		}
	};

	acc.preClose = function () {
		acc.closeTimeout = setTimeout(acc.close, acc.waitBeforeAnimate * 2 * 1000);
	};

	acc.close = function () {
		return;
		for (var i = 0; i < acc.items.length; i++) {
			$(acc.items[i]).stop().animate({
				left: acc.positions[i]
			}, {
				duration: 800,
				easing: "easeOutSine"
			});
		}
	};

	acc.items.bind("mouseover", acc.preOpen);
	acc.items.bind("click", acc.open);
	acc.items.bind("mouseout", acc.preClose);

	setTimeout(function () {
		$(acc.items[0]).trigger("mouseover", 1);
	}, 100);



	var dur = 300;
	var easing = "easeOutQuad";


	var bgs = {
		"about": "#124d2b",
		"educational": "#175632",
		"community": "#1a6038",
		"network": "#1a6b3c",
		"charter": "#1e7b45",
		"free-schools": "#2a8c53",
		"faq": "#3b9e64",
		"downloads": "#47ae72",
		"contact": "#63c08a",
		"basic": "#186438"
	};
	lw.bgs = [];
	for (i in bgs) {
		lw.bgs.push(bgs[i]);
	}

	$(".menu>li").each(function (i, el) {
		el.menu = createMenu(el, null, i);
	});



	function createMenu(el, parent, i) {
		var m = {};
		m.el = $(el);
		m._index = i;
		m._a = $(el).children("a");

		m._background = lw.bgs[i];
		m._a[0]._background = lw.bgs[i];

		m.el.data("bg", m._background);

		m._a.each(function () {
			if (this.href == location.href) {
				$(this).addClass("_selected");
				m.el.css("background-color", this._background);
				m.el.addClass("fixbg");
				try {
					var p = m.el.parent().parent().parent();
					if (p[0].nodeName.toLowerCase() == "li") {

						p.css("background-color", p.data("bg"));
						p.addClass("fixbg");
					}
				} catch (E) { }
			}
		});

		m.div = $(el).children("div.menu-sub");




		m._ol = m.div.children("ul");
		m.a = m._a[0];
		m.a.menu = m;

		if (m._ol.length > 0) {

			if (m._background) {
				m.div.css("background-color", m._background);
				m._ol.css("background-color", m._background);
			}
			m._a.addClass("haschildren");

			var span = m._a.children("span");

			m.ol = m._ol[0];

			m.li = m._ol.children("li");
			m.maxHeight = m._ol.outerHeight() + 2;
			m.maxWidth = m._ol.outerWidth() + 2;

			m.visible = false;
			m.hideMe = false;
			m.parent = parent;

			m.div[0].menu = m;

			m.children = [];
			m.li.each(function (i, el) {
				m.children.push(el);
				el.menu = createMenu(el, this);
				var $a = $($(this).children("a"));
				if ($(el).children("ul.topmenu-sub").length == 0)
					$a.addClass("arrow1");
			});
			if (m.children.length > 0 && m.parent != null) {
				m._a.addClass("arrow");
			}
		}
		m.show = function () {
			this.hideMe = false;
			if (this.visible)
				return;
			this.visible = true;

			if (m._background) {
				if (!this.el.hasClass("fixbg"))
					this.el.stop().animate({ "background-color": m._background }, dur);
			}
			if (this._ol.length == 0)
				return;

			this.div.css({
				overflow: "visible",
				visibility: "visible",
				width: 0,
				top: this._a.position().top + (m._index == 0 ? -1 : 0),
				left: this._a.position().left + this._a.width()
			});
			this.div.stop();
			var animateTo = { width: this.maxWidth };
			//if (!$.browser.msie)
			$.extend(animateTo, { opacity: 0.99 });
			this.div.animate(animateTo, { duration: dur, easing: easing });
			this._a.addClass("_hover");
		};
		m.hide = function () {
			this.hideMe = true;
			window.setTimeout(function () {
				m._hide();
			}, 50);
		}
		m._hide = function () {
			if (!this.hideMe)
				return;
			this.visible = false;

			if (m._background) {
				if (!this.el.hasClass("fixbg"))
					this.el.stop().animate({ "background-color": bgs.basic }, dur);
			}
			if (this._ol.length == 0)
				return;

			for (var i = 0; i < this.children.length; i++) {
				if (this.children[i].visible)
					return;
			}
			this.div.stop();
			var animateTo = { width: 0 };
			//if (!$.browser.msie)
			$.extend(animateTo, { opacity: 0 });



			this.div.animate(animateTo, { duration: dur / 2, easing: easing,
				complete: function () {
					if (!this.menu.hideMe)
						return;
					this.menu.div.css("visibility", "hidden");
					this.menu._a.removeClass("_hover");
				}
			});
		}

		m._a.bind("mouseover", function () {
			if (this.menu) {
				this.menu.show();
			}
		});
		m._a.bind("mouseout", function () {
			if (this.menu)
				this.menu.hide();
		});
		m.div.bind("mouseover", function () {
			if (this.menu)
				this.menu.show();
		});
		m.div.bind("mouseout", function () {
			if (this.menu)
				this.menu.hide();
		});
		return m;
	}
	function hideMenu(el) {
		window.setTimeout(function () {
			_hideMenu(el);
		}, 200);
	}
	function _hideMenu(el) {
		if (el.childVisible)
			return;
		alert(el);
		el._sub.css("display", "none");
		el._ol.css("height", 0)
		el._a.removeClass("_hover");
	}

	// Reset Font Size
	lw.area = lw.area = $('.resizable-area');
	lw.originalFontSize = lw.area.css('font-size');
	lw.originalLineHeight = parseFloat(lw.area.css("line-height"));
	$(".resetFont").click(function () {
		lw.area.css('font-size', lw.originalFontSize);
		if (!isNaN(lw.originalLineHeight))
			lw.area.css("line-height", lw.originalLineHeight + "px");
	});
	// Increase Font Size
	$(".increaseFont").click(function () {
		var currentFontSize = lw.area.css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize);
		var newFontSize = currentFontSizeNum * 1.2;
		lw.area.css('font-size', newFontSize);
		var currentLineHeight = parseFloat(lw.area.css("line-height"));
		if (!isNaN(currentLineHeight))
			lw.area.css("line-height", (currentLineHeight * 1.15) + "px");
		return false;
	});
	// Decrease Font Size
	$(".decreaseFont").click(function () {
		var currentFontSize = lw.area.css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum / 1.2;
		lw.area.css('font-size', newFontSize);
		var currentLineHeight = parseFloat(lw.area.css("line-height"));
		if (!isNaN(currentLineHeight))
			lw.area.css("line-height", (currentLineHeight / 1.15) + "px");
		return false;
	});
});


lw.AppendInit(function () {
lw.testimonials = $(".testimonials div");
lw.currentTesti = -1;

if (lw.testimonials.length == 0)
    return;

lw.testimonials.each(function (i) {
    /*
    $(this).hide("blind", { percent: 0 }, 1, function () {
    $(this).css("visibility", "visible");
    });
    */
    $(this).height(0).css("visibility", "visible");
});

function nextTesti() {
    if (lw.currentTesti >= 0) {
      	$(lw.testimonials[lw.currentTesti]).animate({ height: 0 }, 1000, "easeOutQuad", showTesti);
    } else {
      	showTesti();
    }
}
function showTesti() {
    lw.currentTesti++;
    if (lw.currentTesti >= lw.testimonials.length)
      	lw.currentTesti = 0;
    $(lw.testimonials[lw.currentTesti]).css("visibility", "visible");
    $(lw.testimonials[lw.currentTesti]).animate({ height: 130 }, 1000, "easeOutQuad", function () {
      	setTimeout(nextTesti, 4000);
    });
}
nextTesti();
});



lw.AppendInit(function () {
$('.flash-animation').flash(null, { version: 10 }, function (htmlOptions) {
    var $this = $(this);
    var params = $this.attr('rel').split(':');
    htmlOptions.src = params[0];
    htmlOptions.width = params[1];
    htmlOptions.height = params[2];
    htmlOptions.wmode = "transparent";
    this.innerHTML = '<div class="alt">' + this.innerHTML + '</div>';
    $this.addClass('flash-animation').prepend($.fn.flash.transform(htmlOptions));
});
});
