﻿/* news main EDU */

$(function() {
	$("#FeatureImageThumbs img").mouseover(function() {
		$(this).css("border-color", "#ff0000");
	});

	$("#FeatureImageThumbs img").mouseout(function() {
		$(this).css("border-color", "#80A1B6");
	});

	if (!$("body").is(".edit-mode")) {
		/* our faculty, our expert */
		var randomnumber = Math.floor(Math.random() * $("#our_faculty > a").length);
		$("#our_faculty > a:eq(" + randomnumber + "), #our_faculty > div.SideContent:eq(" + randomnumber + ")").show();
		$("#our_faculty .SideContent_container").append($("#our_faculty div.SideContent:visible"));

		randomnumber = Math.floor(Math.random() * $("#our_expert > a").length);
		$("#our_expert > a:eq(" + randomnumber + "), #our_expert > div.SideContent:eq(" + randomnumber + ")").show();
		$("#our_expert .SideContent_container").append($("#our_expert div.SideContent:visible"));

		// set up scrolling div
		// set up scrolling div
		$("div.SideContent_wrapper .SideContent").jScrollPane({ scrollbarWidth: 0, scrollbarMargin: 0, animateInterval: 40, maintainPosition: false });
		// scroll with up arrow
		scrollDiv("#our_faculty .ScrollControls img:eq(0)", "#our_faculty div.SideContent_wrapper .SideContent", -10);
		// scroll with down arrow
		scrollDiv("#our_faculty .ScrollControls img:eq(1)", "#our_faculty div.SideContent_wrapper .SideContent", 10);
		scrollDiv("#our_expert .ScrollControls img:eq(0)", "#our_expert div.SideContent_wrapper .SideContent", -10);
		scrollDiv("#our_expert .ScrollControls img:eq(1)", "#our_expert div.SideContent_wrapper .SideContent", 10);
		
		
		

		$("#our_faculty, #our_expert, div.meltwaternewswrapper, #media_contacts, #fast_facts").shadow();

		/* fast facts */
		$("#fast_facts div.SideContent").hide();
		randomnumber = Math.floor(Math.random() * $("#fast_facts div.SideContent").length);
		$("#fast_facts div.SideContent:eq(" + randomnumber + ")").show();
		$("#fast_facts > a").appendTo($("#fast_facts div.SideContent:visible"));

		/* media contacts */
		$("#media_contacts h3.staff").click(function() {
			$(this).addClass("selected").siblings().removeClass("selected");
			$("#media_contacts #ExpertSearch").hide();
			$("#media_contacts div.SideContent").show();
		});
		$("#media_contacts h3.expert").click(function() {
			$(this).addClass("selected").siblings().removeClass("selected");
			$("#media_contacts div.SideContent").hide();
			$("#media_contacts #ExpertSearch").show();
		});
	}
});

function scrollDiv(trigger, div, verticalpixels) {
	var t;
	$(trigger).unbind();
	if ($(div).siblings(".jScrollPaneTrack").length > 0) {
        $(trigger).mousedown(function() {  
                t = setInterval(function() {  
                        $(div)[0].scrollBy(verticalpixels);  
                }, 100);  
        }).mouseup(function() {  
                clearInterval(t);  
        }).hover(function () {  
                $(this).addClass("hover");  
        }, function () {  
                $(this).removeClass("hover");  
        });  
        /*  
		$(trigger).mouseover(function() {
			t = setInterval(function() {
				$(div)[0].scrollBy(verticalpixels);
			}, 100);
			$(trigger).addClass("hover");
		}).mouseout(function() {
			clearInterval(t);
			$(trigger).removeClass("hover");
		});
		*/
	}
}