jQuery(document).ready(function($) {
slider_init(6000);
$("span.requestSamplebox a").each(function() {;
var p = $(this).attr('href');
if (typeof(p) != "undefined") {
var p = p.replace("request-sample.php", "jsrequestsample.php");
$(this).attr('href',p);
}
});

$("a.requestSample").fancybox({
type: 'iframe',
width: 560,
height: 300
});
$("form#reqSample").submit(function(e) {
e.preventDefault();
__formid = this;
theform = form;
theform.formid = __formid;
theform.toupdate = $("#responseHolder");
theform.sendData();
});
});

/* message to developers - I have a version of this done in several named functions for the repeated pieces of code,
But for a reason that I cannot fathom it ruins the effect - in particular the caption dropping down is not done immediately after
the images slide, unless the callback of the slide is an anonymous function declared as it happens. Anyone who wants the nicer
coded version to use (and/or work out what the hell the problem is) can email info@galloway-web-services.com */

function slider_init(speed) {
$('#slider ul li .caption').animate({
height: '47px'
},{
duration:500,
queue:false
});
$('#slider ul li .caption').find('p').show('fast')
setTimeout(function() {
$('#slider ul li .caption').find('p').hide('fast',function() { 
$('.caption').animate({
height: '0px'
},{
duration:500,
queue:false
})
});
},5000)
var timer = setInterval('run_slider()',speed);

}

function run_slider() {
var elm = $('#slider ul li');
ct = elm.length-1;
ct = ct*-920;
var x = $(elm).css('left');
x = parseInt(x);
if (x == ct) {
$(elm).animate({
  left: '0px'
 },500, function() { 
	$('.caption').animate({
	height: '47px'
	},500,function() {
	$('#slider ul li .caption').find('p').show('fast')
	});
	})
setTimeout(function() {
$('#slider ul li .caption').find('p').hide('fast',function() { 
$('.caption').animate({
height: '0px'
},{
duration:500,
queue:false})
});
},5000);
  }
 else {
$(elm).animate({
	left: '-=920px'
	},{
duration:500,
queue:false,
complete:function() { 
	$('.caption').animate({
	height: '47px'
	},{
duration:500,
complete:function() { 
	$('#slider ul li .caption').find('p').show('fast');
	}});
	}});
	setTimeout(function() {
	$('#slider ul li .caption').find('p').hide('fast',function() { 
$('.caption').animate({
height: '0px'
},{
duration:500,
queue:false
})
});
},5000);
}
}
