/*
 *KU Theme Scripts
 *Author: Jeffrey Uyeno & Brett Stoppel
 */
 
//JS fix for IE5.5
if (document) {
  if (!document.nodeType) document.nodeType = 9;
  if (!document.nodeName) document.nodeName = '#document';
}
 
/**
 *Menu Prettying for JS
 */
$(document).ready(function(){
	//Add notification for selected tier 1 items
	$("#menu-117 > a").addTriangle();
	$("#menu-118 > a").addTriangle();
	$("#menu-119 > a").addTriangle();
	$("#menu-858 > a").addTriangle();
	
	//Frontpage Feed Height Fix
	fixHeight();
	
	$("#nice-menu-1 > .menuparent").hover(
		function(){
			$(this).addClass("over");
		},
		function(){
			$(this).removeClass("over");
		}
	);


	$('.clear-me').focus(function() {
		$(this).val('');
	});
	$('#more-info').submit(function() {
		moreInfo();
		return false;
	});
});

//IE6 Fix from nice_menus.js
if (document.all && !window.opera && (navigator.appVersion.search("MSIE 6.0") != -1) && $.browser.msie) {
  function IEHoverPseudo() {
      //$("ul.nice-menu li.menuparent").hover(function(){
	  $("ul.nice-menu").find("> li.menuparent").hover(function(){												   
          $(this).addClass("over").find("> ul").show().addShim();
        },function(){
          $(this).removeClass("over").find("> ul").removeShim().hide();
        }
      );
      // Add a hover class to all li for CSS styling. Silly naming is done
      // so we don't break CSS compatibility for .over class already in use
      // and due to the fact that IE6 doesn't understand multiple selectors.
      $("ul.nice-menu li").hover(function(){
          $(this).addClass("ie-over");
        },function(){
          $(this).removeClass("ie-over");
        }
      );
    }

    // This is the jquery method of adding a function
    // to the BODY onload event.  (See jquery.com)
    $(document).ready(function(){ IEHoverPseudo() });
}

$.fn.addShim = function() {
  return this.each(function(){
	  if(document.all && $("select").size() > 0) {
	    var ifShim = document.createElement('iframe');
	    ifShim.src = "javascript:false";
			ifShim.style.width=$(this).width()+1+"px";
      ifShim.style.height=$(this).find("> li").size()*23+20+"px";
			ifShim.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
		  ifShim.style.zIndex="0";
    $(this).prepend(ifShim);
      $(this).css("zIndex","99");
		}
	});
};

$.fn.removeShim = function() {
  return this.each(function(){
	  if (document.all) $("iframe", this).remove();
	});
};

function fixHeight() {
	var borderHeight = $(".frontpage-feed-first").height();
	var otherHeight = $(".frontpage-feed").height();
	if( borderHeight < otherHeight ) {
		$(".frontpage-feed-first").height(otherHeight);
	}
}

jQuery.fn.addTriangle = function() {
  this.append("<div class=\"triangle\"><div class=\"triangle-left\"></div><div class=\"triangle-right\"></div></div>");
  return this.each(function(){
  });
}
	


/*
function initMenu() {
	kuMenuTimer = null;
	closeMenuTimer = null;
	$("#nice-menu-1").addClass("js-enabled");
	$("#nice-menu-1 > .menuparent").children('ul').hide();
	$('#nice-menu-1 > .menuparent').hover(
		function(){
			checkThisElement = $(this).children('ul');
			checkSiblingElements = $(this).siblings().children('ul');
			if ( (!checkThisElement.is(':animated')) && (!checkSiblingElements.is(':animated')) ) {
				$(this).children('ul').slideDown(250);
			}
		},
		function(){
			checkThisElement = $(this).children('ul');
			checkSiblingElements = $(this).siblings().children('ul');
			if ( (!checkThisElement.is(':animated')) && (!checkSiblingElements.is(':animated')) ) {
				$(this).children('ul').fadeOut(250);
			}
		}
	);
	
}

function initKUMenu() {
	var menuTimer = null;
	$("#nice-menu-1").addClass("js-enabled");
	$("#nice-menu-1 > .menuparent").children('ul').hide();
	$('#nice-menu-1 > .menuparent').hover(
		function() {
			var checkElement = $(this).children('ul');
			clearTimeout(menuTimer);
			menuTimer = null;
			if(checkElement.is(':visible')) {
				return false;
			}
			if(!checkElement.is(':visible')) {
				$('#nice-menu-1 > .menuparent').children('ul:visible').fadeOut(500);
				checkElement.slideDown(500);
				return false;
			}
		},
		function() {
			var checkElement = $(this).children('ul');
			if ( checkElement.is(':animated') ) {
				menuTimer = setTimeout(function(){
					$('#nice-menu-1 > .menuparent').children('ul').fadeOut(500);
					menuTimer = null;
				},500);	
				return false;	
			}
			if ( !checkElement.is(':animated') ) {
				$(this).children('ul').fadeOut(250);
				return false;
			}
		}
	);
	$('#nice-menu-1').mouseout(function(){
										
	});
}
*/


function moreInfo(e)
{
	if($('#more-info-name').val() != '' && $('#more-info-name').val() != 'Your Name')
	{
		moreInfoError = false;
	} else
	{
		moreInfoError = true;
		$('#more-info-name').val('Error: Your name is required.');
	}
	if($('#more-info-email').val() != '' && $('#more-info-email').val() != 'Your Email')
	{
		moreInfoError = false;
	} else
	{
		moreInfoError = true;
		$('#more-info-email').val('Error: Your email is required.');

	}
	if (moreInfoError)
	{
		return false;
	} else
	{
		dataString = "name=" + $('#more-info-name').val()+"&email=" + $('#more-info-email').val(),
		$.ajax({
			type: "POST",
			url: "/~swm/cgi-bin/mail.php",
			data: dataString,
			success: function(msg) 
			{
				$("#more-info").html(msg);
			},
			error: function(data, sts, msg) 
			{
			}
		});
	}
	return false;
}

