﻿// JavaScript Document

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function unblur() {
	this.blur();
}

function getLinksToBlur() {
	if (!document.getElementById) return
	links = document.getElementsByTagName("a");
	for(i=0; i<links.length; i++) {
		links[i].onfocus = unblur
	}
}




// ========== Jquery ==========

$(document).ready(function() {
	
	
	
	// ---------- View / Hide Summary ----------
	
	var hide_summary = "Hide Summary";
	var show_summary = "Show Summary";
	if ($("#container.es-ES").length > 0)
	{
		hide_summary = "Ocultar resumen";
		show_summary = "Mostrar resumen";
	}
	
	$("a.hidesummary,a.viewsummary").each(function() {
		var item = $(this);
		//item.parent().parent().parent().children("div.content").css('height', item.parent().parent().parent().children("div.content").height());
		item.parent().parent().parent().children("div.content").css('display', 'none');
		if (item.parent().parent().parent().children("div.content").css('display') == "block")
		{
			item.text(hide_summary);
			item.addClass("hidesummary");
			item.removeClass("viewsummary");
		}
		else
		{
			item.text(show_summary);
			item.removeClass("hidesummary");
			item.addClass("viewsummary");
		}
	});
	
	$("a.hidesummary,a.viewsummary").click(function(e) {
		var item = $(this);
		$(this).parent().parent().parent().children("div.content").toggle('fast', function() {		
			if (item.parent().parent().parent().children("div.content").css('display') == "block")
			{
				item.text(hide_summary);
				item.addClass("hidesummary");
				item.removeClass("viewsummary");
			}
			else
			{
				item.text(show_summary);
				item.removeClass("hidesummary");
				item.addClass("viewsummary");
			}
		});
		e.preventDefault();
	});
	

	
	// ---------- Search Fields ----------
	
	if ($("#container.es-ES").length > 0)
	{
		if ($("input#query").val() == "Search")
		{
			$("input#query").val("Buscar");
		}
		$("input#query").focus(function() {
			 if ($(this).val() == "Buscar")
			 {
				 $(this).val("");
			 }
		});
		$("input#query").blur(function() {
			 if ($(this).val() == "")
			 {
				 $(this).val("Buscar");
			 }
		});
		$("#ctl01_submitquery").attr('src', '/file.axd?pointerid=aeb88a7137e64ffb91b372a58a72bba4');
	}
	else
	{
		$("input#query").focus(function() {
			 if ($(this).val() == "Search")
			 {
				 $(this).val("");
			 }
		});
		$("input#query").blur(function() {
			 if ($(this).val() == "")
			 {
				 $(this).val("Search");
			 }
		});
    }
	

	
	// ---------- Resource Search Fields ----------
	
	if ($("#container.es-ES").length > 0)
	{
		if ($("input#resourcequery").val() == "Search")
		{
			$("input#resourcequery").val("Buscar");
		}
		$("input#resourcequery").focus(function() {
			 if ($(this).val() == "Buscar")
			 {
				 $(this).val("");
			 }
		});
		$("input#resourcequery").blur(function() {
			 if ($(this).val() == "")
			 {
				 $(this).val("Buscar");
			 }
		});
		$("#ctl04_submitquery").attr('src', '/file.axd?pointerid=aeb88a7137e64ffb91b372a58a72bba4');
	}
	else
	{
		$("input#resourcequery").focus(function() {
			 if ($(this).val() == "Search")
			 {
				 $(this).val("");
			 }
		});
		$("input#resourcequery").blur(function() {
			 if ($(this).val() == "")
			 {
				 $(this).val("Search");
			 }
		});
    }
	
	
	
	// ---------- Filter Resources ----------
	
	if ($("div.sidebar-resourcefilters span.whatisthis").length > 0)
	{
	
		var what_is_this = "What is this?";
		var hide_info = "Hide info";
		if ($("#container.es-ES").length > 0)
		{
			what_is_this = "Qué es esto?";
			hide_info = "Ocultar";
		}
		
		$("div.sidebar-resourcefilters p.whatisthistarget").css('height', $("div.sidebar-resourcefilters p.whatisthistarget").height());
		$("div.sidebar-resourcefilters span.whatisthis a").live("click", function(e) {
			if ($(this).text() == what_is_this)
			{
				$(this).text(hide_info);
			}
			else
			{
				$(this).text(what_is_this);
			}
			$("div.sidebar-resourcefilters p.whatisthistarget").toggle('fast');
			e.preventDefault();
		});
		
		$("div.sidebar-resourcefilters span.whatisthis").html("<a href=\"#\">" + what_is_this + "</a>");
		$("div.sidebar-resourcefilters p.whatisthistarget").hide();
		
	}
	
	
	
	// ---------- Print Page ----------
	
	if (window.print)
	{
		if ($("#container.es-ES").length > 0)
		{
			$("div.pagebuttons li:first").after("<li><a href=\"javascript:window.print();\" class=\"printPage\">imprimir página</a></li>");
		}
		else
		{
			$("div.pagebuttons li:first").after("<li><a href=\"javascript:window.print();\" class=\"printPage\">print page</a></li>");
		}
		$("a.printPage").live("click", function(e) {
			window.print();
			e.preventDefault();
		});
	}
	
	
	
	// ---------- Email a Link ----------
	
	$("a.emailLink").click(function(e) {
		var mailtolink = "mailto:?subject=Visit%20the%20Davies%20Arnold%20Cooper%20web%20site&body=%0A%0AVisit%20the%20Davies%20Arnold%20Cooper%20web%20site%3A%0A" + encodeURI(document.location);
		$(this).attr('href', mailtolink);
	});



	// ---------- Scrolling ----------
	
	// Autoscroll if hash
	var target = location.hash && jQuery(location.hash)[0];
	if (target && location.hash != "#Top")
	{
		jQuery.scrollTo(0, { speed:500, margin:true });
		jQuery.scrollTo(target, { speed:500, margin:true });
	}
	
	// localScroll
	jQuery().localScroll({duration:500, hash:true, margin:true});
	jQuery('a.backToTop').unbind("click");
	jQuery('a.backToTop').click(
		function()
		{
			jQuery.scrollTo(0, { speed:500, margin:true });
			return false;
		}
	);
	
	
	
	// ---------- Lightbox ----------
	
	jQuery(function() {
		jQuery('table.gallery-table a').lightBox({
			fixedNavigation:true,
			overlayBgColor:'#FFF',
			imageLoading:'/file.axd?pointerid=2105c98054084e40b10ffec65ca2cef0',
			imageBtnClose:'/file.axd?pointerid=0b5b1439c7fc4cf3b6f14c6565871987',
			imageBtnPrev:'/file.axd?pointerid=30650d2a059b4d62850c5ba2c464d3cc',
			imageBtnNext:'/file.axd?pointerid=33703ac0b4f240a99559811eca80dcf1',
			imageBlank:'/file.axd?pointerid=845098785c854a21bac74acf5d7e5b99'
		});
	});
	
	
	
});




