//Document on ready functions ~njackson
$(document).ready(function() {
    $('ul#print').append('<li><a href="#print" class="print" title="Print this page from Acorn Stairlifts" style=" color: #8E2C45; text-align:center; font-weight:bold; padding: 8px 10px 0px 30px ; background: url(http://resources.acornstairlifts.com/images/icons/set/printer.png) 8px 8px no-repeat #E8DFB5; width: auto; height: 22px; display:block; -moz-border-radius-topleft:10px; -webkit-border-radius-topleft:10px; -moz-border-radius-topright:10px; -webkit-border-radius-topright:10px;">Print this page<\/a><\/li>');
    $('ul#print li a.print').click(function() {
        window.print();
        pageTracker._trackEvent('Buttons', 'Print', window.location.pathname);
        return false;
    });
    
    $("#callback_form_click").click(function(){
        if($("#header-box-form").css("display") != 'none')
        {
            $("#header-box-form").css("display","none");
            $("#header-box-form-callback").css("display","block");
            $(".h3-callback-form").css("visibility","visible");
            $("#call-or-post").html('for info via post');
            pageTracker._trackEvent('FormToggle', window.location.pathname, 'Callback');
            //sIFR.redraw();
        }
        else
        {
            $("#header-box-form").css("display","block");
            $("#header-box-form-callback").css("display","none");
            //sIFR.redraw();
            $("#call-or-post").html('and we\'ll call you');
            pageTracker._trackEvent('FormToggle', window.location.pathname, 'Post');
        }
        return false;
    });

    $("#Who_For_other_div").css("display","none");
    $("#Who_For").change(function(){
        if($("#Who_For :selected").val()=='Other'){
            $("#Who_For_other_div").css("display","block");
        }
        else
        {
            $("#Who_For_other_div").css("display","none");
        }
    });
    
    //Load the slideshow
    theRotator();
    theNumberRotator();
    
    $('li.headlink').hover(
        function() { $('ul', this).css('display', 'block'); },
        function() { $('ul', this).css('display', 'none'); }
    );
    
    $('ul.tabnav').tabs({ fx: { height: 'toggle', opacity: 'toggle' } }); 
});
//Functions ~njackson
function PostcodeLookup()
{
    var postcode = $("#PostcodeZipcode").val();
    
    if(postcode.length > 0)
    {
        var div = $("#divLoading");
        div.css("display","block");
        div.html('<div class="loadinglist">Loading Address List<br /><img src="/images/ajax-loader.gif" height="16" width="16" style="margin:2px auto;"/></div>');
        $.get('/contact_form.php?bdna_action=postcodelookup&postcode='+postcode,function(req){
            div.html(req);
            $("#PostcodeZipcode").removeClass('input-nice-error');
            $("#PostcodeZipcode").addClass('input-nice-correct');
        });
    }
    else
    {
        alert("Please enter a postcode");
        $("#PostcodeZipcode").focus();
        $("#PostcodeZipcode").removeClass('input-nice-correct');
        $("#PostcodeZipcode").addClass('input-nice-error');
    }
}

function populate_address_data()
{
    var addressid = $("#choosy_postcode").val();
    if(addressid != null)
    {
        var div = $("#divLoading");
        div.html('<div class="loadingdetails">Loading Address Details<br /><img src="/images/ajax-loader.gif" height="16" width="16" style="margin:2px auto;"/></div>');
        $.get('/contact_form.php?bdna_action=addressidlookup&addressid='+addressid,function(req){
            div.css('display','none');
            var pieces = req.split('[|]');
            $("#contactaddress").css('display','');
            $("#contacttown").css('display','');
            $("#contactcounty").css('display','');
            $("#postcodeentrytext").css('display','none');
            $("#postcodeentrybutton").css('display','none');
            $("#loadingdiv").css('display','none');
            $("#Street_Address").val(pieces[2]);
            $("#Street_Address_2").val(pieces[3]);
            $("#Street_Address_3").val(pieces[4]);
            $("#Street_Address_4").val(pieces[5]);
            $("#Street_Address_5").val(pieces[6]);
            $("#TownCity").val(pieces[7]);
            $("#County").val(pieces[8]);
            $("#PostcodeZipcode").val(pieces[9]);
        });
    }   
    else alert("Please select an address!");
}

function not_found()
{
    var div = $("#divLoading");
    div.css("display","none");
    $("#contactaddress").css('display','');
    $("#contacttown").css('display','');
    $("#contactcounty").css('display','');
    $("#Street_Address").val('');
    $("#Street_Address_2").val('');
    $("#Street_Address_3").val('');                  
    $("#Street_Address_4").val('');
    $("#Street_Address_5").val('');                   
    $("#TownCity").val('');
    $("#County").val('');
    //$("#PostcodeZipcode").value=pieces[9];
}

function theRotator() {
    //Set the opacity of all images to 0
    $('#rotator ul li').css({opacity: 0.0});
    
    //Get the first image and display it (gets set to full opacity)
    $('#rotator ul li:first').css({opacity: 1.0});
        
    //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
    setInterval('rotate()',6000);
    
}

function rotate() { 
    //Get the first image
    var current = ($('#rotator ul li.show')?  $('#rotator ul li.show') : $('#rotator ul li:first'));

    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#rotator ul li:first') :current.next()) : $('#rotator ul li:first')); 
    
    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({opacity: 0.0})
    .addClass('show')
    .animate({opacity: 1.0}, 1000);

    //Hide the current image
    current.animate({opacity: 0.0}, 1000)
    .removeClass('show');
    
};

function theNumberRotator() {
    //Set the opacity of all images to 0
    $('#numberrotator ul li').css({opacity: 0.0});
    
    //Get the first image and display it (gets set to full opacity)
    $('#numberrotator ul li:first').css({opacity: 1.0});
        
    //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
    setInterval('numberrotate()',6000);
    
}

function numberrotate() {   
    //Get the first image
    var current = ($('#numberrotator ul li.show')?  $('#numberrotator ul li.show') : $('#numberrotator ul li:first'));

    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#numberrotator ul li:first') :current.next()) : $('#numberrotator ul li:first')); 
    
    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({opacity: 0.0})
    .addClass('show')
    .animate({opacity: 1.0}, 1000);

    //Hide the current image
    current.animate({opacity: 0.0}, 1000)
    .removeClass('show');
    
};

 

/*$(document).ready(function(){
  // Reset Font Size
  var originalFontSize = $('html').css('font-size');
    $(".resetFont").click(function(){
    $('html').css('font-size', originalFontSize);
  });
  // Increase Font Size
  $(".increaseFont").click(function(){
    var currentFontSize = $('html').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*1.2;
    $('html').css('font-size', newFontSize);
    return false;
  });
  // Decrease Font Size
  $(".decreaseFont").click(function(){
    var currentFontSize = $('html').css('font-size');
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*0.8;
    $('html').css('font-size', newFontSize);
    return false;
  });
});*/