var pausecontent=new Array()
var sgifs=new Array();
var slinks=new Array();

sgifs.push('images/animatedgifxmas.gif');slinks.push('christmas.htm');
sgifs.push('images/animatedgifshopvoucher.gif');slinks.push('shopclick.php?goodref=0001000');
//sgifs.push('images/animatedgifcamden1.gif');slinks.push('comedyclubs/camden/index.htm');
sgifs.push('images/animatedgifclapham.gif');slinks.push('comedyclubs/clapham/index.htm');
sgifs.push('images/animatedgifcity.gif');slinks.push('comedyclubs/thecity/index.htm');
sgifs.push('images/animatedgifimpro.gif');slinks.push('comedycourses/comedy-courses');
sgifs.push('images/animatedgifactsaz.gif');slinks.push('comedians/index.htm');
//sgifs.push('images/animatedgifhenning.gif');slinks.push('shopclick.php?goodref=0003000');
var numpics=sgifs.length;

for(i=0;i<numpics;i++){MM_preloadImages(spath+sgifs[i]);}

//var startnum=Math.floor(Math.random()*numpics)
var startnum=0;//for testing

for(i=0;i<numpics;i++){
  code='<a href="'+spath+slinks[i]+'"><img src="'+spath+sgifs[i]+'" style="width:580px;height:60px;border:none;" /></a>';
  pausecontent[(startnum+i)%numpics]=code;  
}

/*****************************************************************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
* ****************************************************************************************
* The code has been largely replaced/updated so go to their site if you want the original
******************************************************************************************/
function pausescrollerhidden(content,divId,divClass,delay){
//Temporarily do nothing
}

//new pausescroller(name_of_message_array,CSS_ID,CSS_classname,pause_in_miliseconds)
function pausescroller(content,divId,divClass,delay){
  this.content=content //message array content
  this.tickerid=divId //ID of ticker div to display information
  this.delay=delay; //Delay between msg change, in miliseconds.???????????HARD CODED RATHER THAN PASSED IN
  this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
  this.hiddendivpointer=1 //index of message array for hidden div

  towrite='<div id="'+divId+'" class="'+divClass+'" style="position:relative;overflow:hidden;text-align:center;">';
  towrite+='<div class="innerDiv" style="position:absolute;left:0px;width:100%;text-align:center;" id="'+divId+'1">';
  towrite+=content[0];
  towrite+='</div>';
  towrite+='<div class="innerDiv" style="position:absolute;left:0px;width:100%;visibility:hidden;text-align:center;" id="'+divId+'2">';
  towrite+=content[1];
  towrite+='</div>';
  towrite+='</div>';

  //alert(towrite);

  $(towrite).prependTo("div#pagetop");

  var scrollerinstance=this
  $(document).ready(function(){
    scrollerinstance.initialize();
  });

}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
pausescroller.prototype.initialize=function(){

  this.tickerdiv=$("#"+this.tickerid)
  this.visiblediv=$("#"+this.tickerid+"1")
  this.hiddendiv=$("#"+this.tickerid+"2") 

  this.visibledivtop=parseInt($(this.tickerdiv).css("padding-top"));

  //set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
  $(this.visiblediv).css({'width':($(this.tickerdiv).attr("offsetWidth")-(this.visibledivtop*2))+"px"});
  $(this.hiddendiv).css({'width':($(this.tickerdiv).attr("offsetWidth")-(this.visibledivtop*2))+"px"});

  this.getinline(this.visiblediv,this.hiddendiv)

  $(this.hiddendiv).css({'visibility':'visible'});

  var scrollerinstance=this
  $(this.tickerdiv).hover(
    function(){scrollerinstance.mouseoverBol=1;}, 
    function(){scrollerinstance.mouseoverBol=0;}
  );

  //Clean up loose references in IE
  $(window).unload(function(){$(this.tickerdiv).unbind('mouseenter mouseleave');});
  
  setTimeout(function(){scrollerinstance.animateup()},this.delay)

}

// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
pausescroller.prototype.animateup=function(){
  var scrollerinstance=this
  if(parseInt($(this.hiddendiv).css("top"))>(this.visibledivtop+5)){
    $(this.visiblediv).css({'top':parseInt($(this.visiblediv).css("top"))-5+"px"});
    $(this.hiddendiv).css({'top':parseInt($(this.hiddendiv).css("top"))-5+"px"});
    setTimeout(function(){scrollerinstance.animateup()},50)
  } else{
    this.getinline(this.hiddendiv,this.visiblediv)
    this.swapdivs()
    setTimeout(function(){scrollerinstance.setmessage()},this.delay)
  }
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
pausescroller.prototype.swapdivs=function(){
  var tempcontainer=this.visiblediv
  this.visiblediv=this.hiddendiv
  this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1,div2){
  $(div1).css({'top':this.visibledivtop+"px"});
  $(div2).css({'top':Math.max($(div1).parent().attr("offsetHeight"),$(div1).attr("offsetHeight"))+"px"});
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
pausescroller.prototype.setmessage=function(){
  var scrollerinstance=this
  if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
    setTimeout(function(){scrollerinstance.setmessage()},100)
  else{
    var i=this.hiddendivpointer
    var ceiling=$(this.content).length
    this.hiddendivpointer=(i+1>ceiling-1)?0:i+1
    $(this.hiddendiv).html(this.content[this.hiddendivpointer]);
    this.animateup()
  }
}
