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();
	});
	$("#twitterfeed").each(function() {
		var feed = $(this);
		var handle = $(this).attr("class");
		$(this).empty();
		$.getJSON("http://twitter.com/statuses/user_timeline.json?screen_name="+handle+"&count=5&callback=?", function(data) {
			$.each(data, function(i,item) {
				text = item.text;
				text = text.replace(/http:\/\/\S+/g,  '<a href="$&" target="_blank">$&</a>');
				time = item.created_at;
				url = "http://twitter.com/"+handle+"/status/"+item.id_str;
				feed.append('<li>'+text+'<a href="'+url+'" title="'+machineTime(time)+'" class="time" rel="external">'+americanTime(time)+'</a></li>');
			});
			$("#twitterfeed a.time").prettyDate();
		});
	});
	if ($("div.cprblank").size()>0) {		
		if ((agentIs("ipod")||agentIs("ipad")||agentIs("iphone")||agentIs("android"))) {
			$("div.cprblank").addClass("cprmobile");
			$("div.cprblank").removeClass("cprblank");
		} else {
			$("div.cprblank").addClass("cpr");
			$("div.cprblank").removeClass("cprblank");
			$("div#cprblank").attr("id", "cprdropdownlist");
			$("div.cpr").append('<a id="cprdrop" class="cprselect" href="#">Select:</a>');
			$("div#cprdropdownlist").after('<div id="cprdropdownbot"></div>');
			$('#cprcontent').hide();
			activatemenu("#cprdrop","findmenudone", "#cprcontent", "#cprdrop", "over");
		} // if ((agentIs("ipod")||agentIs("ipad")||agentIs("android")))
	}
	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 agentIs(device) {
	// This function returns TRUE if the agent reports itself as the
	// specified device, otherwise FALSE
	var r = false;
	var agent = navigator.userAgent.toLowerCase();
	if (agent.search(device) > -1) { r = true; }
	return r;
} // function agentIs(device)

function pad(number,length) {
	var str = '' + number;
	while (str.length < length) {
		str = '0'+str;
	} // while (str.length < length)
	return str;
} // function pad(number,length)

function machineTime(time) {
	// Takes a date string of the form
	// Mon May 23 18:33:11 +0000 2011
	// and returns it in the form of
	// 2011-05-23T18:33:11Z
	var time = time.split(" ");
	// time[0] = 'Mon'
	// time[1] = 'May'
	// time[2] = '23'
	// time[3] = '18:33:11'
	// time[4] = '+0000'
	// time[5] = '2011'
	var str = time[5];
	switch (time[1]) {
		case 'Jan': str = str+'-01-'; break;
		case 'Feb': str = str+'-02-'; break;
		case 'Mar': str = str+'-03-'; break;
		case 'Apr': str = str+'-04-'; break;
		case 'May': str = str+'-05-'; break;
		case 'Jun': str = str+'-06-'; break;
		case 'Jul': str = str+'-07-'; break;
		case 'Aug': str = str+'-08-'; break;
		case 'Sep': str = str+'-09-'; break;
		case 'Oct': str = str+'-10-'; break;
		case 'Nov': str = str+'-11-'; break;
		case 'Dec': str = str+'-12-'; break;
	} // switch (time[1])
	return str + pad(time[2],2) + 'T' + time[3]+'Z';
} // function machineTime(time)

function americanTime(time) {
	// Takes a date string of the form
	// Mon May 23 18:33:11 +0000 2011
	// and returns it in the form of
	// May 23, 2011
	var time = time.split(" ");
	// time[0] = 'Mon'
	// time[1] = 'May'
	// time[2] = '23'
	// time[3] = '18:33:11'
	// time[4] = '+0000'
	// time[5] = '2011'
	switch (time[1]) {
		case 'Jan': str = 'January '; break;
		case 'Feb': str = 'February '; break;
		case 'Mar': str = 'March '; break;
		case 'Apr': str = 'April '; break;
		case 'May': str = 'May '; break;
		case 'Jun': str = 'June '; break;
		case 'Jul': str = 'July '; break;
		case 'Aug': str = 'August '; break;
		case 'Sep': str = 'September '; break;
		case 'Oct': str = 'October '; break;
		case 'Nov': str = 'November '; break;
		case 'Dec': str = 'December '; break;
	} // switch (time[1])
	if (time[2].substring(0,1)=="0") {
		str = str + time[2].substring(1);
	} else {
		str = str + time[2];
	} // if (time[2].substring(0,1)=="0")
	return str + ', ' + time[5];
} // function americanTime(time)

function internationalTime(time) {
	// Takes a date string of the form
	// Mon May 23 18:33:11 +0000 2011
	// and returns it in the form of
	// 23 May 2011
	var time = time.split(" ");
	// time[0] = 'Mon'
	// time[1] = 'May'
	// time[2] = '23'
	// time[3] = '18:33:11'
	// time[4] = '+0000'
	// time[5] = '2011'
	var str = '';
	if (time[2].substring(0,1)=="0") {
		str = time[2].substring(1);
	} else {
		str = time[2];
	} // if (time[2].substring(0,1)=="0")
	switch (time[1]) {
		case 'Jan': str = str+' January '; break;
		case 'Feb': str = str+' February '; break;
		case 'Mar': str = str+' March '; break;
		case 'Apr': str = str+' April '; break;
		case 'May': str = str+' May '; break;
		case 'Jun': str = str+' June '; break;
		case 'Jul': str = str+' July '; break;
		case 'Aug': str = str+' August '; break;
		case 'Sep': str = str+' September '; break;
		case 'Oct': str = str+' October '; break;
		case 'Nov': str = str+' November '; break;
		case 'Dec': str = str+' December '; break;
	} // switch (time[1])
	return str + time[5];
} // function internationalTime(time)

/* ----------------------------------------
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();	
	});
}
