var map;
var directionsPanel;
var directions;
var old_background = 0;
/*@cc_on
  @if (@_jscript_version == 5.6)
var main_panel_div;
var top_slider_div;
var contact_div;
var rhs_div;
var price_list_div;
var main_container;
  @end
  @*/

function load() {
/*@cc_on
  @if (@_jscript_version == 5.6)
  main_panel_div = document.getElementById( "main_panel" );
  top_slider_div = document.getElementById( "top_slider" );
  contact_div = document.getElementById( "contact" );
  rhs_div = document.getElementById( "rhs" );
  price_list_div = document.getElementById( "price_list" );
  main_container = document.getElementById( "main_container" );
  ie6adjust();
  @end
  @*/
  document.getElementById( "salon_slide_chooser" ).onclick = function() { launch_top_strip( 0 ); return false; };
  document.getElementById( "clients_slide_chooser" ).onclick = function() { launch_top_strip( 1 ); return false; };
  change_background();
  launch_top_strip( 0 );
  launch_strip( "look4strip", 110, 660, 1100 );
  launch_strip( "look3strip", 110, 550, 1220 );
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map"));
    var mapcenter=new GLatLng(52.938,-1.256);
    var pincenter=new GLatLng(52.938533,-1.257802);
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(mapcenter, 15);
    map.addOverlay(new GMarker(pincenter));
    map.setMapType(G_NORMAL_MAP);
  }
}

var imagelist = [ 
  "tigi/blond.jpg",
  "tigi/brunette.jpg",
  "tigi/gent.jpg",
  "tigi/curls.jpg",
  "tigi/jack.jpg",
  "tigi/curls3.jpg"
];

function change_background()
{
  var index;
  do
  {
    index = Math.floor( Math.random() * imagelist.length );
  } while ( index == old_background );
  old_background = index;
  document.getElementById( "price_list" ).style.backgroundImage='url("' + imagelist[index] + '")';
}

function clear_background()
{
  document.getElementById( "price_list" ).style.backgroundImage='none';
}

var top_strips = [
  { id: "salon_slider", repeat: 2042, timer:null, chooser_id:"salon_slide_chooser" },
  { id: "clients_slider", repeat: 2852, timer:null, chooser_id:"clients_slide_chooser" }
];
var cur_top_strip = -1;

function launch_top_strip( strip_num )
{
  if ( cur_top_strip == strip_num )
    return;
  if ( cur_top_strip != -1 )
  {
    document.getElementById( top_strips[cur_top_strip].id ).style.visibility="hidden";
    document.getElementById( top_strips[cur_top_strip].chooser_id ).className="slide_chooser";
    clearInterval( top_strips[cur_top_strip].timer );
  }
  cur_top_strip = strip_num;
  document.getElementById( top_strips[strip_num].id ).style.visibility="visible";
  document.getElementById( top_strips[strip_num].chooser_id ).className="active_slide_chooser";
  top_strips[strip_num].timer = launch_strip( top_strips[strip_num].id, 1, top_strips[strip_num].repeat, 30 );
}

function launch_strip( given_div_id, given_offset, given_count, given_speed )
{
  var div = document.getElementById( given_div_id );
  var index = 0;
  var offset = given_offset;
  var count = given_count;
  return setInterval( 
    function()
    {
      div.style.marginLeft = -(Math.floor(index)) + 'px';
      index += offset;
      index %= count;
    }, given_speed );
}

window.onload=load;
window.onunload=GUnload;

function ie6adjust()
{
  var temp_height = document.documentElement.clientHeight;
  var temp_width = document.documentElement.clientWidth;

  rhs_wid = (temp_width - 560);
  if (rhs_wid < 100)
    rhs_wid = 100;
  if (rhs_wid > 750)
    rhs_wid = 750;
  rhs_div.style.width = rhs_wid+ "px";
  top_slider_div.style.width = rhs_wid + "px";
  price_list_div.style.width = rhs_wid + "px";

  if ( temp_height < 400 )
    temp_height = 400;
  main_panel_div.style.height = (temp_height - 60) + "px";
  contact_div.style.top = (temp_height - 55) + "px";;
  rhs_div.style.height = (temp_height - 60) + "px";
  price_list_div.style.height = (temp_height - 305) + "px";
  setTimeout( ie6adjust, 500 );
}
