$.fn.pause = function(duration) {
	$(this).stop().animate({ dummy: 1 }, duration);
	return this;
};
/*function mouseleft() {
	$("#footer").triggerHandler("mouseleave");
}*/
$(document).ready(function() {
	
	$('a[href^=#top],a[href^=#Top]').click(function() {
		$('body').scrollTo(0,1000);
		return false;
	});	
	
	
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
			&& location.hostname == this.hostname) {
				var $target = $(this.hash);
				$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
				if ($target.length) {
					var targetOffset = $target.offset().top;
					$('html,body').animate({scrollTop: targetOffset}, 1000);
					return false;
				}
			}
	});
	
						   
$(function(){
	var path = location.pathname.substring(1);
		if ( path )
			$('#navigation a[href$="' + path + '"]').attr('class', 'selected');
});

					
				$(".col").equalHeights();		   
			$('.news-slider li').wrapInner('<div class="image" />');
			//$('#footer h3').wrapInner('<span />');
			$('a.button').wrapInner('<span />');

	$('#user-options ul')
		.prepend('<li><a id="bookmark">Bookmark</a></li>')
		.prepend('<li><a href="#email" id="email" title="Email this page">Email</a></li>')
		.prepend('<li><a href="#print" id="print" title="Print this page">Print</a></li>');
	$('#user-options a#print').click(function() {
		window.print();
		return false;
	});
	$('#user-options a#email').click(function() {
		window.location = "mailto:?subject=" +document.title+ "&body=" +window.location+ "";
		return false;
	});
	$('#user-options a#bookmark').jFav();

	$(".ipf-sectionmenu").each(
		function() {
			var elem = $(this);
			if (elem.children().length == 0) {
				elem.remove();
				$("#navigation script").remove();
				if($.trim($("#navigation").text()) == "") {
  					$("#navigation").html("");
				}
			}
		}
	);
	
	/*if ($.trim($("#navigation").text()) == "" && $.trim($("#sidebar").text()) == "")*/
	if ($("#navigation").is(":empty") && $("#sidebar").is(":empty")) { 
		$("#navigation").remove();
		$("#sidebar").remove();
		$("#content").css("width", "940px").css("padding-left", "10px");
	}
	else if ((!$("#navigation").length > 0) && (!$("#sidebar").length > 0)) {
		$("#content").css("width", "940px").css("padding-left", "10px");
	}
	if ($("#sidebar").is(":empty")) { 
		$("#sidebar").remove();
		$("#content").css("width", "770px");
	}
	else if ((!$("#sidebar").length > 0 && $("#navigation").length > 0)) {
		$("#content").css("width", "770px");
	}
	if ($("#navigation").is(":empty")) { 
		$("#navigation").remove();
		$("#content").css("width", "659px").css("padding-left", "10px").css("margin-left", "45px").css("margin-right", "45px");
	}
	else if ((!$("#navigation").length > 0 && $("#sidebar").length > 0)) {
		$("#content").css("width", "659px").css("padding-left", "10px").css("margin-left", "45px").css("margin-right", "45px");
	}

	var selectedInput = null;

	/*$("#footer .col, #footer").mouseenter(
		function () {
			
			$("#footer .col").stop().pause(60).animate({ height:"20em" }, 400, "easeOutQuart" );
		}).mouseleave(
		function () {
			
			if (selectedInput == null) {
				$("#footer .col").stop().pause(60).animate({ height:"20px" }, 400, "easeOutQuart" );
			}
		}
	);*/
	
	
	/*var object = SHARETHIS.addEntry({title:'Share'},{button:false, offsetLeft: -296});
	$('#user-options ul').append('<li><a href="javascript:void(0);" title="Share this page" id="share">ShareThis</a><li>');
	var element = document.getElementById("share");
	object.attachButton(element);*/
	
	
	

	


	var el = $('#location');
	if (el.html() == null) {
		return false;
	}
	else {
		el.html(el.html().replace(/&gt;/ig, ""));
	}



	$('#design .ipf-sectionmenu #pageid1712 ul').remove();
	$('#design .ipf-sectionmenu #pageid1714 ul').remove();
	$('#design .ipf-sectionmenu #pageid1715 ul').remove();
	$('#design .ipf-sectionmenu #pageid1716 ul').remove();
	$('#design .ipf-sectionmenu #pageid10389 ul').remove();
	$('#design .ipf-sectionmenu #pageid1712').removeClass();
	$('#design .ipf-sectionmenu #pageid1714').removeClass();
	$('#design .ipf-sectionmenu #pageid1715').removeClass();
	$('#design .ipf-sectionmenu #pageid1716').removeClass();
	$('#design .ipf-sectionmenu #pageid10389').removeClass();
	
	
	$('#qs .ipf-sectionmenu #pageid8047 ul').remove();
	$('#qs .ipf-sectionmenu #pageid3069 ul').remove();
	$('#qs .ipf-sectionmenu #pageid3133 ul').remove();
	$('#qs .ipf-sectionmenu #pageid7096 ul').remove();
	$('#qs .ipf-sectionmenu #pageid3062 ul').remove();
	$('#qs .ipf-sectionmenu #pageid8047').removeClass();
	$('#qs .ipf-sectionmenu #pageid3069').removeClass();
	$('#qs .ipf-sectionmenu #pageid3133').removeClass();
	$('#qs .ipf-sectionmenu #pageid7096').removeClass();
	$('#qs .ipf-sectionmenu #pageid3062').removeClass();
	
	$('.ipf-sectionmenu #pageid4721').removeClass();




	var imgWidth = 0;
	$('.image-caption img').each(function() {
		imgWidth += $(this).width();
		$(this).closest('.image-caption').css('width', imgWidth);
	});
	
	

	
	

});

function pwlEntr(myfield,e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13) {
	  searchType();
	  return false;
	}
	else
		return true;
}





function searchType() {
	if(document.pwl.pwlSelect[1].checked == true) {
		search(document.pwl.q.value);
		return false;
	}
	if(document.pwl.pwlSelect[0].checked == true) {
		document.pwl.action='http://search.kwantlen.ca/search';
		document.pwl.method='GET';
		document.pwl.submit();
	}
	if(document.pwl.pwlSelect[2].checked == true) {
		var lib = document.getElementById('lookUp'); 
 		lib.name = 'searchdata1'; 
		document.pwl.action='https://webcat.kwantlen.ca/uhtbin/cgisirsi/0/0/0/5';
		document.pwl.method='POST';
		document.pwl.submit();
	}
}
