var TimeToFade = 1000.0;
var stopMessage = false;
function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null
        || element.style.opacity == ''
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
   
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }  
}

function animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
 
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}

//swap image
function swapImage(image, on) {
	
	if(on) {
		image.src= image.src.replace("_off", "_on");
	}
	else {
		image.src= image.src.replace("_on", "_off");		
	}
}

//swap image
function swapImageById(imageId, on) {
	
	var imageEl = document.getElementById(imageId)
	if(on) {
		imageEl.src= imageEl.src.replace("_off", "_on");
	}
	else {
		imageEl.src= imageEl.src.replace("_on", "_off");		
	}
}

r=107;
g=114;
b=108;
text="";
divid="";
complete=true;

function resetTest() {
	if(complete) {
	setColour(107,114,108, "Craftinsure.com was established in 2001 as the UK's first on-line boat insurance provider, designed specifically to offer competitive, comprehensive insurance via the internet. <a href='aboutus/aboutus.asp'>Find out More about Us</a>", "fader", true, false);
	}
}

function setColour(rc, bc, gc, newText, id, out, stopScroll) {
	stopMessage = stopScroll;
 if(document.getElementById(id) == null) {
	return;
 }

 if((out) && (document.getElementById(id).innerHTML == newText) ) {
	return; 
 }

 if(!complete) {
	return; 
 }

 complete = false;
 r = rc;
 g = gc;
 b = bc;
 rf = rc;
 bf = bc;
 gf = gc;
 text = newText;
 divid=id;
 if(out) {
	 fadeouttext();
 }
 else {
	 rf = bf = gf = 255;
	 fadeintext();	 
 }
}

function fadeouttext(){ 

if( (rf<=255) && (gf<=255) && (bf<=255) ) { 
rf+=11;
gf+=11;
bf+=11;
document.getElementById(divid).style.color="rgb("+rf+","+gf+","+bf+")";
setTimeout("fadeouttext()",10); 
}
else {
  if(text != "") {
	document.getElementById(divid).innerHTML = text;
  }
  
  fadeintext();	
}
}

function fadeintext(){ 
if( (rf>r) && (gf>g) && (bf>b) ) { 
rf-=11;
gf-=11;
bf-=11;
document.getElementById(divid).style.color="rgb("+rf+","+gf+","+bf+")";
setTimeout("fadeintext()",10); 
}
else {
complete = true;
}
}

mainCount=0;
function mainText() {
	
	if(stopMessage) {
		return;	
	}
var mainContent=new Array();
mainContent[0]="Select your boat type from the list on the left to get started. Click the arrows for more options. You can obtain a quote in under a minute.";
mainContent[1]="You can check a sample policy in the quote pages and then purchase immediate cover if required, to receive your Policy instantly by email";
mainContent[2]="Use our FAQ section for commonly asked advice, or contact us <a href='aboutus/contactus.asp'>here</a> if you would rather speak to us. Click our logo to return to our Home Page at any time.";
mainContent[3]="Craftinsure was established in 2001 as the UK's first online boat insurance provider, designed specifically to offer competitive, comprehensive insurance on the internet. <a href='aboutus/aboutus.asp'>Find out More About Us</a>";


mainCount++;
if(mainCount==4) {
 mainCount=0;
}
setColour(107,114,108, mainContent[mainCount], "fader", true, false);
setTimeout("mainText()",8000); 
	
}

count=0;
var maxCount = 3;
var stories=new Array();
stories[0]="Keep up to date with Craftinsure and boating news";
stories[1]="Follow us on Facebook or Twitter.";
stories[2]="We look forward to hearing from you!";

function newsStories() {

count++;
if(count==maxCount) {
 count="0";
}
setColour(107,114,108, stories[count], "news", true, false);
setTimeout("newsStories()",10000); 

}

function pageLoad() {
	setColour(107,114,108, "Craftinsure.com was established in 2001 as the UK's first on-line boat insurance provider, designed specifically to offer competitive, comprehensive insurance via the internet. <a href='#'>Find out More about Us</a>", "fader", false, false);
}

function preLoad() {
 preload_image_object = new Image();
      // set image url
      image_url = new Array();
      image_url[0] = "images/nav/quick_quote_on.png";
      image_url[1] = "images/nav/existing_customers_on.png";
		image_url[2] = "images/nav/existing_customers_on.png";
		image_url[3] = "images/menu_arrow_on.png";
		image_url[4] = "images/modules/small_module_arrow_on.png";
		image_url[5] = "images/nav/claims_on.png";
		image_url[6] = "images/nav/about_us_on.png";
		image_url[7] = "images/nav/links_on.png";
		image_url[8] = "images/nav/faqs_on.png";
		image_url[9] = "images/irish_flag_on.png";
		image_url[10] = "images/uk_flag_on.png";
		image_url[11] = "images/modules/help_me_on.png";
		image_url[12] = "images/modules/large_arrow_link_on.png";
		image_url[13] = "images/modules/make_a_claim_on.png";
		image_url[14] = "images/twitter_on.png";
		image_url[15] = "images/facebook_on.png";

       var i = 0;
       for(i=0; i<=15; i++) {
         preload_image_object.src = image_url[i];
	}
}

var logIt = function(data) {

	for(i=0; i<data.length;i++) {
		stories[i] = data[i].text;
	}
	maxCount = data.length;
}


