// JavaScript Document

var imgDir = '/home/images';

$(document).ready(function(){
   
   $('.btnProtocol').each(function(){
	    var currentImgPath = this.src;
		var newImg = this.src.substring(0,this.src.length - 7) + 'on.jpg';
		
		//Setup Portocol Image Detail Change
		$(this).bind('mouseover',function(){
			protoIconsOff();
			$(this).attr('src',newImg);
		    $('#protocolDetail').attr('src',imgDir + '/home-protocal-detail-' + this.title.toLowerCase() + '.gif');
			showProtoInfo(this.title);
		});
		
	});
   
   /*
   $('.btnNav').each(function(){
	    var currentImgPath = this.src;
		
		if(this.src.indexOf('-off.') > -1){
		    //img is off
			var turn = 'on';
			var trimOff = 7;
		}
		else{
		    //img is on
			var turn = 'off';
			var trimOff = 6;
		}
		
		var newImg = this.src.substring(0,this.src.length - trimOff) + turn + '.gif';
		
		$(this).hover(
		    function(){$(this).attr('src',newImg);},
			function(){$(this).attr('src',currentImgPath);}
		);
		
	});
   */
   
   $('.imgSwap').each(function(){
	    var currentImgPath = this.src;
		var ext = this.src.substring(this.src.length - 3);
		
		if(this.src.indexOf('-off.') > -1){
		    //img is off
			var turn = 'on';
			var trimOff = 7;
		}
		else{
		    //img is on
			var turn = 'off';
			var trimOff = 6;
		}
		
		var newImg = this.src.substring(0,this.src.length - trimOff) + turn + '.' + ext;
		
		$(this).hover(
		    function(){$(this).attr('src',newImg);},
			function(){$(this).attr('src',currentImgPath);}
		);
		
	});
   
   //Defaults
   showProtoInfo('CPR');
   
   $.preloadImages(
				   "images/home-p1-on.jpg",
				   "images/home-p2-on.jpg",
				   "images/home-p3-on.jpg",
				   "images/home-p4-on.jpg",
				   "images/home-p5-on.jpg",
				   "images/home-p6-on.jpg",
				   "images/home-p7-on.jpg",
				   "images/home-p8-on.jpg",
				   "images/home-protocal-detail-cpr.gif",
				   "images/home-protocal-detail-choking.gif",
				   "images/home-protocal-detail-alergic.gif"
				   );
   
   
});

function showProtoInfo(k){
    $('#protocolInfo').html($('#info'+ k).html());
}

function protoIconsOff(){
    $('.btnProtocol').each(function(){
	    var currentImgPath = this.src;
		
		if(this.src.indexOf('-off.jpg') > -1){
		    //img is off
			var trimOff = 7;
		}
		else{
		    //img is on
			var trimOff = 6;
		}
		
		var newImg = this.src.substring(0,this.src.length - trimOff) + 'off.jpg';
		$(this).attr('src',newImg);
	});
}

function playVideo(key){
    var vid = new Array;
	vid['today']        = '<iframe height="339" width="425" src="http://www.msnbc.msn.com/id/22425001/vp/23688605#23688605" frameborder="0" scrolling="no"></iframe>';
	vid['univision']    = '<iframe frameborder="0" height="380" src="http://www.univision.com/content/flashvideo/embed.jhtml?vars=videoCID%3D1513802" width="400"></iframe>';
	vid['mommywarrior'] = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="300" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.vimeo.com/moogaloop.swf?clip_id=1036779&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="300" src="http://www.vimeo.com/moogaloop.swf?clip_id=1036779&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" allowfullscreen="true" allowscriptaccess="always"></embed></object>';
	
	$('#videoHere').html(vid[key]);
}

$.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

