// wait until document is fully scriptable
$(function () {

    // Cufon styles
    Cufon.replace('h1, p.large, .jquery-slider p.heading', { fontFamily: 'HelveticaNeueLT', hover: true });
    Cufon.replace($("h2").not($(".homepage h2")), { fontFamily: 'HelveticaNeueLT', hover: true });
    Cufon.replace('.nav-primary a, .nav-secondary a, .view-all a, .header ul.nav-primary-sub li a, .portal-sidebar a', { fontFamily: 'HelveticaNeueMDCon', hover: true });

    // Uniform custom dropdowns
    $(function () { $("select").uniform(); });

    // Team profile hovers
    $("[property='team-more-info']").mouseenter(function (event) {
        var self = $(this)
			, target_id = self.attr('href')
			, cnt = $(target_id).html()
			, holder_id = self.attr('rel')
			, holder = $(holder_id);

        if (self.closest('dd.col').hasClass('alt')) {
            holder.addClass('holder-alt');
        }
        else {
            holder.removeClass('holder-alt');
        }
        holder.html(cnt).show();
        $('.arrow', self.closest('dd')).show();
    }).mouseleave(function () {
        var self = $(this)
			, holder_id = self.attr('rel')
			, holder = $(holder_id);

        holder.hide();
        $('.arrow', self.closest('dd')).hide();
    });

    $("[property='team-more-info']").click(function () { return false; });

    // News market-updates slidedown
    $("ul.market-updates li a.country-pane").live('click', function () {
        var li = $(this).parent();
        var dl = $(li).find('dl');
        var ar = $(this);


        if ($(dl).is(':hidden')) {
            $(dl).slideDown(250, function () {
                $(li).addClass("active");
            });
        } else {
            $(dl).slideUp(250, function () {
                $(li).removeClass("active");
            });
        }

        return false;
    });

    // Homepage jQuery slider
    // select #flowplanes and make it scrollable. use circular and navigator plugins
    $("#flowpanes").scrollable({ circular: true, mousewheel: false }).navigator({

        // select #flowtabs to be used as navigator
        navi: "#flowtabs",

        // select A tags inside the navigator to work as items (not direct children)
        naviItem: 'a',

        // assign "current" class name for the active A tag inside navigator
        activeClass: 'current',

        // make browser's back button work
        history: false

    });

    //Daily Market Update Widget Home page
    $(document).ready(function () {
        //Daily Market Update
        $('ul.dmu-countries li a').click(function () {
            $('div.market-updates').find('dl.dmu').each(function () {
                $(this).hide();
            });
            $('ul.dmu-countries li').removeClass('active');
            $(this).parent().addClass('active');
            $($(this).attr('rel')).show();
            return false;
        });
        //Search Results Page (Prev  & NExt Button Text)
        $(".pages .nextprev").each(function () {
            var txt = $(this).html();
            if (txt.length > 8) {
                $(this).html("&laquo;");
            } else {
                $(this).html("&raquo;");
            }
        });
        //Contact us form
        $('.contact-form input,.contact-form textarea').each(
            function () {
                $(this).val($(this).attr("rel"));
            }
        );
        $('.contact-form input,.contact-form textarea ').focus(
        function () {
            if (!$(this).hasClass('no-change')) {
                if ($(this).val() == $(this).attr("rel")) {
                    $(this).val("");
                }
            }
        });
        $('.contact-form input,.contact-form textarea ').blur(
        function () {
            if ($.trim($(this).val()) == "") {
                $(this).val($(this).attr("rel"));
            }
        });
    });
});
