$(document).ready(function(){

    // THIS FIXES THE "BUG" WITH THE SCROLLER AND COLORBOX
    $("a").live("mouseover", function(){
    	$(".youtubenohd").colorbox({
    		iframe: true,
    		opacity: .55,
    		width: 460,
    		height: 460
    	});
    	
    	$(".flv").colorbox({
    		iframe: true,
    		opacity: .55,
    		width: 680,
    		height: 590
    	});
    	
    	$(".a1").colorbox({
    		iframe: true,
    		opacity: .55,
    		width: 980,
    		height: 800
    	});
    });
    // END SCROLLER/COLORBOX BUGFIX
    
    
    // Start the image scroller
    $("div#imageScroller").smoothDivScroll({
    	scrollingSpeed: .1, 
    	autoScroll: "always", 
    	autoScrollDirection: "endlessloop", 
    	autoScrollSpeed:1,
    	pauseAutoScroll: "mouseover"
    });
    
    // Function to start the rotating quotes
    theRotator();
    
    
    // Set all the elements that will be shown in a lightbox
    $(".lb").colorbox();
    $(".flv").colorbox({iframe:true, width:680,height:590,opacity:.55});
    $(".contactlink").colorbox({iframe:true, width:510,height:400,opacity:.55});
    $(".privlink").colorbox({iframe:true, width:520,height:520,opacity:.55});
    $(".youtubenohd").colorbox({iframe:true, width:460,height:400,opacity:.55});
    $(".stalok").colorbox({iframe:true, width:680,height:550,opacity:.55});
    $(".texthtml").colorbox({iframe:true, width:980,height:"100%",opacity:.55});
    $(".gvid").colorbox({iframe:true, width:680,height:540,opacity:.55});
    $(".surv").colorbox({iframe:true, width:980,height:"100%",opacity:.55});
    $(".a1").colorbox({iframe:true, width:980,height:800,opacity:.55});
    
// my qtips

$('a[title]').qtip({ 
 position: {adjust: {screen: true}}, style: {'font-family':'arial,sans-serif',tip: 
{target:'topRight',corner: 'topRight', color: '#660000', size: {x:20, y:8}},
width:300,padding: 5,  
background: '#E8E3BD',  
color: '#212931', 
textAlign: 'left',
border: {width: 2, radius:2,color: '#006600'}}});
});
 







function sendSurvey()
{
    roles = document.getElementById("role");
    selectedRole = roles.options[roles.selectedIndex].value;
    
    if (selectedRole == 'null') { alert('Please select your role in the incident.'); return; }
    
    firstName = document.getElementById("firstName").value;
    lastName = document.getElementById("lastName").value;
    email = document.getElementById("email").value;
    desc = document.getElementById("description").value;
    
    if (desc == '') { alert('Please enter a description of the needlestick incident.'); return; }
    
    				
    $.ajax({
    	type: "POST",
    	url: "surveys/submitSurveyAjax.php",
    	data: $("#ajaxSurvey").serialize(),
    	success: function(msg){
    	  if (msg == "Success") 
    	  { 
    	  	document.getElementById("takesurvey").innerHTML = "<span class='surveythanks'>Thank you for submitting your needlestick experience. <br />We will post it as soon as we moderate it.</span><div style='float:right;width:100px;'><a href='' onclick='document.getElementById('takesurvey').style.display='none'; return false;'><span style='font-size:20px;color:red;'>X</span></a><span style='font-size:10px;'><br />(click to close survey) </span><br /><br /></div>";
    	  } else { 
    	  	alert(msg);
    	  }
    	}
     });
    
}

/*
    This is the code for the rotating quotes
*/

function theRotator() {
    //Set the opacity of all images to 0
    $('div#rotator ul li').css({opacity: 0.0});
    
    //Get the first image and display it (gets set to full opacity)
    $('div#rotator ul li:first').css({opacity: 1.0});
        
    //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
    setInterval('rotate()',10000);
    
}	
    
function rotate() {	
    //Get the first image
    var current = ($('div#rotator ul li.show')?  $('div#rotator ul li.show') : $('div#rotator ul li:first'));
    
    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#rotator ul li:first') :current.next()) : $('div#rotator ul li:first'));	
    
    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({opacity: 0.0})
    .addClass('show')
    .animate({opacity: 1.0}, 1000);
    
    //Hide the current image
    current.animate({opacity: 0.0}, 1000)
    .removeClass('show');
    
};	

/*
    End rotating quotes code
*/