		var _gaq = _gaq || [];
		 _gaq.push(['_setAccount', 'UA-27189539-1']);
		 _gaq.push(['_trackPageview']);

		 (function() {
		   var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		   ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		 })();
				$(document).ready(function(){			
			$(".armyBox").live("click", function(){
				/* helper stuff */
				function parseQuery ( query ) {
				   var Params = {};
				   if ( ! query ) {return Params;}// return empty object
				   var Pairs = query.split(/[;&]/);
				   for ( var i = 0; i < Pairs.length; i++ ) {
				      var KeyVal = Pairs[i].split('=');
				      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
				      var key = unescape( KeyVal[0] );
				      var val = unescape( KeyVal[1] );
				      val = val.replace(/\+/g, ' ');
				      Params[key] = val;
				   }
				   return Params;
				}
				function position() {
					popup.css({marginLeft: '-' + parseInt((popupW / 2),10) + 'px', width: popupW + 'px'});
					if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
						popup.css({marginTop: '-' + parseInt((popupH / 2),10) + 'px'});
					}
				}

				/* the nitty gritty. append overlay and popup divs, position them, and load them with content */
				if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
					$("body","html").css({height: "100%", width: "100%"});
					$("html").css("overflow","hidden");
					$("select").hide();
				}
				if(document.getElementById("overlay") === null){
					$("body").append("<div id='overlay'></div><div id='popup'></div>");
				}

				var overlay = $("#overlay");
				var popup = $("#popup");
				var url;
				url = $(this).attr("href");
				if (typeof(url) === "undefined"){
					url = $(this).attr("value");
				}
				var queryString = url.replace(/^[^\?]+\??/,'');
				var params = parseQuery(queryString);
				var popupW = (params['width']*1) || 668; //defaults to 668 if no paramaters were added to URL
				var popupH = (params['height']*1) || 600; //defaults to 600
				var current = (params['curr']) || 999; //defaults to 999

				position();

				if(document.getElementById("ajaxContent") != null){ // if popup already defined, just load new content
					$.ajax({
					  	url: url,
						cache: false,
						success: function(html){
							$("#ajaxContent").html(html);
							popup.fadeIn(300);
							if (window.init){ // if init() is defined, call it. use init() for any script that needs to run after the popup loads
								init();
							}
						}
					});
				}
				else {
					popup.append("<a href='' id='closeWindowButton'><span class='hide'>close</span></a><div id='ajaxContent' style='width:"+popupW+"px;height:"+popupH+"px'></div>");
					$("#closeWindowButton").css({
						"position":"relative",
						"left":popupW-30
					});
					$.ajax({
					  	url: url,
						cache: false,
						success: function(html){
							$("#ajaxContent").html(html);
							popup.fadeIn(300);
							if (window.init && current != 999){	// if curr is set, we're editing media detail, so call init() on the review media popup
								init(current);
							}
						}
					});
				}
				return false;
			}); // end armyBox click function

			$("#closeWindowButton").live("click", function(){
				var overlay = $("#overlay");
				var popup = $("#popup");
				popup.fadeOut(300, function(){
					popup.unbind().remove();
					overlay.unbind().remove();
				});
				if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
					$("body","html").css({height: "auto", width: "auto"});
					$("html").css("overflow","");
					$("select").show();
				}
				return false;
			});

		});
		
		$(document).ready(function(){
			$("body").append('<div id="overlays"><div id="overlayAll"></div></div>');
			var overlays = $("#overlays");
			var borderWidth = 6;
			var counter = 0;
			
			function setOverlays(){
				var container = $("#pageManagementCol #container");
				var cPos = container.offset();
				var cHeight = container.height();
				var cWidth = container.width();
				$("#overlayAll").css({
					"position":"absolute",
					"top":cPos.top,
					"left":cPos.left,
					"height":cHeight,
					"width":cWidth,
					"z-index":1200
				});
				
				$(".widgetBox").each(function(){
					var pos = $(this).offset();
					var height = $(this).height();
					var width = $(this).width();
					var sectionID = $(this).attr('value');
					if (counter == 0){
						overlays.append('<div id="overlay_' + sectionID + '"><a class="armyBox" href="/webpages/manage_page/?asset='+$(this).attr('name')+'&aid='+sectionID+'"></a><span class="overlayFill"></span><span class="overlayEffects"></span><span class="widgetEditIcon"></span></div>');
					}
					$("#overlay_" + sectionID + ", #overlay_" + sectionID + " a, #overlay_" + sectionID + " .overlayFill, #overlay_" + sectionID + " .overlayEffects").css({
						"position":"absolute",
						"height":height - borderWidth,
						"width":width - borderWidth
					});
					$("#overlay_" + sectionID).css({
						"top":pos.top,
						"left":pos.left,
						"z-index":1201
					}).addClass("overlay");
					$("#overlay_" + sectionID + " a").css({
						"top":0,
						"left":0,
						"z-index":1299
					});
					$("#overlay_" + sectionID + " .overlayFill").css({
						"top":0,
						"left":0,
						"z-index":1202
					});
					$("#overlay_" + sectionID + " .overlayEffects").css({
						"top":0,
						"left":0,
						"z-index":1203
					});
				});
				counter = 1;
			}
			
			$(window).resize(function(){
				setOverlays();
			});
			$(window).load(function(){
				setOverlays();
			});

			$(".overlay a").live("mouseover", function(){
				$(this).parent().addClass("hover");
			});
			$(".overlay a").live("mouseout", function(){
				$(this).parent().removeClass("hover");
			});

		});	
				/*! Copyright (c) 2008 Brandon Aaron (http://brandonaaron.net)
		 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
		 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
		 *
		 * Version: 1.0.3
		 * Requires jQuery 1.1.3+
		 * Docs: http://docs.jquery.com/Plugins/livequery
		 */

		(function($) {

		$.extend($.fn, {
			livequery: function(type, fn, fn2) {
				var self = this, q;

				// Handle different call patterns
				if ($.isFunction(type))
					fn2 = fn, fn = type, type = undefined;

				// See if Live Query already exists
				$.each( $.livequery.queries, function(i, query) {
					if ( self.selector == query.selector && self.context == query.context &&
						type == query.type && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) )
							// Found the query, exit the each loop
							return (q = query) && false;
				});

				// Create new Live Query if it wasn't found
				q = q || new $.livequery(this.selector, this.context, type, fn, fn2);

				// Make sure it is running
				q.stopped = false;

				// Run it immediately for the first time
				q.run();

				// Contnue the chain
				return this;
			},

			expire: function(type, fn, fn2) {
				var self = this;

				// Handle different call patterns
				if ($.isFunction(type))
					fn2 = fn, fn = type, type = undefined;

				// Find the Live Query based on arguments and stop it
				$.each( $.livequery.queries, function(i, query) {
					if ( self.selector == query.selector && self.context == query.context && 
						(!type || type == query.type) && (!fn || fn.$lqguid == query.fn.$lqguid) && (!fn2 || fn2.$lqguid == query.fn2.$lqguid) && !this.stopped )
							$.livequery.stop(query.id);
				});

				// Continue the chain
				return this;
			}
		});

		$.livequery = function(selector, context, type, fn, fn2) {
			this.selector = selector;
			this.context  = context || document;
			this.type     = type;
			this.fn       = fn;
			this.fn2      = fn2;
			this.elements = [];
			this.stopped  = false;

			// The id is the index of the Live Query in $.livequery.queries
			this.id = $.livequery.queries.push(this)-1;

			// Mark the functions for matching later on
			fn.$lqguid = fn.$lqguid || $.livequery.guid++;
			if (fn2) fn2.$lqguid = fn2.$lqguid || $.livequery.guid++;

			// Return the Live Query
			return this;
		};

		$.livequery.prototype = {
			stop: function() {
				var query = this;

				if ( this.type )
					// Unbind all bound events
					this.elements.unbind(this.type, this.fn);
				else if (this.fn2)
					// Call the second function for all matched elements
					this.elements.each(function(i, el) {
						query.fn2.apply(el);
					});

				// Clear out matched elements
				this.elements = [];

				// Stop the Live Query from running until restarted
				this.stopped = true;
			},

			run: function() {
				// Short-circuit if stopped
				if ( this.stopped ) return;
				var query = this;

				var oEls = this.elements,
					els  = $(this.selector, this.context),
					nEls = els.not(oEls);

				// Set elements to the latest set of matched elements
				this.elements = els;

				if (this.type) {
					// Bind events to newly matched elements
					nEls.bind(this.type, this.fn);

					// Unbind events to elements no longer matched
					if (oEls.length > 0)
						$.each(oEls, function(i, el) {
							if ( $.inArray(el, els) < 0 )
								$.event.remove(el, query.type, query.fn);
						});
				}
				else {
					// Call the first function for newly matched elements
					nEls.each(function() {
						query.fn.apply(this);
					});

					// Call the second function for elements no longer matched
					if ( this.fn2 && oEls.length > 0 )
						$.each(oEls, function(i, el) {
							if ( $.inArray(el, els) < 0 )
								query.fn2.apply(el);
						});
				}
			}
		};

		$.extend($.livequery, {
			guid: 0,
			queries: [],
			queue: [],
			running: false,
			timeout: null,

			checkQueue: function() {
				if ( $.livequery.running && $.livequery.queue.length ) {
					var length = $.livequery.queue.length;
					// Run each Live Query currently in the queue
					while ( length-- )
						$.livequery.queries[ $.livequery.queue.shift() ].run();
				}
			},

			pause: function() {
				// Don't run anymore Live Queries until restarted
				$.livequery.running = false;
			},

			play: function() {
				// Restart Live Queries
				$.livequery.running = true;
				// Request a run of the Live Queries
				$.livequery.run();
			},

			registerPlugin: function() {
				$.each( arguments, function(i,n) {
					// Short-circuit if the method doesn't exist
					if (!$.fn[n]) return;

					// Save a reference to the original method
					var old = $.fn[n];

					// Create a new method
					$.fn[n] = function() {
						// Call the original method
						var r = old.apply(this, arguments);

						// Request a run of the Live Queries
						$.livequery.run();

						// Return the original methods result
						return r;
					}
				});
			},

			run: function(id) {
				if (id != undefined) {
					// Put the particular Live Query in the queue if it doesn't already exist
					if ( $.inArray(id, $.livequery.queue) < 0 )
						$.livequery.queue.push( id );
				}
				else
					// Put each Live Query in the queue if it doesn't already exist
					$.each( $.livequery.queries, function(id) {
						if ( $.inArray(id, $.livequery.queue) < 0 )
							$.livequery.queue.push( id );
					});

				// Clear timeout if it already exists
				if ($.livequery.timeout) clearTimeout($.livequery.timeout);
				// Create a timeout to check the queue and actually run the Live Queries
				$.livequery.timeout = setTimeout($.livequery.checkQueue, 20);
			},

			stop: function(id) {
				if (id != undefined)
					// Stop are particular Live Query
					$.livequery.queries[ id ].stop();
				else
					// Stop all Live Queries
					$.each( $.livequery.queries, function(id) {
						$.livequery.queries[ id ].stop();
					});
			}
		});

		// Register core DOM manipulation methods
		$.livequery.registerPlugin('append', 'prepend', 'after', 'before', 'wrap', 'attr', 'removeAttr', 'addClass', 'removeClass', 'toggleClass', 'empty', 'remove');

		// Run Live Queries when the Document is ready
		$(function() { $.livequery.play(); });


		// Save a reference to the original init method
		var init = $.prototype.init;

		// Create a new init method that exposes two new properties: selector and context
		$.prototype.init = function(a,c) {
			// Call the original init and save the result
			var r = init.apply(this, arguments);

			// Copy over properties if they exist already
			if (a && a.selector)
				r.context = a.context, r.selector = a.selector;

			// Set properties
			if ( typeof a == 'string' )
				r.context = c || document, r.selector = a;

			// Return the result
			return r;
		};

		// Give the init function the jQuery prototype for later instantiation (needed after Rev 4091)
		$.prototype.init.prototype = $.prototype;

		})(jQuery);
				$(document).ready(function(){
			var focusCount = 0;
			$("#librarySearchField").livequery("focus", function(){
				if (focusCount == 0){
					$(this).val("");
					$(this).css({"color":"#3d3d3d"});
					focusCount = 1;
				}
			});
			
			$(".deleteItem").live("click", function(){
				var li = $(this).parents("li");
				var value = li.attr("value");
				var filler = '\n';
				filler += '<li class="filler" value="'+value+'">\n';
				filler += '	<div class="itemOverlay"></div>\n';
				filler += '	<div class="boxLeft"></div>\n';
				filler += ' <div class="boxContent">\n';
				filler += '	<img src="http://www.army.mil/images/icon_star_100.png" height = "38px" width = "58px" alt="">\n';
				filler += '	<div class="boxText">\n';
				filler += '		<h5>Filler Content</h5>\n';
						
				filler += '		<h6><span class="author"></span></h6>\n';
				filler += '	</div>\n';
				filler += '	<a class="deleteItem" href=""><span class="hide">Delete Item</span></a>\n';
				filler += ' </div>\n';
				filler += '	<div class="boxRight"></div>\n';
				filler += '</li>\n';
				li.replaceWith(filler);
				runsortable();
				rundroppable();
				return false;
			});
			
			$("#librarySearch #searchIcon").live("click", function(){
				$("#librarySearch").submit();
			});
			
			function updateFeed(id){
				$.ajax({
				   type: "GET",
				   url: "/webpages/load_feed_items/"+id+"/1/1/",
				   success: function(msg){
				     $("#availableItems").empty().append(msg);
				   },
				   complete: function(){
					rundraggable();
					rundroppable();
				   }
				 });
				 $.ajax({
				   type: "GET",
				   url: "/webpages/load_feed_list/"+id+"/",
				   success: function(msg){
				    $("#pickFeedAndSectionSelection").replaceWith(msg);
				   }
				 });
			}
			function updateFeedAndSection(id, s_id, p){
				$.ajax({
				   type: "GET",
				   url: "/webpages/load_feed_items/"+s_id+"/"+id+"/"+p+"/",
				   success: function(msg){
				    $("#availableItems").empty().append(msg);
				   },
				   complete: function(){
					rundraggable();
					rundroppable();
				   }
				});
			}
			
			function updateLibrary(p){
				$.ajax({
				   type: "GET",
				   url: "/webpages/load_feed_library/"+p+"/",
				   success: function(msg){
				    $("#libraryPag").empty().append(msg);
				   },
				   complete: function(){}
				});
			}
			
			// ie doesn't pick up option.click, so use select.change (works with keyboard too)

			$('#pickFeedSectionSelection').livequery("change", function(){
				var id = $(this).children("option:selected").attr("value");
				//alert(id);
				updateFeed(id);
				updateLibrary(1);
			});
			$('#pickFeedAndSectionSelection').livequery("change", function(){
				var s_id = $("#pickFeedSectionSelection").attr("value");
				var id = $(this).children("option:selected").attr("value");
				//alert(s_id + "---" + id);
				updateFeedAndSection(id, s_id, 1);
				updateLibrary(1);
			});
			$('#libraryNext.active').live("click", function(){
				var s_id = $("#pickFeedSectionSelection").attr("value");
				var id = $("#pickFeedAndSectionSelection").children("option:selected").attr("value");
				var p = $(this).attr("value");
				//alert(s_id + "---" + id + "---" + p);
				updateFeedAndSection(id, s_id, p);
				updateLibrary(p);
				return false;
			});
			$('#libraryPrev.active').live("click", function(){
				var s_id = $("#pickFeedSectionSelection").attr("value");
				var id = $("#pickFeedAndSectionSelection").children("option:selected").attr("value");
				var p = $(this).attr("value");
				//alert(s_id + "---" + id);
				updateFeedAndSection(id, s_id, p);
				updateLibrary(p);
				return false;
			});
			
		});
		
