//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();
		try{_gaq.push(['_trackEvent', 'Buttons', 'Print', window.location.pathname]);}
		catch(err){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 mail');
			try{_gaq.push(['_trackEvent', 'FormToggle', window.location.pathname, 'Callback']);}
			catch(err){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');
			try{_gaq.push(['_trackEvent', 'FormToggle', window.location.pathname, 'Mail']);}
			catch(err){pageTracker._trackEvent('FormToggle', window.location.pathname, 'Mail');}
        }
        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");
        }
    });
    
    $("#Source_other_div").css("display","none");
    $("#Source").change(function(){
        if($("#Source :selected").val()=='Other'){
            $("#Source_other_div").css("display","block");
        }
        else
        {
            $("#Source_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'); }
    ); 
    
    // Load the sidebar form!
    $("#sidebarform_container").load('/us/includes/sidebar-form.ajax.php');

    
    
});


//-------------------------------------------------------------------------------------------------------
// ClearTypeFadeTo / ClearTypeFadeIn / ClearTypeFadeOut
//
// Custom fade in and fade out functions for jQuery that will work around
// IE's bug with bold text in elements that have opacity filters set when
// also using Window's ClearType text rendering.
//
// New Parameter:
// bgColor    The color to set the background if none specified in the CSS (default is '#fff')
//
// Examples:
// $('div').ClearTypeFadeIn({ speed: 1500 });
// $('div').ClearTypeFadeIn({ speed: 1500, bgColor: '#ff6666', callback: myCallback });
// $('div').ClearTypeFadeOut({ speed: 1500, callback: function() { alert('Fade Out complete') } });
//
// Notes on the interaction of ClearType with DXTransforms in IE7
// http://blogs.msdn.com/ie/archive/2006/08/31/730887.aspx
/*
(function($) {
    $.fn.ClearTypeFadeTo = function(options) {
        if (options)
                $(this)
                        .show()
                        .each(function() {
                                if (jQuery.browser.msie) {
                                        // Save the original background color
                                        $(this).attr('oBgColor', $(this).css('background-color'));
                                        // Set the bgColor so that bold text renders correctly (bug with IE/ClearType/bold text)
                                        $(this).css({ 'background-color': (options.bgColor ? options.bgColor : '#fff') })
                                }
                        })
                        .fadeTo(options.speed, options.opacity, function() {
                                if (jQuery.browser.msie) {
                                        // ClearType can only be turned back on if this is a full fade in or
                                        // fade out. Partial opacity will still have the problem because the
                                        // filter style must remain. So, in the latter case, we will leave the
                                        // background color and 'filter' style in place.
                                        if (options.opacity == 0 || options.opacity == 1) {
                                                // Reset the background color if we saved it previously
                                                $(this).css({ 'background-color': $(this).attr('oBgColor') }).removeAttr('oBgColor');
                                                // Remove the 'filter' style to restore ClearType functionality.
                                                $(this).get(0).style.removeAttribute('filter');
                                        }
                                }
                                if (options.callback != undefined) options.callback();
                        });
    };

    $.fn.ClearTypeFadeIn = function(options) {
        if (options)
                $(this)
                        .css({ opacity: 0 })
                        .ClearTypeFadeTo({ speed: options.speed, opacity: 1, callback: options.callback });
    };

    $.fn.ClearTypeFadeOut = function(options) {
        if (options)
                $(this)
                        .css({ opacity: 1 })
                        .ClearTypeFadeTo({ speed: options.speed, opacity: 0, callback: options.callback });
    };
})(jQuery);
*/


//Functions ~njackson
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, 4000 = change to next image after 6 seconds
    setInterval('rotate()',4000);
    
}

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')); 
     
    //next.ClearTypeFadeIn({ speed: 1000 });
    next.css({opacity: 0.0}).removeClass('hide').addClass('show').animate({opacity: 1.0}, 1000);

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

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()',4000);
    
}

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})
	.removeClass('hide')
    .addClass('show')
    .animate({opacity: 1.0}, 1000);

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


