var translatemenudone = findmenudone = 0;

$(document).ready(function() {
	$('div').pngFix( );
	$("a").each(function() {
		if (($(this).attr("rel")=="external")||
			($(this).attr("rel")=="download")||
			($(this).attr("rel")=="socialmedia")) {
			this.target = "_blank";
		} // rel to open in new window
	});
	activatemenu("#findlink","findmenudone", "#quicklinkscontent", "#findlink", "over");
	$('.collapsiblelist li>ul').each(function(i) {
		var parent = $(this).parent('li');
		parent.addClass('closed');
		var children = $(this).remove();
		parent.prepend('<span class="toggle">-</span>').find('span').toggle(
			function() {
				parent.removeClass('closed');
				parent.addClass('open');
				children.show();
			},
			function() {
				parent.removeClass('open');
				parent.addClass('closed');
				children.hide();
			}
		);
		parent.append(children);
	});
	$("a#otherTranslations").click(function() {
		$("div#translationOptions").hide();
		$("div#translationDropdown").show();
	});
	$('.collapsiblelist ul ul').hide();
	$(".striped tr:even").addClass("alt");
    $("#cse-search-box").append('<input type="hidden" name="id" value="728" />');
    $("#cse-search-box").append('<input type="hidden" name="cof" value="FORID:11" />');
	$("#programSearchBoxGo").click(function() {
		window.location.href = "/CourseSearch.aspx?kw="+$("#txtKW").val();
	});
	$("a[rel^='popup']").click(function() {
		var params;
		if ($(this).attr("rel").substring(5,6)=="|") {
			params = $(this).attr("rel").substring(6);
		} else if ($(this).attr("rel").substring(5,6)=="[") {
			params = params = $(this).attr("rel").substring(6,$(this).attr("rel").length-1);
			var x = params.indexOf("x");
			var w = params.substring(0,x);
			var h = params.substring(x+1);
			params = "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+w+",height="+h;
		} // if ($(this).attr("rel").substring(5,6)=="|")
		if (!params||params.length==0) {
			params = "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=647,height=500";
		} // if (!params||params.length==0)
		var loc = $(this).attr("href");
		var file = loc.substring(loc.lastIndexOf("/")+1,loc.indexOf("."));
		window.open(loc, file, params);
		return false;
	});
	$("#twitterfeed").each(function() {
		alert("Hey, here's a Twitter feed.");
	});
	if ($(".randomphoto").size()>0) {
		$(".randomphoto:first").before('<p class="randomphoto-controls"><span class="randomphoto-back">Back</span> <span class="randomphoto-pause">Pause</span> <span class="randomphoto-next">Next</span></p>');
		var timer = setInterval("nextRandomPhoto()",10000);
	} // if ($(".randomphoto").size()>0)
	$(".randomphoto-controls span").click(function() {
		clearTimeout(timer);
		if ($(this).hasClass("randomphoto-back")) {
			prevRandomPhoto();
		} else if ($(this).hasClass("randomphoto-next")) {
			nextRandomPhoto();
		} // if ($(this).hasClass("randomphoto-next"))
	});
});

function activatemenu(id, storedlocation, menu, linkover, classover) {
	var trackerID;
	$(id).mouseover(function() {				 	
		if(eval(storedlocation) == 0) {
			trackerID = window.setTimeout('showMenu("' + storedlocation + '","' + menu + '","' + linkover + '","' + classover + '")',250);
		} else { 
			window.clearTimeout(trackerID); }
	   });
		$(id).mouseout(function() {
			window.clearTimeout(trackerID);
			trackerID = window.setTimeout('clearMenu("' + storedlocation + '","' + menu + '","' + linkover + '","' + classover + '")',250);
	   }); 
		$(menu).mouseover(function() {
			window.clearTimeout(trackerID);
			$(menu).show("");
			$(linkover).addClass(classover);
	   }); 
		$(menu).mouseout(function() {
			window.clearTimeout(trackerID);
			trackerID = window.setTimeout('clearMenu("' + storedlocation + '","' + menu + '","' + linkover + '","' + classover + '")',250);
	   });	
}

function showMenu(storedlocation, menu, linkover, classover) {
		eval(storedlocation+"=1;");
    	$(menu).slideDown("fast"); 
		$(linkover).addClass(classover);
}
 function clearMenu(storedlocation, menu, linkover, classover) {
		eval(storedlocation+"=0;");
		$(menu).stop();
		$(menu).hide("");
		$(linkover).removeClass(classover);
}

function translatePage(lang) {
	window.location='http://www.google.com/translate_c?hl=en&langpair=en%7C'+lang+'&u='+window.location.href;
}

function nextRandomPhoto() {
	var curr = $(".randomphoto:visible");
	var next = $(curr).next(".randomphoto");
	if ($(next).size()==0) {
		next = $(curr).siblings(".randomphoto:first");
	} // if ($(next).size()==0)
	$(curr).fadeOut("fast", function() {
		$(next).fadeIn("fast");
	});
}

function prevRandomPhoto() {
	var curr = $(".randomphoto:visible");
	var prev = $(curr).prev(".randomphoto");
	if ($(prev).size()==0) {
		prev = $(curr).siblings(".randomphoto:last");
	} // if ($(next).size()==0)
	$(curr).fadeOut("fast", function() {
		$(prev).fadeIn("fast");
	});
}

function autoLink(text) {
	return text.replace(/(http:\/\/[\w\.\/]+)/, "<a href=\"$1\" target=\"blank\">$1</a>");
} // function autoLink(text)


/*
Wrote by jose.nobile@gmail.com
Free to use for any purpose
Tested at IE 7, IE 8, FF 3.5.5, Chrome 3, Safari 4, Opera 10
Tested with Object[classid and codebase] < embed >, object[classid and codebase], embed, object < embed > -> Vimeo/Youtube Videos
Please, reporte me any error / issue
*/
window.noConflict = false;
window.setTimeout('window.fix_wmode2transparent_swf()', 200);
window.fix_wmode2transparent_swf = function  () {
	if(typeof (jQuery) == "undefined") {
		window.setTimeout('window.fix_wmode2transparent_swf()', 200);
		return;
	}
	if(window.noConflict)jQuery.noConflict();
	// For embed
	jQuery("embed").each(function(i) {
		var elClone = this.cloneNode(true);
		elClone.setAttribute("WMode", "Transparent");
		jQuery(this).before(elClone);
		jQuery(this).remove();
	});	
	// For object and/or embed into objects
	jQuery("object").each(function (i, v) {
	var elEmbed = jQuery(this).children("embed");
	if(typeof (elEmbed.get(0)) != "undefined") {
		if(typeof (elEmbed.get(0).outerHTML) != "undefined") {
			elEmbed.attr("wmode", "transparent");
			jQuery(this.outerHTML).insertAfter(this);
			jQuery(this).remove();
		}
		return true;
	}
	var algo = this.attributes;
	var str_tag = '<OBJECT ';
	for (var i=0; i < algo.length; i++) str_tag += algo[i].name + '="' + algo[i].value + '" ';	
	str_tag += '>';
	var flag = false;
	jQuery(this).children().each(function (elem) {
		if(this.nodeName == "PARAM") {
			if (this.name == "wmode") {
				flag=true;
				str_tag += '<PARAM NAME="' + this.name + '" VALUE="transparent">';		
			}
			else  str_tag += '<PARAM NAME="' + this.name + '" VALUE="' + this.value + '">';
		}
	});
	if(!flag)
		str_tag += '<PARAM NAME="wmode" VALUE="transparent">';		
	str_tag += '</OBJECT>';
	jQuery(str_tag).insertAfter(this);
	jQuery(this).remove();	
	});
}


OAS_url = 'http://ads.digitalhealthcare.com/RealMedia/ads/';
OAS_sitepage = window.location.hostname + window.location.pathname;
if(OAS_sitepage.substring(0,7) == "http://") {
	OAS_sitepage = OAS_sitepage.substring(7);
}
if((OAS_sitepage.substring(0,8) == "www-iis-")||(OAS_sitepage.substring(0,10) == "d-www-iis-")) {
	OAS_sitepage = "onsmaster.ons.org"+window.location.pathname;
} else if(OAS_sitepage.substring(0,4) != "www.") {
	OAS_sitepage = "www." + OAS_sitepage;
}
if (OAS_sitepage.substring(0,18) == "www.onsconnect.org") {
	OAS_listpos = 'Top_combo,Right_combo,Bottom_combo';
} else {
	OAS_listpos = 'Right_combo,Bottom_combo';
}
OAS_query = '';
OAS_target = '_top';
OAS_version = 10;
OAS_rn = '001234567890'; OAS_rns = '1234567890';
OAS_rn = new String (Math.random()); OAS_rns = OAS_rn.substring (2, 11);
function OAS_NORMAL(pos) {
	document.write('<A HREF="' + OAS_url + 'click_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" TARGET=' + OAS_target + '>');
	document.write('<IMG SRC="' + OAS_url + 'adstream_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" BORDER=0></A>');
}
OAS_version = 11;
if ((navigator.userAgent.indexOf('Mozilla/3') != -1) || (navigator.userAgent.indexOf('Mozilla/4.0 WebTV') != -1))
	OAS_version = 10;
if (OAS_version >= 11)
	document.write('<SCR' + 'IPT LANGUAGE=JavaScript1.1 SRC="' + OAS_url + 'adstream_mjx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '?' + OAS_query + '"><\/SCRIPT>');
document.write('');
function OAS_AD(pos) {
	if (OAS_version >= 11)
		OAS_RICH(pos);
	else
		OAS_NORMAL(pos);
}
