/**
 * Open/Close Popups
 *
 */
 
$(document).ready(function() {
		
	$(".popup-link").click(function(){
		var popupBlock = $($(this).attr("href"))
		
		if(popupBlock.is(':hidden')){		
			popupBlock.fadeIn('fast');
		}
		else {
			popupBlock.fadeOut('fast');			
		}
			
		return false;
	});
	
	
	$(".close-wf").click(function(){
		$(this).parents(".wf-div").fadeOut('fast');
					
		return false;
	});

});


/**
 * Open/Close Warm Fuzzies
 *
 */
 
 $(document).ready(function() {
		
	$(".send-wf").click(function(){
		var popupBlock = $($(this).attr("href"));
		
		if(popupBlock.is(':hidden')){		
			popupBlock.fadeIn('fast');
		}
		else {
			popupBlock.fadeOut('fast');			
		}
			
		return false;
	});
	
	
	$(".close-popup").click(function(){
		$(this).parents(".popup").fadeOut('fast');
					
		return false;
	});

});



/**
 * Open/Close Share
 *
 */
 
$(window).load(function () {
	
	// Create share divs
	$(".share-div").prepend('<div class="share-top"></div><div class="share-arrow"></div>');
	$(".share-div").append('<div class="share-bottom"></div>');
	$(".share-div").hide(); 
	
	$(".share-link").each(function(){
		
		// calculate positions
		topPos = ($(this).offset().top);
		leftPos = ($(this).offset().left);
		
		// move to the end of the document
		$('body').append($($(this).attr("href")));
		
		// position again
		$('body').css('position', 'relative');
		$($(this).attr("href")).css('position', 'absolute');
		$($(this).attr("href")).css('left', leftPos + $(this).width() + 10);
		$($(this).attr("href")).css('top', topPos - $(this).height() - 34);	
	});
	
	
	$(".share-link").click(function(){
		var popupBlock = $($(this).attr("href"))
		
		if(popupBlock.is(':hidden')){		
			popupBlock.fadeIn('fast');
			
			var topPos = popupBlock.offset().top;
			var divHeight = popupBlock.height();
			
			if($('body').height() < topPos + divHeight){
				var bodyOffset = (topPos + divHeight) - $('body').height();
				popupBlock.css('top', topPos - bodyOffset - 9);
				popupBlock.children(".share-arrow").css('top', bodyOffset + 59);
			}

		}
		else {
			popupBlock.fadeOut('fast');
		}
			
		return false;
	});
	
	
	$(".close-share").click(function(){
		$(this).parents(".share-div").fadeOut('fast');
					
		return false;
	});

});



/**
 * Open/Close Email
 *
 */
 
$(document).ready(function() {
 
 	$(".email-share").hide();
 	
 	$(".email-link").click(function(){
		var emailBlock = $($(this).attr("href"));
		
		if(emailBlock.is(':hidden')){		
			$(this).parents(".share-div").children(".suffice").hide();
			emailBlock.show();
		
			var topPos = $(this).parents(".share-div").offset().top;
			var divHeight = $(this).parents(".share-div").height();
			
			if($('body').height() < topPos + divHeight){
				var bodyOffset = (topPos + divHeight) - $('body').height();
				$(this).parents(".share-div").css('top', topPos - bodyOffset - 9);
				$(this).parents(".share-div").children(".share-arrow").css('top', bodyOffset + 59);
			}
			
		}
			
		return false;
	});
	
	
	$(".email-share .more").click(function(){
		$(this).parents(".email-share").hide();
		$(this).parents(".share-div").children(".suffice").show();
		
		return false;
	});


});


/**
 * Get Elements by Class Name
 *
 */
function getElementsByClassName(className,oParent) {
  var doc = (oParent||document);
  var matches = [];
  var nodes = doc.all||doc.getElementsByTagName('*');
  for (var i=0; i<nodes.length; i++) {
    if (nodes[i].className == className || nodes[i].className.indexOf(className)+1 || nodes[i].className.indexOf(className+' ')+1 || nodes[i].className.indexOf(' '+className)+1) {
      matches[matches.length] = nodes[i];
    }
  }
  return matches; 
}


/**
 * Grey Initial Values
 *
 */
 
$(document).ready(function() {
 
	var filled = getElementsByClassName("filled");
	
	if(filled.length > 0){
		for(var i = 0; i < filled.length; i++){
			filled[i].className = "empty";
			filled[i].initialValue = filled[i].value;
			
			filled[i].onclick = filled[i].onfocus = function(){
				this.className = "filled";
				if(this.value == this.initialValue){
					this.value= "";
				}
			}
			
			filled[i].onblur = function(){
				if(this.value == this.initialValue || this.value == ""){
					this.className = "empty";
					this.value = this.initialValue;
				}else{
					this.className = "filled";
				}
			}
		}
	}else{ 
		return; 
	}


});


/**
 * Input hover
 *
 */
 
$(document).ready(function() {
	$(".submit-button").hover(function() {
		$(this).attr("src","/i/screen/widgets/submit-hover.gif");
			}, function() {
		$(this).attr("src","/i/screen/widgets/submit.gif");
	});

	$("input.update").hover(function() {
		$(this).attr("src","/i/screen/widgets/update-hover.gif");
			}, function() {
		$(this).attr("src","/i/screen/widgets/update.gif");
	});
	
	$("td.checkbox input").click(function(){
		$('input.advance-student').removeAttr("disabled").attr("src","/i/screen/widgets/advance-student.gif");
		$('input.decline-student').removeAttr("disabled").attr("src","/i/screen/widgets/decline-student.gif");
		$('input.export-selected').removeAttr("disabled").attr("src","/i/screen/widgets/export-selected-to-file.gif"); 
	});
	
	
	$("input.advance-student").hover(function() {
		$(this).attr("src","/i/screen/widgets/advance-student-hover.gif");
			}, function() {
		$(this).attr("src","/i/screen/widgets/advance-student.gif");
	});
	
	$("input.decline-student").hover(function() {
		$(this).attr("src","/i/screen/widgets/decline-student-hover.gif");
			}, function() {
		$(this).attr("src","/i/screen/widgets/decline-student.gif");
	});
	
	$("input.export-selected").hover(function() {
		$(this).attr("src","/i/screen/widgets/export-selected-to-file-hover.gif");
			}, function() {
		$(this).attr("src","/i/screen/widgets/export-selected-to-file.gif");
	});
	
});


 
 
 