//set count for headers
var typecount = 1;
var type;
//slideshow
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');
        });
	
	
	
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

//show direct debit option
function directDebit(status){
	if (status == 2){
	document.getElementById("Submit1").style.visibility= "hidden";
	document.getElementById("paydata").style.display = "inline";
	} else {
	document.getElementById("Submit1").style.visibility= "visible";
	document.getElementById("paydata").style.display = "none";
	}
}

//show direct debit option
function checkField(){
	if ((document.getElementById("email").value != "") && (document.getElementById("first_name").value != "") && (document.getElementById("phone").value != "") && (document.getElementById("delivery_address").value != "")){
	document.getElementById("ddebit").submit();
	} else {
	alert("Please ensure that you complete the First Name, Email Address, Phone Number and Delivery Address fields.");
	}
}


var xmlHttp
var displaycart

function addToCart(itemid,showcart,itemdel,itemqty)
{ 

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
 if (showcart == "x"){
	 displaycart = showCartTotals;
 } else {
 	 displaycart = showCart;
 }
var qfield = "qty"+itemqty
var url="includes/utilities_cart.php"
url=url+"?itemid="+itemid
url=url+"&showcart="+showcart
url=url+"&delete="+itemdel
if (itemqty != "x"){
url=url+"&qty="+document.getElementById(qfield).value
} else {
url=url+"x"
}
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=displaycart
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function showCartTotals() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
 	document.getElementById("cart").innerHTML=xmlHttp.responseText;
}
}

function showCart() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
 	document.getElementById("showcart").innerHTML=xmlHttp.responseText;
	cartAdjust("x", "x");
}
}

