$(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
        }
    });

    $("a[rel=gallery]").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'titlePosition': 'over',
        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
        }
    });



   if ($("a.surveyButton").length != 0) {
        $("a.surveyButton").fancybox({
            'width': 800,
            'height': 650,
            'padding': 0,
            'margin': 0,
			'hideOnOverlayClick': false,
            'overlayOpacity': 0.1,
            'overlayColor': '#000000',
            'opacity': true,
            'scrolling': 'auto',
            'autoScale': true,
            'transitionIn': 'none',
            'transitionOut': 'none',
			'enableEscapeButton': false,
            'type': 'iframe'
        });
    }


    if ($("a.linkTipPassword").length != 0) {
        $('a.linkTipPassword').qtip({
            position: {
                corner: {
                    tooltip: 'bottomLeft',
                    target: 'topRight'
                }
            },
            content: 'Get your password emailed to you' // Give it some content, in this case a simple string
            ,
            style: {
                border: {
                    width:  0,
                    radius: 0,
                    color:  "#d3d3d3"
                },
                background: "#d3d3d3",
                padding:    10,
                color:      "#999999",
                textAlign:  'center',
                tip:        true // Give it a speech bubble tip with automatic corner detection
            }
        });
    }


    if ($("a.linkTipEmail").length != 0) {
        $('a.linkTipEmail').qtip({
            position: {
                corner: {
                    tooltip: 'bottomLeft',
                    target: 'topRight'
                }
            },
            content: 'Tell us your name and new email so we can update and get back to you' // Give it some content, in this case a simple string
            ,
            style: {
                border: {
                    width: 0,
                    radius: 0,
                    color: "#d3d3d3"
                },
                background: "#d3d3d3",
                padding: 10,
                color: "#999999",
                textAlign: 'center',
                tip: true // Give it a speech bubble tip with automatic corner detection
            }
        });
    }



});

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);
});

