//Runs all custom jQuery and functions
$(function () {
    $('body').supersleight();

    $(".mouseOver").hover(function () {
        if ($(this).attr("src").indexOf("_ovr") == -1 && !$(this).hasClass('act')) {
            $(this).attr("src", $(this).attr("src").split(".").join("_ovr."));
        }
    }, function () {
        if ($(this).attr("src").indexOf("_ovr") != -1 && !$(this).hasClass('act')) {
            $(this).attr("src", $(this).attr("src").split("_ovr.").join("."));
        }
    });

    $('.cboxImage').colorbox();

    if (window.location.href.indexOf('search.aspx') != -1 && $.query.get("r") != "") {
        var term = $.query.get("r").toString();
        prepareSearch("'" + term + "'");
    }

    $('#btnSearch').click(function () {
        window.location = '/search.aspx?r=' + $('#txtSearch').val();
    });

    $('#txtSearch').keypress(function (e) {
        verlicon(e.keyCode);
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            window.location = '/search.aspx?r=' + $('#txtSearch').val();
            return false;
        }
    });

    var flashvars = { wmode: "opaque" };
    var params = {};
    var attributes = {};
    swfobject.embedSWF("/swf/hefrenT_masterPlan.swf", "masterPlan", "720", "405", "8.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
    swfobject.embedSWF("/swf/hefrenT_401k.swf", "Plan401k", "960", "540", "8.0.0", "/swf/expressInstall.swf");

    swfobject.embedSWF("/swf/banner.swf", "micTuneIn", "626", "266", "8.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);

    //Interior SWF Embeds
    swfobject.embedSWF("/swf/about_us.swf", "about_us", "733", "116", "8.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
    swfobject.embedSWF("/swf/businesses.swf", "businesses", "733", "116", "8.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
    swfobject.embedSWF("/swf/how_help_you.swf", "how_help_you", "733", "116", "8.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
    swfobject.embedSWF("/swf/individual_investors.swf", "individual_investors", "733", "116", "8.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
    swfobject.embedSWF("/swf/institutions.swf", "institutions", "733", "116", "8.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
    swfobject.embedSWF("/swf/investor_resources.swf", "investor_resources", "733", "116", "8.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);

    $('#quoteContainer').cycle({
        timeout: 6000,
        fx: 'fade',
        speed: 700
    });

    //FLOWPLAYER
    $('#thumbnailSections img').click(function () {
        $('#thumbnailSections span img').each(function (i, val) {
            var _this = $(this);
            if ($(_this).attr("src").indexOf("_ovr") != -1) {
                $(_this).attr("src", $(_this).attr("src").split("_ovr.").join("."));
            }
        });

        $(this).attr("src", $(this).attr("src").split(".").join("_ovr."));
        $('#thumbnailSections img').removeClass('act');
        $(this).addClass('act');
    });

//    if ($.cookie('cl') == 'true') {
//        $('#clientLogin a').attr('href', 'https://www2.netxselect.com/home_6KB.htm');
//        $('#clientLogin a').attr('target', '_blank');
//    }

//    if (window.location.href.indexOf('content.aspx?id=55') != -1 && $.cookie('cl') == 'true') {
//        window.location = 'https://www2.netxselect.com/home_6KB.htm';
//    }
});

function setCLCookie(cookieName) {
    //$.cookie(cookieName, 'true', { expires: 730 });
}

function setVideoSource($s, $t) {
    var rtmpFilePrefixStr;

    switch ($s) {
        case "Jim":
            rtmpFilePrefixStr = "JimMeredith2-15-2012";
            break;
        case "Brian":
            rtmpFilePrefixStr = "BrianKoble2-15-2012";
            break;
        case "Rob":
            rtmpFilePrefixStr = "RobRodgers2-15-2012";
            break;
    }

    $("#videoTitle").html($t);

    try {
        var fPlayer = flowplayer("player", "/swf/flowplayer/flowplayer.commercial-3.2.5.swf", { key: '#@96a0c83996c7731a378',
            canvas: {
                // customize player background, i.e. the canvas
                backgroundColor: "#000000",
                backgroundGradient: 'none'
            },
            clip: {

                urlResolvers: 'bwcheck',
                provider: 'rtmp',
                autoPlay: false,
                scaling: 'fit',
                autoplay: true,

                // available bitrates and the corresponding files. We specify also the video width
                // here, so that the player does not use a too large file. It switches to a 
                // file/stream with larger dimensions when going fullscreen if the available bandwidth permits.
                bitrates: [
			 {
			     url: rtmpFilePrefixStr + "_400", width: 646, height: 364, bitrate: 400,
			     // this is the default bitrate, the playback kicks off with this and after that
			     // Quality Of Service monitoring adjusts to the most appropriate bitrate
			     isDefault: true
			 },
			 { url: rtmpFilePrefixStr + "_700", width: 646, height: 364, bitrate: 700 },
			 { url: rtmpFilePrefixStr + "_1000", width: 646, height: 364, bitrate: 1000 },
			 { url: rtmpFilePrefixStr + "_1500", width: 646, height: 364, bitrate: 1500 }
		   ]
            },
            plugins: {

                // bandwidth check plugin
                bwcheck: {
                    url: '/swf/flowplayer/flowplayer.bwcheck-3.2.3.swf',

                    serverType: 'fms',

                    // we use dynamic switching, the appropriate bitrate is switched on the fly
                    dynamic: true,

                    netConnectionUrl: 'rtmp://cf4d20pk2rt.rtmphost.com/hefren/'
                },

                // RTMP streaming plugin
                rtmp: {
                    url: '/swf/flowplayer/flowplayer.rtmp-3.2.3.swf',
                    netConnectionUrl: 'rtmp://cf4d20pk2rt.rtmphost.com/hefren/'
                },

                controls: {
                    // location of the controlbar plugin
                    url: '/swf/flowplayer/flowplayer.controls-3.2.3.swf',
                    opacity: 0.95,

                    height: 30,

                    // styling properties (will be applied to all plugins)
                    backgroundGradient: 'none',
                    background: '#002b45',


                    // controlbar specific settings
                    timeColor: '#ffffff',
                    durationColor: '#96b7d1',
                    sliderColor: '#ffffff',
                    progressColor: '#4da8ff',
                    volumeColor: '#4da8ff',
                    all: false,
                    play: true,
                    volume: true,
                    mute: true,
                    time: true,
                    fullscreen: true,
                    scrubber: true,

                    tooltips: {
                        buttons: false,
                        volume: null,
                        scrubber: null
                    }

                }
            }
        });

        fPlayer.play();
    } catch (e) {

    }
}

function verlicon(data){
//	if (window.console) {
		//Firebug is enabled
	//	console.log(data)
//	}
}
