
$(function () {
	$('.bubble_info').each(function () {
		// options
		var distance = 0;
		var time = 250;
		var hideDelay = 500;

		var hideDelayTimer = null;

		// tracker
		var beingShown = false;
		var shown = false;

		var trigger = $('.trigger', this);
		var popup = $('.bubble_popup', this).css('opacity', 0);

		// set the mouseover and mouseout on both element
		$([trigger.get(0), popup.get(0)]).mouseover(function () {
			// stops the hide event if we move from the trigger to the popup element
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
		}).mouseout(function () {
			// reset the timer if we get fired again - avoids double animations
			if (hideDelayTimer) clearTimeout(hideDelayTimer);

			// store the timer so that it can be cleared in the mouseover if required
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				popup.animate({
					top: '-=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function () {
					// once the animate is complete, set the tracker variables
					shown = false;
					// hide the popup entirely after the effect (opacity alone doesn't do the job)
					popup.css('display', 'none');
				});
			}, hideDelay);
		}).click(function () {
			// don't trigger the animation again if we're being shown, or already visible
			if (beingShown || shown) {
				return;
			} else {
				beingShown = true;

				// reset position of popup box
				popup.css({
					top: 42,
					display: 'block' // brings the popup back in to view
				})

				// (we're using chaining on the popup) now animate it's opacity and position
				.animate({
					top: '-=' + distance + 'px',
					opacity: 1
				}, time, 'swing', function() {
					// once the animation is complete, set the tracker variables
					beingShown = false;
					shown = true;
				});
			}
		});
	});
});

$(function () {
	var current_image = -1;
	var media_list_timeout;
	
	media_list_auto_rotate()

	$('.media_list li').mouseover(function () {
		if (media_list_timeout) {
			clearTimeout(media_list_timeout);
		}

		media_list_change_image($(".media_list li").index(this));
	});

	$('.media_list li').mouseout(function () {
		media_list_timeout = setTimeout(media_list_auto_rotate, 5000);
	});

	function media_list_auto_rotate() {
		if(current_image >= ($(".media_list li").length - 1)) { 
			current_image = 0; 
		} else { current_image = current_image + 1; }

		media_list_change_image(current_image);
		media_list_timeout = setTimeout(media_list_auto_rotate, 5000);
	}

	function media_list_change_image(image_id) {
		current_image = image_id;

		$('.media_list li').attr("class", "");
		$('.media_list li:eq('+current_image+')').attr("class", "selected");
		$('#main_image').attr("src", $('.media_list li:eq('+current_image+') img').attr("src"));
		$('#related_media_link').attr("href", $('.media_list li:eq('+current_image+') a').attr("href"));

		$('#featured_title').html($('.media_list li:eq('+current_image+') h2').html());
		$('#featured_desc').html($('.media_list li:eq('+current_image+') p').html());

	}
});

var progress_bar_width = 700;

$(function() {
	$(".global_slider_1").each(function() {
		slider_width_value = $(this).css("width");
		group_progress = parseInt($(".progress_amt").eq($(".global_slider_1").index(this)).html());
		slider_width = parseInt(slider_width_value.substr(0,(slider_width_value.length-2)));
		slider_position = Math.round(0 - progress_bar_width + (slider_width * (group_progress/100)));
		$(this).css("background-position", slider_position+"px 0px");
	});
	$(".global_slider_2").each(function() {
		slider_width_value = $(this).css("width");
		group_progress = parseInt($(".progress_amt").eq($(".global_slider_2").index(this)).html());
		slider_width = parseInt(slider_width_value.substr(0,(slider_width_value.length-2)));
		slider_position = Math.round(0 - progress_bar_width + (slider_width * (group_progress/100)));
		$(this).css("background-position", slider_position+"px 0px");
	});
	$(".global_slider_3").each(function() {
		slider_width_value = $(this).css("width");
		group_progress = parseInt($(".progress_amt").eq($(".global_slider_3").index(this)).html());
		slider_width = parseInt(slider_width_value.substr(0,(slider_width_value.length-2)));
		slider_position = Math.round(0 - progress_bar_width + (slider_width * (group_progress/100)));
		$(this).css("background-position", slider_position+"px 0px");
	});
});

$(function() {
	$(".font_smaller").click(function() {
		alert($(".article").css("font-size"));
	});
	$(".font_bigger").click(function() {
		alert("big");
	});
});

$(document).ready(function(){
	$(".changer").click(function(){
		var $mainText = $('.resizeable');
		var currentSize = $mainText.css('font-size');
		var num = parseFloat(currentSize, 10);
		var unit = currentSize.slice(-2);
		if (this.id == 'font_bigger'){
			num = num * 1.25;
		} else if (this.id == 'font_smaller'){
			num = num / 1.25;
		}
		$mainText.css('font-size', num + unit);
		return false;
	});
});

$(function () {
	var widgets_visible = 5;
	var widget_width = 188;
	var margin_width = 2;
	var offset = widget_width + (2 * margin_width);
	
	$(".animate_left").click(function() {
		var pos = $(".tool_widgets .flc img").css("left");
		var position = pos.substr(0,(pos.length-2));
		var new_position = parseInt(position) + offset;
		if (position < 0) {
			$(".tool_widgets .flc img").animate({
				left: new_position
			}, "slow")
		}
		if ($(this).css("display") == 'inline' && new_position == 0) {
			$(this).css("display", "none")
		}
		if ($(".animate_right").css("display") == 'none' && position < 0) {
			$(".animate_right").css("display", "inline")
			$(this).css("marginRight", "0px")
		}
	});
	
	$(".animate_right").click(function() {
		var pos = $(".tool_widgets .flc img").css("left");
		var position = pos.substr(0,(pos.length-2));
		var new_position = parseInt(position) - offset;
		var max_right = 0 - (($(".tool_widgets .flc img").length - widgets_visible) * offset);
		if (position > max_right) {
			$(".tool_widgets .flc img").animate({
				left: new_position
			}, "slow")
		}
		if ($(this).css("display") == 'inline' && new_position == max_right) {
			$(this).css("display", "none")
			$(".animate_left").css("marginRight", "25px")
		}
		if ($(".animate_left").css("display") == 'none' && position > max_right) {
			$(".animate_left").css("display", "inline")
		}
	});
});


$(function () {
	var widgets_visible = 5;
	var widget_width = 115;
	var margin_width = 0;
	var offset = widget_width + (2 * margin_width);
	
	$(".animate_left_v").click(function() {
		var pos = $(".video_window .videos").css("left");
		var position = pos.substr(0,(pos.length-2));
		var new_position = parseInt(position) + offset;
		if (position < 0) {
			$(".video_window .videos").animate({
				left: new_position
			}, "slow")
		}
		if ($(this).css("visibility") == 'visible' && new_position == 0) {
			$(this).css("visibility", "hidden")
		}
		if ($(".animate_right_v").css("display") == 'none' && position < 0) {
			$(".animate_right_v").css("display", "inline")
		}
	});
	
	$(".animate_right_v").click(function() {
		var pos = $(".video_window .videos").css("left");
		var position = pos.substr(0,(pos.length-2));
		var new_position = parseInt(position) - offset;
		var max_right = 0 - (($(".video_window .videos .video").length - widgets_visible) * offset);
		if (position > max_right) {
			$(".video_window .videos").animate({
				left: new_position
			}, "slow")
		}
		if ($(this).css("display") == 'inline' && new_position == max_right) {
			$(this).css("display", "none")
		}
		if ($(".animate_left_v").css("visibility") == 'hidden' && position > max_right) {
			$(".animate_left_v").css("visibility", "visible")
		}
	});
});

$(function() {
	$(".togglemodule").click(function() {
		var module = $(this).attr('id');
		if (module != undefined)
		{
			module = module.split('-');
			$.get("/prof/ajax/modules", { id: module[1] } );
		}
		var body = $(this).parent().parent().parent().parent().children("div:nth-child(2)");
		var state = body.attr('class');
		if (state.indexOf('moduleopen') > -1) {
			$(this).attr('src', '/images/temp/flex_arrow_shut.gif');
			body.attr('class', 'moduleclosed');
		} else {
			$(this).attr('src', '/images/temp/flex_arrow_open.gif');
			body.attr('class', 'moduleopen');
		}
	});
});