$(function()
{
		//DPMC ticker
		// ------------------------------------------------------------
				
		//Calculate the size of scrolling div based on the span tags found
		//inside the div
		var twidth = 0;
		$.each( $("#ticker").children(), function(){
			 twidth +=$(this).outerWidth(true);
		});
		
		//Reported width seems to be inaccurate for computed styles
		//for inline elements, so for now add extra length to compensate
		// based on a value added for each span tag.
		//I am using the size of right padding set on the span style.
		twidth += 20*$("#ticker").children().length;
		$("#ticker").css("width", twidth);
		
		// Speed in milliseconds lower number is faster scroll
		var scrollSpeed = 15;       
		var step = 1;               
		var current = 800;           

		//position to restart scroll
		//this is set to happen when end of scroll div is reached
		var restartPosition = -(twidth);
		
		function scrollDiv(){
				current -= step;
			 
				//If at the end scroll div, then start over.
				if (current == restartPosition){
						current = 800;
				}
				$('#ticker').css("left", current+"px");	 
	  }
	  
		//function stopDiv(){
		//	ClearInterval(init);
	  //}

	//Calls the scrolling function repeatedly
	var init = setInterval(scrollDiv, scrollSpeed);
	
	$(".stockticker").hover(
		function (){ init = clearInterval(init); },
		function (){ init = setInterval(scrollDiv, scrollSpeed);  
	});
	
	//---------------------------------------------------------------------
  
  
  //DPMC customer quote changer
  //---------------------------------------------------------------------
  var test = $("div[class='customerq']");
  var index = 1;
  var switchSpeed = 9000;
  $(test[0]).css("display","block");
  
  function switchDiv(){
    if(index > (test.length-1)) {
      index = 0;
    }
    
    for(var i=0; i < test.length; i++){
       $(test[i]).fadeOut("fast");
    }
    $(test[index]).fadeIn("slow");
    index++;
  }
 
  var cust = setInterval( switchDiv, switchSpeed);
  
  $(".quotebox").hover(
		function (){ cust = clearInterval(cust); },
		function (){ cust = setInterval(switchDiv, switchSpeed);  
	});
 
  //---------------------------------------------------------------------
  
  //DPMC Home page message switcher
  //---------------------------------------------------------------------
  var mtest = $("div[class='message']");
  var mindex=1;
  $(mtest[0]).css("display","block");
  
  function switchMessage(){
    if(mindex > (mtest.length-1)) {
      mindex = 0;
    }
    
    for(var i=0; i < mtest.length; i++){
       $(mtest[i]).fadeOut("fast");
    }
    $(mtest[mindex]).fadeIn("fast");
    mindex++;
  }
 
  var message = setInterval( switchMessage, 14000);
  
 
});
