$(document).ready(function() {
    if (typeof sIFR == "function") {
        sIFR.replaceElement("h2", named({ sFlashSrc: "/Common/Flash/helveticalight.swf", sColor: "#626250", sWmode: "transparent" }));
        sIFR.replaceElement("h4", named({ sFlashSrc: "/Common/Flash/helveticalight.swf", sColor: "#ffffff", sFlashVars: "textalign=center", sWmode: "transparent" }));
        sIFR.replaceElement("h3.caption", named({ sFlashSrc: "/Common/Flash/helveticalight.swf", sColor: "#999999" }));
    };

    $('.rollover').rollover();

    $('.slideShow li').not(':eq(0)').hide();
    $('.slideShowControl #btnSlideBack').click(function() {
        var i = $('.slideShow li').index($('.slideShow li:visible')[0]);
        var h = (i - 1 == -1) ? $('.slideShow li').size() - 1 : i - 1;
        $('.slideShow li:eq(' + i + ')').hide();
        $('.slideShow li:eq(' + h + ')').show();
    });

    $('.slideShowControl #btnSlideNext').click(function() {
        var i = $('.slideShow li').index($('.slideShow li:visible')[0]);
        var j = (i + 1 == $('.slideShow li').size()) ? 0 : i + 1;
        $('.slideShow li:eq(' + i + ')').hide();
        $('.slideShow li:eq(' + j + ')').show();
    });

    //back button functionality
    $('.backbutton').click(function() {
        history.go(-1);
        return false;
    });

    $('._carousel').addClass('carousel');
    $('.carousel a.carouselNav:eq(1)').click(function() {
        $('.carousel div ul').animate({ left: '-140' }, 250, function() { $('.carousel div ul li').slice(0, 1).appendTo($('.carousel div ul')); $('.carousel div ul').css({ left: '0' }) });
    });
    $('.carousel a.carouselNav:eq(0)').click(function() {
        $('.carousel div ul li').slice(-1).prependTo($('.carousel div ul')); $('.carousel div ul').css({ left: '-120px' }).animate({ left: '0' }, 250);
    });


    // select all desired input fields and attach tooltips to them
    $('.agencylogin .formhint').qtip({
        position: {
            corner: {
                tooltip: 'bottomRight',
                target: 'topRight'
            }
        },
        style: {
            padding: 5,
            background: '#959595',
            color: '#fff',
            border: {
                width: 1,
                radius: 5,
                color: '#999'
            },
            tip: true


        }
    });

});

function rotate(c){
    var i = $(c).index($(c+":visible")[0]);
    var j = (i+1 == $(c).size()) ? 0 : i +1;
    if ($.browser.msie && ($.browser.version == 6)) {
        $(c+":eq("+i+")").hide();$(c+":eq("+j+")").show();
    } else {
        $(c+":eq("+i+")").fadeOut(600, function(){$(c+":eq("+j+")").fadeIn();});
    }
}

$(window).load(function() {
    $(".slideShow li, .slideShowControl a").hover(function(){clearInterval(callout_interval);},function(){callout_interval = setInterval("rotate('.slideShow li')",2000);});
    $(".slideShow li").slice(1).hide();
    callout_interval = setInterval("rotate('.slideShow li')",2000);
});
