
$(document).ready(function() {
	$(".mailinglistlink").click(function() {
		$(".mailinglist").toggle('blind', '', 1000);
	});
	
	$('.searchbox').val('Search...');
	$('.searchbox').focus(function() {
		if($('.searchbox').val()=='Search...') $('.searchbox').val('');
	});
	$('.searchbox').blur(function() {
		if($('.searchbox').val()=='') $('.searchbox').val('Search...');
	});
	
	clock();
	
	$('.left_menu a[href*=]').prepend("&#9679; ");
	
	$(".searchbox").autocomplete({
		source: "inc/search-suggest.php",
		minLength: 2,
		open: function() { $(".ui-widget").css("z-index", 1100) },
		select: function(event, ui){
			$(".search").submit();
		}
	});
	
});


function clock(){
	Digital=new Date();
	hours=Digital.getHours();
	minutes=Digital.getMinutes();
	seconds=Digital.getSeconds();
	
	day=Digital.getDay();
	date=Digital.getDate();
	month=Digital.getMonth();
	year=Digital.getFullYear();
	if(day==0) day="Sunday";
	if(day==1) day="Monday";
	if(day==2) day="Tuesday";
	if(day==3) day="Wednesday";
	if(day==4) day="Thursday";
	if(day==5) day="Friday";
	if(day==6) day="Saturday";
	if(day==7) day="Sunday";
  
	if(month==0) month="January";
	if(month==1) month="Febuary";
	if(month==2) month="March";
	if(month==3) month="April";
	if(month==4) month="May";
	if(month==5) month="June";
	if(month==6) month="July";
	if(month==7) month="August";
	if(month==8) month="September";
	if(month==9) month="October";
	if(month==10) month="November";
	if(month==11) month="December";
	
	if (hours==0) hours='00';
	
	if (minutes<=9) minutes="0"+minutes;
	if (seconds<=9) seconds="0"+seconds;
	
	show = day + " " + date + " " + month + " " + year + "<br />" + hours + ":" + minutes + ":" + seconds;

	$(".clock").html(show);
	setTimeout("clock()",1000);
}

// update bar
var delay =8000; //set delay between message change (in miliseconds)
var maxsteps=30; // number of steps to take to change from start color to endcolor
var stepdelay=40; // time in miliseconds of a single step
//**Note: maxsteps*stepdelay will be total time in miliseconds of fading effect
var startcolor= new Array(0,100,0); // start color (red, green, blue)
var endcolor=new Array(255,255,255); // end color (red, green, blue)

var fcontent=new Array();
fcontent[0]="DD Sleeper and DD Scout Hammock now back in stock!";
fcontent[1]="Hammock karabiners now in stock! In green colour, due to popular demand.";
fcontent[2]="Shipping included in all prices.";
fcontent[3]="All orders dispatched within 24 hours! (Mon-Fri).";
fcontent[4]="We ship to the UK, EU, USA & Canada, please select your country at checkout. Other countries please contact us.";
fcontent[5]="Free T-Shirt (within UK) with orders over &pound;50!";
fcontent[6]="DD Hammocks now has a distributor in Canada!";
fcontent[7]="Limited number of hammock and tarp seconds available";

var DOM2=document.getElementById;
var faderdelay=0;
var index=0;

function changecontent(){
  if (index>=fcontent.length)
    index=0
  if (DOM2){
    document.getElementById("update-bar").style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")"
	document.getElementById("update-bar").innerHTML=fcontent[index]
    colorfade(1, 15);
  }
  index++
}

function linkcolorchange(step){
  var obj=document.getElementById("update-bar").getElementsByTagName("A");
  if (obj.length>0){
    for (i=0;i<obj.length;i++)
      obj[i].style.color=getstepcolor(step);
  }
}

var fadecounter;
function colorfade(step) {
  if(step<=maxsteps) {	
    document.getElementById("update-bar").style.color=getstepcolor(step);
    step++;
    fadecounter=setTimeout("colorfade("+step+")",stepdelay);
  }else{
    clearTimeout(fadecounter);
    document.getElementById("update-bar").style.color="rgb("+endcolor[0]+", "+endcolor[1]+", "+endcolor[2]+")";
    setTimeout("changecontent()", delay);
	
  }   
}

function getstepcolor(step) {
  var diff
  var newcolor=new Array(3);
  for(var i=0;i<3;i++) {
    diff = (startcolor[i]-endcolor[i]);
    if(diff > 0) {
      newcolor[i] = startcolor[i]-(Math.round((diff/maxsteps))*step);
    } else {
      newcolor[i] = startcolor[i]+(Math.round((Math.abs(diff)/maxsteps))*step);
    }
  }
  return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
}

if (window.addEventListener)
window.addEventListener("load", changecontent, false)
else if (window.attachEvent)
window.attachEvent("onload", changecontent)
else if (document.getElementById)
window.onload=changecontent




