
$(document).ready(function() {
//	-------------------------------------------------------
//	Links any images in an operational item thumbnail CQWP.
//	-------------------------------------------------------
//	if($(".operational .thumbnail img")) {
//		var newsrc = window.location.protocol + "//" + window.location.host + $(".operational .thumbnail img").attr("src");
//		$(".operational .thumbnail img").wrap("<a href=\"/usmc/Pages/meta.aspx?image=" + newsrc + "\"></a>");
//	}


//	-----------------------------------------------
//	global nav - line next to Home - this loses it.
//	-----------------------------------------------
//	$('table.ms-topnav a').get(0).style.border = "0";

//	--------------------------------------------------------
//	Sidebar nav - this turns on the section if you're in it.
//	--------------------------------------------------------
//	var path = location.pathname.substring();
//	var x = $('a.ms-navitem[@href$="' + path + '"]');
//	var y = $('a.ms-navheader[@href$="' + path + '"]');
//	var z = x.size() + y.size();
//	if (z > 0) {
//		$('table.ms-selectednavheader').removeClass('ms-selectednavheader');
//	}
//	$('a.ms-navheader[@href$="' + path + '"]').parent().parent().parent().parent('table.ms-navheader').addClass("selectednav")
//	$('a.ms-navitem[@href$="' + path + '"]').parent().parent().parent().parent('table.ms-navitem').addClass("selectednav")

//	-------------------------------------------------------
//	Removes the duplicate agencies or units from breadcrumb
//	-------------------------------------------------------
	var u = 0;
	$("div.breadcrumb a").each(function(i) {
		if ($(this).text() == "Units" && u == 1) {
			$(this).parent().next().remove();
			$(this).parent().remove();
		} else if ($(this).text() == "Agencies") { 
			$(this).parent().next().remove();
			$(this).parent().remove();
		} else if ($(this).text() == "Units") { 
			u = 1; 
		}
	});
	
//	----------------------------------------------
//	Checking for Preview Images on Metadata sheets
//	----------------------------------------------
	var imgThumb = '';
	// This if is for View Form
	if ($("td#SPFieldFile a").attr("href")) {
		imgThumb = $("td#SPFieldFile a").attr("href");
		$("img#webImgShrinked").attr({ src: "/_layouts/getthumbnail.aspx?ImageUrl=" + imgThumb }); 
	}

	// This form for Edit form.
	if ($("img#webImgShrinked").parent().parent().parent().parent().prev().find("td.ms-formbody input.ms-input").val()) {
		imgThumb = $("img#webImgShrinked").parent().parent().parent().parent().prev().find("input.ms-input").val();
		var currenturl = window.location + '';	
		var suburl = currenturl.lastIndexOf('/Forms/EditForm.aspx');
		var imgurl = currenturl.substring(0, suburl+1);
		imgThumb = imgurl + imgThumb + '.jpg';
		$("img#webImgShrinked").attr({ src: "/_layouts/getthumbnail.aspx?ImageUrl=" + imgThumb }); 
	}
		
	// This is for all CQWP images	
	$("span.thumbnail img").each(function(i) {
		var origImg = $(this).attr("src");
		var thumbUrl = origImg .indexOf('/_layouts/getthumbnail.aspx?ImageUrl=');
		if(thumbUrl == -1) {
			$(this).attr({ src: "/_layouts/getthumbnail.aspx?ImageUrl=" + origImg });
		}
	});
});

