function swapImage(e, src){
  $(e).src = src;
}

function swapBkgImage(e, src){
  //alert_debug($(e));
  $(e).style.backgroundImage = 'url('+src+')';
  //alert("image swapped :"+$(e).style.backgroundImage+":");
}

function alert_debug(obj)
{
  // debugging function
  
  var str = "";
  for (var prop in obj) {
    str = str + prop + " = " + obj[prop] + ";";
  }
  //if($('debug')){
    //$('debug').innerHTML = str;
  //}else{
    alert("Debug: " + str);
  //}
}

function hide(el){
  el.style.display = "none";
}

function show(el){
  el.style.display = "block";
}

function my_hide(el){
  el.style.display = "none";
}

function my_show(el){
  el.style.display = "block";
}

function hide_existing_login()
{
  Element.hide("existing_customer_login");
  Element.show("signup");
}

function show_existing_login()
{
  Element.show("existing_customer_login");
  Element.hide("signup");
}


function hide_dd_form()
{
  try {
    Element.show("credit_card_form");
    Element.hide("direct_debit_form");
  }
  catch (e)
  {
    alert('RJS error:\n\n' + e.toString()); alert('Element.show(\"credit_card_form\");\nElement.hide(\"direct_debit_form\");');
    throw e
  }

}

function hide_cc_form()
{
  try {
    Element.hide("credit_card_form");
    Element.show("direct_debit_form");
  }
  catch (e)
  {
    alert('RJS error:\n\n' + e.toString()); alert('Element.hide(\"credit_card_form\");\nElement.show(\"direct_debit_form\");');
    throw e
  }
}


function show_standalone_form()
{
  try {
    Element.show("standalone_form");
    //Element.hide("overflow_form");
    
  }
  catch (e)
  {
    //alert('RJS error:\n\n' + e.toString()); alert('Element.show(\"new_form\");\nElement.hide(\"churn_form\");');
    throw e
  }
}


function show_click_to_call(){

  var screen = document.getElementById('clicktocall');
  if (screen.style.zIndex != "90000")
  {
  screen.style.position = "fixed";
  screen.style.zIndex   = "90000";
  screen.style.top      = "70px";
  
  screen.style.left     = ((document.body.offsetWidth/2)-175) + "px";
  }

  var blocker = document.getElementById( "blocker" );
  blocker.style.filter = "alpha(opacity=90)";
  blocker.style.MozOpacity = ".9";
  blocker.style.opacity = ".9";
  blocker.style.width   = "100%";
  //blocker.style.height  = "100%"; // not enough ..
  
  blocker.style.height  = document.getElementById('body_table').offsetHeight + "px";
  blocker.style.overflow= "hidden";
  blocker.style.left    = "0px";
  blocker.style.top     = "0px";
  blocker.style.position= "absolute";
  blocker.style.zIndex  = "89999"; //phew, just under 9000 ;)
  blocker.style.backgroundColor = "#EBECFF";
  
  my_show( blocker );
  my_show( screen );
}

function hide_click_to_call(){
  my_hide( document.getElementById( "blocker" ) );
  my_hide( document.getElementById( "clicktocall" ) );
}


function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

