$(document).ready(function() {
	// Defaults
	var _employeeDefaultHeight = "52px";
	var _blogDefaultHeight = "52px";
	var _animationLength = 250;

	// ***************************
	// ** Employee of the Month **
	// ***************************

	// Save all the current heights of the blocks and close them up
	var blockHeights = new Array();
	$(".employee .block").each(function(i) {
		blockHeights[i] = $(this).height();
		$(this).css({ height: _employeeDefaultHeight });
	});

	// Read More:
	$(".employee a.active1").click(function() {
		// Find the sibling block element and animate it back to the original height that was stored in the height Array
		// Then hide the link and show the sibling "close" element
		$(this).siblings("div.slide-holder").find(".block").animate({ height: blockHeights[$(".employee .block").index($(this).siblings("div.slide-holder").find(".block"))] + "px" }, _animationLength, "swing").end().end().hide().siblings("a.noactive").show();
		return false;
	});

	// Close:
	$(".employee a.noactive").click(function() {
		// Find the sibling block element and animate it back to the original height that was stored in the height Array
		$(this).siblings("div.slide-holder").find(".block").animate({ height: _employeeDefaultHeight }, _animationLength, "swing").end().end().hide().siblings("a.active1").show();
		return false;
	});

	// Other Nominees:
	$(".block .link-view-holder").click(function() {
		// Hide the link and set the parent block's height to automatically expand if necessary
		$(this).hide().parents(".block").css({ height: "auto" });
		// Grab the inner content and slide it down
		$(this).siblings(".block-text").slideDown(_animationLength, function() {
			// When the animation is complete, update the height of the entire block by adding the height of the expanded nominees section
			blockHeights[$(".employee .block").index($(this).parents("div.slide-holder").find(".block"))] += $(this).height();
		});
	});

	$(".searchBox .text1").Watermark("Search");

	$(".sel", "#calendar").hover(
		function() {
			$(".list-date a").removeClass("hover");
			$(".list-date a[title='" + $(this).find("a").attr("title") + "']").addClass("hover");
		},
		function() {
			$(".list-date a").removeClass("hover");
		}
	);

	$(".sidebar a[href*='/Media/Videos/']").colorbox({
		html: "<div id='video' style='margin: 0; padding: 0; overflow: hidden; width: 600px; height: 480px;'>Loading...</div>",
		initialWidth: 100,
		initialHeight: 100,
		close: "Close Video",
		onComplete: function() {
			var href = $(this).attr("href");
			flowplayer("video", { src: "/Site/Flash/flowplayer-3-1-5.swf", width: 600, height: 450 }, {
				clip: {
					autoPlay: true,
					autoBuffering: true
				},
				playlist: [href, { url: href, autoPlay: true}],
				plugins: {
					controls: { url: "flowplayer-controls-3-1-5.swf" }
				}
			});
			flowplayer("video", { src: "/Site/Flash/flowplayer-3-1-5.swf", width: 600, height: 450 }, {
				clip: {
					autoPlay: true,
					autoBuffering: true
				},
				playlist: [href, { url: href, autoPlay: true}],
				plugins: {
					controls: { url: "flowplayer-controls-3-1-5.swf" }
				}
			});
		},
		onCleanup: function() {
			$("#video").html('');
		}
	});

	// ***************************
	// ** Blog **
	// ***************************

	// Save all the current heights of the blocks and close them up
	var blogHeights = new Array();
	$(".list-slide .block").each(function(i) {
		blogHeights[i] = $(this).height();
		$(this).css({ height: _blogDefaultHeight });
	});

	// Read More:
	$(".list-slide a.noactive-link").click(function() {
		// Find the sibling block element and animate it back to the original height that was stored in the height Array
		// Then hide the link and show the sibling "close" element
		$(this).parents(".slide-holder2").siblings(".slide-holder").find(".block").animate({ height: blogHeights[$(".list-slide .block").index($(this).parents(".slide-holder2").siblings("div.slide-holder").find(".block"))] + "px" }, _animationLength, "swing").end().end().end().hide().siblings("a.active-link").show();
		return false;
	});

	// Close:
	$(".list-slide a.active-link").click(function() {
		// Find the sibling block element and animate it back to the original height that was stored in the height Array
		$(this).parents(".slide-holder2").siblings(".slide-holder").find(".block").animate({ height: _blogDefaultHeight }, _animationLength, "swing").end().end().end().hide().siblings("a.noactive-link").show();
		return false;
	});

	// ***************************
	// ** Brag Box              **
	// ***************************

	//	// Save all the current heights of the blocks and close them up
	//	var bragHeights = new Array();
	//	$(".list-brag .open-box").each(function(i){
	//		bragHeights[i] = $(this).height();
	//		$(this).css({height: _bragBoxDefaultHeight});
	//	});
	//	
	//	// Read More:
	//	$(".list-brag a.active1").click(function(){
	//		// Find the sibling block element and animate it back to the original height that was stored in the height Array
	//		// Then hide the link and show the sibling "close" element
	//		$(this).siblings("div.box02").find(".open-box").animate({height: bragHeights[$(".list-brag .open-box").index($(this).siblings("div.box02").find(".open-box"))] + "px"}, _animationLength, "swing").end().end().hide().siblings("a.noactive").show();
	//		return false;
	//	});
	//	
	//	// Close:
	//	$(".list-brag a.noactive").click(function(){
	//		// Find the sibling block element and animate it back to the original height that was stored in the height Array
	//		$(this).siblings("div.box02").find(".open-box").animate({height: _bragBoxDefaultHeight}, _animationLength, "swing").end().end().hide().siblings("a.active1").show();
	//		return false;
	//	});

	addClass({
		tagName: 'a',
		tagClass: 'link-open',
		classAdd: 'div-parent-open',
		addToParent: true
	});

	var _parentSlide = '.list-brag .slide-block';
	var _linkSlide = 'a.open-close';
	var _slideBlock = 'div.block';
	var _openClassS = 'active';
	var _durationSlide = 250;
	var _textOpenS = "Read more";
	var _textCloseS = "Close";

	// Set initial state of full text to hidden
	$(_parentSlide).each(function() {
		if (!$(this).is('.' + _openClassS)) {
			$(this).find(_slideBlock).css('display', 'none');
		}
	});

	// Read More / Close link
	$(_linkSlide, _parentSlide).click(function() {
		if ($(this).parents(_parentSlide).is('.' + _openClassS)) {
			$(this).text(_textCloseS).parents(_parentSlide).removeClass(_openClassS).find(_slideBlock).slideUp(_durationSlide);
		} else {
			$(this).text(_textOpenS).parents(_parentSlide).addClass(_openClassS).find(_slideBlock).slideDown(_durationSlide);
		}
		return false;
	});

	$(".tips p").qtip({
		show: { delay: 0 }, hide: { fixed: true, delay: 200 }, position: { corner: { target: 'leftMiddle', tooltip: 'rightBottom' }, adjust: { x: -10, y: 0} }, style: { name: 'light', width: 500, border: { width: 6, radius: 8, color: "#0066A4" }, tip: { corner: 'rightBottom', color: '#0066A4'} }
	});

	$(".breadcrumbs").prepend("<a href='/'>Home</a>");

	$(".aside2 li:first").hide();

	$(".sel1").change(function() {
		if ($(".sel1 option:eq(0)") != $(".sel1 option:selected")) {
			window.open($(this).val());
		}
	});

	// add the event name and date into CME form
	var eventName = $(".event-content .title h2").html();
	var eventDate = $(".event-content .date h3").html();
	if (eventName != null && eventName.length > 0) {
		$(".event-content .cme-event-name").val(eventName).attr("readonly", "readonly");
		if (eventDate.length > 0) {
			$(".event-content .cme-event-date .CalendarTextBox").val(eventDate).attr("readonly", "readonly").after("<a>&nbsp;</a>");
			$(".event-content .CalendarIcon").hide();
			$(".event-content .CalendarAction").hide();
		}
	}

	// File Icons
	$(".text ul li a[href$='.pdf']").parents("li").css({ background: "url('/App_Themes/Default/Images/FileIcons/List/pdf.gif') no-repeat 0 0" });
	$(".text ul li a[href$='.ppt']").parents("li").css({ background: "url('/App_Themes/Default/Images/FileIcons/List/ppt.gif') no-repeat 0 0" });
	$(".text ul li a[href$='.pptx']").parents("li").css({ background: "url('/App_Themes/Default/Images/FileIcons/List/ppt.gif') no-repeat 0 0" });
	$(".text ul li a[href$='.doc']").parents("li").css({ background: "url('/App_Themes/Default/Images/FileIcons/List/doc.gif') no-repeat 0 0" });
	$(".text ul li a[href$='.docx']").parents("li").css({ background: "url('/App_Themes/Default/Images/FileIcons/List/doc.gif') no-repeat 0 0" });
});

$(window).load(function() {
	// ***************************
	// ** Organizational Goals  **
	// ***************************
	
	$('ul.accordion').accordion({ 
        autoheight: false,
        header: ".opener",
        active: 0,
        selectedClass: 'active',
        alwaysOpen: false,
        event: "click"
    });
});

function addClass (_options) {
	var _tagName = _options.tagName;
	var _tagClass = _options.tagClass;
	var _classAdd = _options.classAdd;
	var _addToParent = false || _options.addToParent;
	var _el = document.getElementsByTagName(_tagName);
	if (_el) {
		for (var i=0; i < _el.length; i++) {
			if (_el[i].className.indexOf(_tagClass) != -1) {
				_el[i].onclick = function() {
					if (_addToParent) {
						if (this.parentNode.className.indexOf(_classAdd) == -1) {
							this.parentNode.className += ' '+_classAdd;
						} else {
							this.parentNode.className = this.parentNode.className.replace(_classAdd,'');
						}
					} else {
						if (this.className.indexOf(_classAdd) == -1) {
							this.className += ' '+_classAdd;
						} else {
							this.className = this.className.replace(_classAdd,'');
						}
					}
					return false;
				}
			}
		}
	}
}
