

/* Resize images in testimonial area */
function testimonialResize() {
    /* Set Rules and equations */

    /* Element */
    var img = $('.imageHolder img');
    /* Get the current width */
    var imgWidth = img.width();
    /* Get the current height */
    var imgHeight = img.height();
    /* define a scale */
    var scale = imgHeight / imgWidth;
    /* Set a maxWidth */
    var maxWidth = 150;
    /* Work out the maxHeight */
    var maxHeight = maxWidth * scale;
    /* Work out the marginLeft for the positioning */
    var marginLeft = "-" + maxWidth / 2 + "px";
    /* Provide the img with the properties */
    img.css('width', maxWidth);
    //img.css('height' , maxHeight);
    img.css('margin-left', marginLeft);

    if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1 || navigator.userAgent.toLowerCase().indexOf('safari') > -1) {

        var positionTop = (150 - img.height()) / 5.5 + "px";

        img.css('top', positionTop);

        if (img.height() > 90) {

            var positionTopMore = (150 - img.height()) / 7.5 + "px";

            img.css('top', positionTopMore);
        }
    }
    else {
        var positionTop = (150 - img.height()) / 2.8 + "px";

        img.css('top', positionTop);

        if (img.height() > 90) {

            var positionTopMore = (150 - img.height()) / 7.5 + "px";

            img.css('top', positionTopMore);
        }
    }
}


/* Content Slider Home */
(function ($) {
    $.fn.contentSlider = function (options) {
        var tabs = $(this);
        var output = $(options.output);
        var promo = $(options.promo)

        new jQuery.contentSlider(tabs, output, options, promo);
        return this;
    };

    $.contentSlider = function (tabs, output, options, promo) {
        function slide(nr) {
            if (typeof nr == "undefined") {
                nr = visible_item + 1;
                nr = nr >= total_items ? 0 : nr;
            }
            tabs.removeClass('current').filter(":eq(" + nr + ")").addClass('current');

            output.stop(true, true).filter(":visible").fadeOut("slow");
            promo.stop(true, true).filter(":visible").fadeOut("slow");

            output.filter(":eq(" + nr + ")").fadeIn("slow", function () {
                visible_item = nr;
            });
            promo.filter(":eq(" + nr + ")").fadeIn("slow", function () {
                visible_item = nr;
            });
        }

        var options = options || {};
        var total_items = tabs.length;
        var visible_item = options.start_item || 0;

        options.pause_on_hover = options.pause_on_hover || true;
        options.transition_interval = options.transition_interval || 7000;

        output.hide().eq(visible_item).show();
        promo.hide().eq(visible_item).show();
        tabs.eq(visible_item).addClass('current');

        if (options.transition_interval > 0) {

            var timer = setInterval(function () {
                slide();

            }, options.transition_interval);

            if (options.pause_on_hover) {
                tabs.mouseover(function () {
                    clearInterval(timer);

                    if ($(this).hasClass('current')) {
                        return false;
                    }

                    slide(tabs.index(this));

                }).mouseout(function () {
                    clearInterval(timer);
                    timer = setInterval(function () {
                        slide();
                    }, options.transition_interval);
                });
            }
        }
    };
})(jQuery);
/* Content Slider Home */

/* Testimonial Content Slider */
(function ($) {
    $.fn.internalSlider = function (options) {
        var tabs = $(this);
        var output = $(options.output);
        //var promo = $(options.promo)

        new jQuery.internalSlider(tabs, output, options, promo);
        return this;
    };

    $.internalSlider = function (tabs, output, options, promo) {
        function slide(nr) {
            if (typeof nr == "undefined") {
                nr = visible_item + 1;
                nr = nr >= total_items ? 0 : nr;
            }
            tabs.removeClass('current').filter(":eq(" + nr + ")").addClass('current');

            output.stop(true, true).filter(":visible").fadeOut("slow");
            // promo.stop(true, true).filter(":visible").fadeOut("slow");

            output.filter(":eq(" + nr + ")").fadeIn("slow", function () {
                visible_item = nr;
            });
            //promo.filter(":eq(" + nr + ")").fadeIn("slow", function () {
            //    visible_item = nr;
            // });
        }

        var options = options || {};
        var total_items = tabs.length;
        var visible_item = options.start_item || 0;

        options.pause_on_hover = options.pause_on_hover || true;
        options.transition_interval = options.transition_interval || 7000;

        output.hide().eq(visible_item).show();
        //promo.hide().eq(visible_item).show();
        tabs.eq(visible_item).addClass('current');

        if (options.transition_interval > 0) {

            var timer = setInterval(function () {
                slide();

            }, options.transition_interval);

            if (options.pause_on_hover) {
                tabs.mouseover(function () {
                    clearInterval(timer);

                    if ($(this).hasClass('current')) {
                        return false;
                    }

                    slide(tabs.index(this));

                }).mouseout(function () {
                    clearInterval(timer);
                    timer = setInterval(function () {
                        slide();
                    }, options.transition_interval);
                });
            }
        }
    };
})(jQuery);

// Check availability 
function checkAvail(id) {
    $('html,body').animate({ scrollTop: $("#" + id).offset().top }, 'slow');
}
//Show Hide Top Bit 
function hideShowTop() {
    $('.infoTop').hide();

    $('.topNav ul li a').hover(function () {
        $('.infoTop').show()
    },
	function () {
	    $('.infoTop').hide();
	}
	);
}
/* Testimonial Content Slider */

/* Fire off functions */
$(document).ready(function () {
    //Image Resize
    testimonialResize();

    //Hide top Bit
    hideShowTop();

    //Content Slider
    $('.tabs li').contentSlider({
        output: '.contentSlider li',
        promo: '.promoBanner li',
        start_item: 0
    });

    //Testimonial Slider
    $('.testimonialBox li').contentSlider({
        output: '.testimonialBox li',
        //promo : '.promoBanner li',
        start_item: 0
    });

});
