// JavaScript Document

$(document).ready(function(){

	$(".emailLink").click(function () { 
      	mail_str = "mailto:?subject=Check out the " + document.title;
		mail_str += "&body=I thought you might be interested in the " + document.title + " page on the UCSF Fetal Treatment Center website.";
		mail_str += ".  You can view it at, " + location.href; 
		location.href = mail_str;
		return false;
    });
	$(".printLink").click(function () {
		window.print();
		return false;
	});
	$("#birthDefectsSelect").toggle(
		function () {
			$("#birthDefectsSubMenu").show("slow");
			$(this).css({'background' : '#E6E1DA url(/global_images/defect_nav_arrow.gif) no-repeat 3px -17px'});
		},
		function () {
			$("#birthDefectsSubMenu").hide();
			$(this).css({'background' : '#E6E1DA url(/global_images/defect_nav_arrow.gif) no-repeat 3px 4px'});
		}
	);
	$(".watchvid").each(function (i) {
        var url = this.href;
		var vidId = url.split('v=')[1].split('&')[0];
		var vidthumb = $(this).children()[0];
		if( jQuery.browser.msie && (jQuery.browser.version <= 7) ) {
			$(vidthumb).replaceWith("<img src='http://i2.ytimg.com/vi/"+ vidId +"/default.jpg' alt='watchvideo' />");
			$(this).append("<span class='vidbtnIE'>Watch Video</span>");
		} else {
			$(vidthumb).replaceWith("<span class='outerwrapper'><span class='innerwrapper'><img src='http://i2.ytimg.com/vi/"+ vidId +"/default.jpg' alt='watch video' /></span></span>");
		}
      });
	$(".ceebox").ceetip().ceebox({vidHeight:400,vidWidth:600});

});

// CeeTip function based on vtip by vertigo project http://www.vertigo-project.com/projects/vtip but changed into a function and modified to work with CeeBox
(function($) {
	$.fn.ceetip = function(settings) {
		var option = $.extend({}, $.fn.ceetip.defaultSettings, settings);

		return this.each(function() {
			$this = $(this);
			
			$this.unbind("hover").hover(    
				function(e) {
					this.t = this.title;
					this.title = ''; 
					this.top = (e.pageY + option.yOffset); this.left = (e.pageX + option.xOffset);
					
					$('body').append( '<p id="ceetip"><img id="ceetipArrow" />' + this.t + '</p>' );
								
					$('p#ceetip #ceetipArrow').attr("src", "/images/vtip_arrow.png").css({
						'position': 'absolute',
						'top': '-10px',
						'left': '5px',
					});
					$('p#ceetip').css({
						'top':this.top+'px',
						'left':this.left+'px',
						'display': 'none',
						'position': 'absolute',
						'padding': '10px', 
						'font-size': '0.8em',
						'background-color': '#fff',
						'border': option.border,
						'-moz-border-radius': '5px',
						'-webkit-border-radius': '5px',
						'z-index': '9999'
					}).fadeIn("slow");
					
				},
				function() {
					this.title = this.t;
					$("p#ceetip").fadeOut("slow").remove();
				}
			).mousemove(
				function(e) {
					this.top = (e.pageY + option.yOffset);
					this.left = (e.pageX + option.xOffset);
								 
					$("p#ceetip").css("top", this.top+"px").css("left", this.left+"px");
				}
			);  
		})
	}

	$.fn.ceetip.defaultSettings = {xOffset:-12,yOffset:30,border:'1px solid #a6c9e2'} //default drops in right under the windows 
})(jQuery);


