// If jQuery didn't load from the CDN use the local file
!window.jQuery && document.write(unescape('%3Cscript src="/js/jquery-1.6.4.min.js"%3E%3C/script%3E'));

// bookmark site
function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
} // onclick="bookmarksite(document.title,document.location);return false;"

// toggle open close button
function toggle_visibility(id) {
   var e = document.getElementById(id);
   if(e.style.display == 'none')
	  e.style.display = 'block';
   else
	  e.style.display = 'none';
}

// addthis customizer
var addthis_config = {ui_cobrand:"", ui_use_addressbook:"true", data_track_clickback:"true", ui_508_compliant:"true"}

// jquery
$(document).ready(function(){
	// color every other row
	$('.grid tr:odd').addClass('odd');
	// save onstate
	loc = location.href.substring(7);
	loc = loc.substring(loc.indexOf("/"));
	var i = loc.indexOf("#");
	if (i > -1) loc = loc.substring(0, i);
	var i = loc.indexOf("?");
	if (i > -1) loc = loc.substring(0, i);
    if (loc == '/' && !($("#nav a[href='" + loc + "']").length)) loc = "/index.php";
	$("#topnav a[href='" + loc + "']").addClass('on');
	// preload images
	$.fn.preload = function() {
		this.each(function(){
			$('<img/>')[0].src = this;
		});
	}
	$(['']).preload();
	// entire block clickable
	$(".pane-list li").click(function() {
    	window.location=$(this).find("a").attr("href");return false;
	});
	// hover color transition
	$(".first a").hover(function() {
		$(this).animate({ backgroundColor:"#00aadd"}, 600);
	},function() {
		$(this).animate({ backgroundColor:"#303030"}, 400);
	});
	// placeholder
	if(!$.support.placeholder) {
	  var active; 
	  try { 
	  	active = document.activeElement; 
	  } catch(e) { 
	  	active = $('body');
	  }
      $("input:text").add("textarea").focus(function () {
         if ($(this).attr('placeholder') != '' && $(this).attr('placeholder') != undefined && $(this).val() == $(this).attr('placeholder')) {
            $(this).val('').removeClass('hasPlaceholder');
         }
      }).blur(function () {
         if ($(this).attr('placeholder') != '' && $(this).attr('placeholder') != undefined && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
            $(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
         }
      });
      $("input:text").add("textarea").blur();
      $(active).focus();
      $("form:eq(0)").submit(function() {
         $(":text.hasPlaceholder").add("textarea.hasPlaceholder").val('');
      });
	}
});

function resizeImages(image_id, max_size) {
	$(image_id).each(function(i) {
		if ($(this).height() < max_size && $(this).width() < max_size)
		  	return;

		if ($(this).height() > $(this).width()) {
		    var h = max_size;
		    var w = Math.ceil($(this).width() / $(this).height() * max_size);
		} else {
		    var w = max_size;
		    var h = Math.ceil($(this).height() / $(this).width() * max_size);
		}
		$(this).css({ height: h, width: w });
	});
}

// dropmenu
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function dropmenu_open()
{  dropmenu_canceltimer();
dropmenu_close();
ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function dropmenu_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function dropmenu_timer()
{  closetimer = window.setTimeout(dropmenu_close, timeout);}

function dropmenu_canceltimer()
{  if(closetimer)
{  window.clearTimeout(closetimer);
closetimer = null;}}

$(document).ready(function()
{  $('#dropmenu > li').bind('mouseover', dropmenu_open)
$('#dropmenu > li').bind('mouseout',  dropmenu_timer)});

document.onclick = dropmenu_close;
