var h2;
var w2;
var w;
var h;
var iswide;
var backindex=0;







var timer_time=2500;

var image_num=Math.floor(Math.random()*backs.length);

var background = new Object();
var background = {image:backs[image_num].image, caption:backs[image_num].caption, width:backs[image_num].width, height:backs[image_num].height};
var image = new Image(); 
var image2 = new Image(); 
var image3 = new Image(); 
var image4 = new Image(); 

var text="content of text here";
var delay=50;
var currentChar=1;
var destination="[not defined]";



function type()
{
  if (document.getElementById)
  {
    var dest=document.getElementById(destination);
    if (dest)
    {
      dest.innerHTML=text.substr(0, currentChar);
      currentChar++
      if (currentChar>text.length)
      {
        //viewport();
        //currentChar=1;
        //setTimeout("type()", 5000);
      }
      else
      {
        setTimeout("type()", delay);
      }
    }
  }
}

function startTyping(textParam, delayParam, destinationParam)
{
  text=textParam;
  delay=delayParam;
  currentChar=1;
  destination=destinationParam;
  delayed_viewport();
  type();
}


function backInfo(image, caption, width, height) {   
    this.image = image; 
    this.caption = caption; 
    this.width = width; 
    this.height = height;  
}

 
function getFlashMovie(movieName) {   
    var isIE = navigator.appName.indexOf("Microsoft") != -1;   
    return (isIE) ? window[movieName] : document[movieName];  
}   
                     

function change_back(change_val) { 
    backindex=(backindex+change_val+backs.length)%backs.length;
    background.image=backs[backindex].image;
    background.caption=backs[backindex].caption;
    background.width=backs[backindex].width;
    background.height=backs[backindex].height;
    iswide=2;
    image.onload = function() {
        viewport();
        getFlashMovie("refresher").play_pause_flash();
    };
    image.src = background.image;
}

function delayed_viewport(){


image.onload = function() {
    setTimeout('viewport()', timer_time);
    setTimeout('slide_in()', timer_time+200);
    setTimeout('document.getElementById(\'title\').innerHTML="<a href=\'mailto:info@astandred.co.uk\'><img src=\'astandred2.png\' alt=\'ast &amp; red websites\' width=\'242\' height=\'184\' style=\'border:none;outline:none;\' border=\'0\' /></a>";', timer_time); 

};
image.src = background.image;
image2.src = "astandred2.png";
image3.src = "images/largeNext.png";
image4.src = "images/refresh.gif";

}

function slide_in(){
    $("#title").animate({top:"10px"}, 1500, function(){
        $("#content2").animate({left:"20px"}, 1000, function(){
            $("#content2_fade").animate({opacity:1}, 1000, function(){
                $("#changeImage").animate({top:"0px"}, 300);        
            });        
        });        
    });
}


function viewport()
{

 if (typeof window.innerWidth != 'undefined')
 {
      w = window.innerWidth,
      h = window.innerHeight
 }

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       w = document.documentElement.clientWidth,
       h = document.documentElement.clientHeight
 }

 else
 {
       w = document.getElementsByTagName('body')[0].clientWidth,
       h = document.getElementsByTagName('body')[0].clientHeight
 }

//alert('w='+w+' and h='+h+' and bw='+background.width+' and bh='+background.height+' and iswide='+iswide);

if ((w/h > (background.width/background.height)) && (iswide!=1)){
    document.getElementById('bg').innerHTML="<img src='" + background.image + "' width='100%' alt='' />";
    iswide=1;
}else if ((w/h <= (background.width/background.height)) && (iswide!=0)){
    document.getElementById('bg').innerHTML="<img src='" + background.image + "' height='100%' alt='' />";
    iswide=0;
}


}


