//---- 		javascript utilites for web pages 		----//
//------------------------------------------------------

var test_val = "Russ";
var banner_images =  new Array; // array to tell what images are currently loaded to avoid dups

var my_landscape_imgs = new Array();
var my_portrait_imgs = new Array();
//var my_imgs_alt = new Array();
var change_order = new Array();

var new_pic= -1;

var imgs_loaded = 0;

function show_alert(){

	alert(test_val);
}

function load_images(){
// Set image URLs *//
my_landscape_imgs[0] = "images/Clive_and_John_lo.jpg";
my_landscape_imgs[1] = "images/calshot_velo_feb07.jpg";
my_landscape_imgs[2] = "images/Round4_003.jpg";
my_landscape_imgs[3] = "images/cross1a.jpg";
my_landscape_imgs[4] = "images/IMG_1478.jpg";
my_landscape_imgs[5] = "images/gal01.jpg";
my_landscape_imgs[6] = "images/andre_and_john3_lo.JPG";
my_landscape_imgs[7] = "images/Golder_Cups.jpg";
my_landscape_imgs[8] = "images/ECCA12KenPlatts.jpg";
my_landscape_imgs[9] = "images/Picture5.jpg";
my_landscape_imgs[10] = "images/Russ_and_Geoff_lo.jpg";
my_landscape_imgs[11] = "images/round4_0036.jpg";
my_landscape_imgs[12] = "images/Russ_Cross_Penshurst.JPG";
my_landscape_imgs[13] = "images/RussDunton.jpg";
my_landscape_imgs[14] = "images/BS107_0056_t.jpg";
my_landscape_imgs[15] = "images/BS107_0035_t.jpg";
my_landscape_imgs[16] = "images/BS107_0036_t.jpg";
my_landscape_imgs[17] = "images/BS107_0033_t.jpg";
my_landscape_imgs[18] = "images/BS107_0032_t.jpg";
my_landscape_imgs[19] = "images/BS107_0026_t.jpg";
my_landscape_imgs[20] = "images/BS107_0009_t.jpg";
my_landscape_imgs[21] = "images/DSC_5099.jpg";
my_landscape_imgs[22] = "images/CIMG0976_lo.JPG";
my_landscape_imgs[23] = "images/Steve_Hainault_Hilly1.jpg";
my_landscape_imgs[24] = "images/Geoff_Hainault-Hilly1.jpg";
my_landscape_imgs[25] = "images/Geoff_Hainault-Hilly2.jpg";
my_landscape_imgs[26] = "images/MaldonHill09-Mark.jpg";
my_landscape_imgs[27] = "images/MaldonHill09-Steve.jpg";
my_landscape_imgs[28] = "images/roller_comp1.jpg";






my_portrait_imgs[0] = "images/Martin_Ryan.jpg";
my_portrait_imgs[1]= "images/Jon_Roebuck.jpg";
my_portrait_imgs[2] = "images/pullen.jpg";
my_portrait_imgs[3] = "images/Jag_lo.jpg";
my_portrait_imgs[4] = "images/Rachel3.jpg";
my_portrait_imgs[5] = "images/cross2.jpg";
my_portrait_imgs[6] = "images/Martin_F_Gorrick_lo.jpg";
my_portrait_imgs[7] = "images/rachel_muddy.jpg";
my_portrait_imgs[8] = "images/round5_3_0009.jpg";
my_portrait_imgs[9] = "images/BS107_0023_t.jpg";
my_portrait_imgs[10] = "images/BS107_0011_t.jpg";
my_portrait_imgs[11] = "images/baldies.jpg";
my_portrait_imgs[12] = "images/MaldonHill09-Clive.jpg";
my_portrait_imgs[13] = "images/MaldonHill09-Mark2.jpg";
my_portrait_imgs[14] = "images/MaldonHill09-Russ.jpg";
my_portrait_imgs[15] = "images/MaldonHill09-Steve2.jpg";
my_portrait_imgs[16] = "images/rachel_cross_shield.jpg";


// this array selects the order that the photos change in
// pseudo random
change_order[0]=5;
change_order[1]=3;
change_order[2]=2;
change_order[3]=8;
change_order[4]=0;
change_order[5]=7;
change_order[6]=1;
change_order[7]=4;
change_order[8]=6;


}

function print_banner(){

	  //document.write("<table align='center' border='1' bgcolor='#000000'  cellpadding='1' cellspacing='1'>);

      //document.write("<img src='images/ford_banner3.jpg' width='980' height='220'></a></th> </tr>	  </table> <BR>");
      
      //document.write ("<TR><TD height='100' width='150'>hello</TD></TR>");
      //document.write("</table> <BR>");
      //document.write ("<img src='images/ford_banner3.jpg' width='980' height='220'>");
      document.write ("<table align='center' border='0' cellpadding='0' cellspacing='0'>");
      document.write ("<TR>");
      document.write ("<TD width='180' height='120' ><div id='Cell0'><img src='images/Clive_and_John_lo.jpg' width='180' height='120'></div></TD>");
      document.write ("<TD width='80' height='120' ><div id='Cell1'><img src='images/Martin_Ryan.jpg' width='80' height='120'></div></TD>");
      
      document.write ("<TD width='180' height='120' ><div id='Cell2'><img src='images/calshot_velo_feb07.jpg' width='180' height='120'></div></TD>");
      
      document.write ("<TD width='80' height='120' ><div id='Cell3'><img src='images/Jon_Roebuck.jpg' width='80' height='120'></div></TD>");
      document.write ("<TD width='180' height='120' ><div id='Cell4'><img src='images/Round4_003.jpg' width='180' height='120'></div></TD>");
      document.write ("<TD width='80' height='120' ><div id='Cell5'><img src='images/pullen.jpg' width='80' height='120'></div></TD>");
      document.write ("<TD width='180' height='120'><div id='Cell6'><img src='images/cross1a.jpg' width='180' height='120'></div></TD>");
      
      document.write ("</TR></table>");
      document.write ("<table align='center' border='0' cellpadding='0' cellspacing='0'><TR>");
      document.write ("<TD width='180' height='120' ><div id='Cell7'><img src='images/IMG_1478.jpg' width='180' height='120'></div></TD>");
      document.write ("<TD><img src='images/fcclogo.jpg' width='600' height='120'></TD>");
      document.write ("<TD width='180' height='120' ><div id='Cell8'><img src='images/gal01.jpg' width='180' height='120'></div></TD>");
      document.write ("</TR></table>");
      
      
}
//----------------------------------------------------------

function load_marquee (){
    var sText;
    
	sText ="";

	sText = sText + "<BR>Mark Donald Wins TT League with perfect 50s<BR><BR>";


	sText = sText + "<BR><BR>";
	
	sText = sText + "<BR><BR>";
	


	sText = sText + "Mud Sweat and Gears - Essex MTB Race series for 2010  <BR>www.mudsweatgears.co.uk<BR>";




			
	//sText = sText + "<br><br>";


	document.getElementById("marq_text").innerHTML = sText;
}
//------------------------------------------------------
function mq_scroll(iVal){
	// doesn't seem to work in FF
    
	if (iVal==0){
	   document.all.mq_news.stop();   
	}
	else{
	   document.all.mq_news.start();	
	}

}


//------------------------------------------------------
function set_highlight(this_obj){
    
	//toggle the highlight for given row
	if (this_obj.className=="row1"){
	   this_obj.className="row1_hl";	
	}
	else if (this_obj.className=="row1_hl"){
	   this_obj.className="row1";	
	}
	else if (this_obj.className=="row0_hl"){
	   this_obj.className="row0";	
	}
	else if (this_obj.className=="row0"){
	   this_obj.className="row0_hl";	
	}
	else if (this_obj.className=="row0b_hl"){
	   this_obj.className="row0b";	
	}
	else if (this_obj.className=="row0b_hl"){
	   this_obj.className="row0b";	
	}

}
//----------------------------------------------
function set_mail()
{
	// this is now fixed and works in IE and FF - 21-Aug-2008
     
     txtToAddr = "gbores";

     txtToAddr = txtToAddr + "@";
     txtToAddr = txtToAddr + "ford";
     txtToAddr = txtToAddr + ".";
     txtToAddr = txtToAddr + "com;jjohal7";
	 txtToAddr = txtToAddr + "@";
	 txtToAddr = txtToAddr + "ford";
     txtToAddr = txtToAddr + ".";
     txtToAddr = txtToAddr + "com";
     //alert (txtToAddr);
	
    // frm1.action = txtAction;
    // frm1.submit();			   // this doesn't work in FireFox (FF)
     
     
	var toaddy = txtToAddr;
	var subject = 'mail from FCC website';
	var mailer = 'mailto:' + toaddy + '?subject=' + subject 
	parent.location = mailer;
} // -->
//---------------------------------------------------

function open_large_image(this_obj){

	// center the popup
	sLeft = screen.width/2 - 300 ; 
	sTop = screen.height/2 - 300 ; 
	strParam = "resizable=yes, height=600 , width=600, left=" + sLeft + ", top= " + sTop ;

	open (this_obj.src,"Image",strParam );

}
//----------------------------------------------------
function print_footer(){


	document.write("<HR width=80%><DIV id=footer>");
	document.write("<CENTER><a href='index.htm' >Home</a><P>Copyright &copy 2007-2010 Ford Cycling Club</P></CENTER></DIV>")

}
//-----------------------------------------------------
function print_links_table(){

	document.write("<CENTER><H2>Links</H2></CENTER>");
	document.write("<table name='tblContacts' border='0' align='center'   cellpadding='0' cellspacing='10'>"	);
     
    document.write("    <TR align='center' CLASS='rowlink'><TD name='mob3'  >");
	document.write("British Cycle Federation (BCF) <BR>");
	document.write("<a href='http://www.britishcycling.org.uk/' target='_blank' class='style3'>");
    document.write("<img src='images/bcf_logo.jpg' height='70' width='70'>");
    document.write("</a></TD></TR>");
     
     document.write("<TR align='center' CLASS='rowlink'><TD name='mob1'>");
	 document.write("Dunton RR Results<BR>");


	 document.write("<a href='http://www.britishcycling.org.uk/web/site/BC/Bridge/calendar_results.asp?evt_cp=1&evt_mode=0&evt_id=&evt_seriesid=&evt_myevents=No&RefID=&RefType=&evt_year=2010&evt_month=Any&evt_kw=dunton&evt_regions=All+Regions&evt_disc=&evt_class=&evt_cat=&evt_series=' target='_blank'><img src='images/20070425_DUNTON_B.JPG' height='70' width='70'> ");
     document.write("</TD></TR>");

document.write("<TR align='center' CLASS='rowlink'><TD name='mob1'>");
	 document.write("Dunton RR Photos<BR>");
	 document.write("<a href='http://www.sportinpictures.co.uk' target='_blank'><img src='images/20070425_DUNTON_B.JPG' height='70' width='70'> ");
     document.write("</TD></TR>");



     document.write("<TR align='center' CLASS='rowlink'><TD name='mob2'   >");
	 document.write("   Cycling Time Trials<BR>");
	 document.write("  <a href='http://www.cyclingtimetrials.org.uk/' target='_blank'>");
     document.write("   <img src='images/johng.jpg' height='70' width='70'>");
	 document.write("</a></TD></TR>");
     
     document.write("<TR align='center' CLASS='rowlink'><TD name='mob3'  >");
	 document.write("  Eastern Cross<BR>");
	 document.write("   <a href='http://www.easterncross.org.uk/' target='_blank' class='style3'>");
     document.write("      <img src='images/crosser.jpg' height='70' width='70'>");
	 document.write("	</a></TD></TR>");


    document.write("<TR align='center' CLASS='rowlink'><TD name='mob3'  >");
	 document.write("  Cycling News<BR>");
	 document.write("   <a href='http://http://www.cyclingnews.com/' target='_blank' class='style3'>");
     document.write("      <img src='images/cyclingnews.jpg' height='70' width='70'>");
	 document.write("	</a></TD></TR>");


//     document.write(" <TR align='center' CLASS='rowlink'><TD name='mob3'  >");
//	 document.write("  Sheldon Brown<BR>");
//	 document.write("<a href='http://www.sheldonbrown.com' target='_blank' class='style3'>");
//     document.write("<img src='images/sheldon.jpg' height='90' width='60'>");
//	document.write("</a></TD></TR>");

// document.write(" <TR align='center' CLASS='rowlink'><TD name='mob3'  >");
//	 document.write("  Repair Tips<BR>");
//	 document.write("<a href='http://www.parktools.com/repair' target='_blank' class='style3'>");
//     document.write("<img src='images/spanner.jpg' height='70' width='70'>");
//	document.write("</a></TD></TR>");

	 
	document.write(" </TABLE>");






}
function print_links_table_2(){

   	document.write(" <p CLASS='rowlink'>");
    document.write("  Our BC Page<BR>");
    document.write("<a href='http://www.britishcycling.org.uk/web/site/BC/clu/cluClubFinder.asp?club_mode=1&club_id=%7BBFF1B79E-BD40-4DFD-BC53-414D9829A501%7D' class='style3'>");
    document.write("<img src='images/bcf_logo.jpg' height='90' width='60'>");
    document.write("</a><BR>");


   	document.write(" <p CLASS='rowlink'>");
 	document.write("  Sheldon Brown<BR>");
	document.write("<a href='http://www.sheldonbrown.com' target='_blank' class='style3'>");
   	document.write("<img src='images/sheldon.jpg' height='90' width='60'>");
	document.write("</a><BR>");

 	document.write("  <BR>Repair Tips<BR>");
 	document.write("<a href='http://www.parktools.com/repair' target='_blank' class='style3'>");
	document.write("<img src='images/spanner.jpg' height='70' width='70'>");
	document.write("</a>");

}

function rand_num(){

  // routine to randomly rotate the banner pictures (banner is now a table of pictures)
  // should prove more interesting than the current one
  //
  // - RGC - 06-Mar-2009 - I wrote this from scratch and it bloody works!


 //var ran_num = Math.floor(Math.random()*(my_imgs.length));
 var pic_to_change = Math.floor(Math.random()*(9));
 var t;
 var the_HTML;
 var this_pic; //string of current pic - used for duplicate detection

  var new_pt_img = Math.floor(Math.random()*(my_portrait_imgs.length));
  var new_ls_img = Math.floor(Math.random()*(my_landscape_imgs.length));
  
   if (imgs_loaded == 0 ){
      load_images();
      init_banner();
      
      //init_img_arrays(my_landscape_imgs ,my_portrait_imgs );
	imgs_loaded =1;


   }

  

  
  new_pic = new_pic+1;
  if(new_pic==9){
    new_pic=0;
  }
 

  pic_to_change = change_order[new_pic]; //0; // force it! for now
  //alert ('new_pic: ' + pic_to_change);
  
   
  //t=setTimeout("rand_num()",500);
  
  if((pic_to_change==1) || (pic_to_change==3) || (pic_to_change==5)){
    
     the_HTML = "<img src=\""+my_portrait_imgs[new_pt_img]+"\" width=\"80\" height=\"120\"/>";

    //alert('portrait:' +new_pt_img);  
    this_pic =my_portrait_imgs[new_pt_img];
  }
  else{
    
    the_HTML = "<img src=\""+my_landscape_imgs[new_ls_img]+"\"  width=\"180\" height=\"120\"/>";

    //alert('landscape: '+new_ls_img); 
    this_pic =my_landscape_imgs[new_ls_img] ;
  }


  //alert(this_pic+' '+ banner_images[pic_to_change] +'  ' +is_pic_in_banner(this_pic,banner_images[pic_to_change] ));

  if (is_pic_in_banner(this_pic, pic_to_change )==1){

     // have new pic already - don't change - retry quickly
     t=setTimeout("rand_num()",200);
  

  }
  else
     
  {
     // new pic is new so change it
     var the_div = document.getElementById("Cell"+pic_to_change);

     //the_HTML += "alt=\""+pic_to_change+"\" />";
     //alert (the_HTML);
     //alert(pic_to_change + ' ' +the_div.id);
     the_div.innerHTML = the_HTML;
     t=setTimeout("rand_num()",2000);
     //alert(this_pic);

  }

}
//-----------------------------------------------------------------
function init_banner(){

   banner_images[0]= my_landscape_imgs[0];
   banner_images[1]= my_portrait_imgs[0] ;
   banner_images[2]= my_landscape_imgs[1] ;
   banner_images[3]= my_portrait_imgs[1];
   banner_images[4]= my_landscape_imgs[2] ;
   banner_images[5]= my_portrait_imgs[2];
   banner_images[6]= my_landscape_imgs[3] ;
   banner_images[7]= my_landscape_imgs[4] ;
   banner_images[8]= my_landscape_imgs[5] ;

   for (i=0;i<9;i++){
      //alert('init_banner:'+ banner_images[i]);
   }
}
//-----------------------------------------------------------------
function is_pic_in_banner(iPic, pic_pos){
   // if the new pic is in the banner don't swap

   var found = false;
   var i; 

   //alert('pic_pos ='+ pic_pos ) 
   for (i=0;i<9;i++){

     // alert('looking for '+ iPic  + ' : '+ banner_images[i] + '\n pic_pos ='+ pic_pos +'\n found = '+ found  );

	if(iPic == banner_images[i]){
        //found it
        //alert('Found '+iPic + ' at position ' +i);
	  found =true;
        

      }

   }
   // if not found then update picture array
   if(!found ){
      //alert ('updating pic ref - was '+ banner_images[pic_pos] + ' now - ' +iPic) ;
      banner_images[pic_pos]=iPic;
      return 0;
   }
   else{
      return 1;
   }



}