/*
CSS Browser Selector v0.3.2
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u) { var ua = u.toLowerCase(), is = function (t) { return ua.indexOf(t) > -1; }, g = 'gecko', w = 'webkit', s = 'safari', h = document.getElementsByTagName('html')[0], b = [(!(/opera|webtv/i.test(ua)) && /msie\s(\d)/.test(ua)) ? ('ie ie' + RegExp.$1) : is('firefox/2') ? g + ' ff2' : is('firefox/3') ? g + ' ff3' : is('gecko/') ? g : /opera(\s|\/)(\d+)/.test(ua) ? 'opera opera' + RegExp.$2 : is('konqueror') ? 'konqueror' : is('chrome') ? w + ' chrome' : is('applewebkit/') ? w + ' ' + s + (/version\/(\d+)/.test(ua) ? ' ' + s + RegExp.$1 : '') : is('mozilla/') ? g : '', is('j2me') ? 'mobile' : is('iphone') ? 'iphone' : is('ipod') ? 'ipod' : is('mac') ? 'mac' : is('darwin') ? 'mac' : is('webtv') ? 'webtv' : is('win') ? 'win' : is('freebsd') ? 'freebsd' : (is('x11') || is('linux')) ? 'linux' : '', 'js']; c = b.join(' '); h.className += ' ' + c; return c; }; css_browser_selector(navigator.userAgent);

// Load required sIFR JS
if (!$.browser.msie) {
    document.write('<script src="/js/sifr.js" type="text/javascript" charset="utf-8"></script>');
    document.write('<script src="/js/sifr-config.js" type="text/javascript" charset="utf-8"></script>');
}

$(function () {
    // Get Stocks
    getStocks();

    // Adds background imaage
    var html = '<div id="background"><div><img src="/img/page-gray-bg.jpg" width="1440" height="2000" alt="Background" /></div></div>'
    $('body').append(html);

    if ($.browser.msie && parseInt(jQuery.browser.version) === 6) {
        $('#background div').remove();
        $('#background').attr('id', 'background-ie6fix');
    }

    // BigTarget	
    if ($('.row .story a').length || $('.advisor a').length) {
        $('.row .story a, .advisor a').bigTarget({
            clickZone: 'div:eq(0)'
        });
    }
    if ($('a.view-bio').length) {
        $('a.view-bio').bigTarget({
            clickZone: 'div.result'
        });
    }
    if (!$.browser.msie && parseInt(jQuery.browser.version) !== 6) {
        if ($('#footer a.more-info').length) {
            $('#footer a.more-info').bigTarget({
                clickZone: 'div:eq(0)'
            });
        }
    }
    // LoopedSlider
    //    if ($('#work-for-us').length) {
    //        $('#work-for-us').loopedSlider({
    //            containerClick: false,
    //            descriptionFade: true
    //        });
    //    }
    if ($('#our-advisors-feature').length) {
        $('#our-advisors-feature').loopedSlider({
            containerClick: false,
            descriptionFade: true
        });
    }
    //QucikSwitch
    if ($('#featured.quickswitch').length) {
        $('#featured.quickswitch').quickSwitch();
    }
    // FancyZoom
    if ($('.watch-video').length) {
        $('.watch-video').fancyZoom();
    }
    // Videofy
    if ($('.featured-video').length) {
        $('.featured-video').videofy();
    }
    if ($('.column .product').length) {
        $('.column').each(function () {
            $('.product:last', this).css({ borderBottom: 'none' })
        });
    };
    // Get Quote
    $('#stock-ticker .go').facebox();
    $('#stock-quote').keypress(function (e) {
        if (e.which == 13 || e.which == 10) {
            $('.go').trigger('click');
            return false;
        }
    });

    // External Links
    $('a[rel="external"]').attr('title', 'By clicking here, you will be leaving UmpquaInvestments.com');

    $('a[rel="external"]').tooltip({
        track: true,
        delay: 0,
        showURL: false,
        showBody: " - ",
        extraClass: "tooltip",
        fixPNG: true,
        left: -25,
        top: -70
    });


    $('a[rel="external"]').click(function () {
        window.open($(this).attr('href'));
        return false;
    });
});
function getStocks() {
    var descList = new Array();
    var itemList = "";
    var content = "";
    $.getJSON('http://pipes.yahoo.com/pipes/pipe.run?_id=e965ef5419c799537575e8c4fd6d7428&_render=json&_callback=?&ticker=%5EDJI%2C%5EGSPC%2C%5EIXIC%2C%5ERUT%2CGLD%2CUMPQ%2C',
		function (json) {
		    if (json.count > 0) {
		        content = output_feed_items(json);
		    } else {
		        content = "The request did not return results.";
		    }
		    $("#stock-ticker #stocks").html(content);
		    if ($('#stocks ul li').length) {
		        $("#stocks ul li:first").addClass('first');
		        $("#stocks ul li span:contains('-')").parent().addClass('down');
		        $("#stocks ul li span:contains('+')").parent().addClass('up');
		        $('li span strong:contains(^GSPC)').html('S&P 500');
		        $('li span strong:contains(^IXIC)').html('NASDAQ');
		        $('li span strong:contains(^RUT)').html('RUSSELL 2000');
		        $('li span strong:contains(GLD)').html('Gold');
		        $('li span strong:contains(^DJI)').html('DOW');
		        $('li span strong:contains(UMPQ)').html('Umpqua Holdings Corp');
		    };
		}
	);
    function output_feed_items(json) {
        for (i = 0; i < json.count; i++) {
            itemList += make_feed_item(json.value.items[i]);
        }
        return '<ul>' + itemList + '</ul>';
    }
    function make_feed_item(item) {
        return '<li><span>' + '<strong>' + item.title + '</strong> ' + item.description + '</span></li>';
    }
};

/* Find Advisor */
$(document).ready(function () {
    $("#advisorsubmit").click(function (event) {
        var name = 'all-advisors'
        if ($("#by_name").val() != '') {
            name = $("#by_name").val();
        }
        window.location = "/advisors/" + $("#by_location").val().toLowerCase() + "/" + name.toLowerCase();
    });

    $('#by_name').keypress(function (e) {
        if (e.which == 13 || e.which == 10) {
            $('#advisorsubmit').trigger('click');
            return false;
        }
    });

});


