﻿jQuery.noConflict();
jQuery(document).ready(function() {

    // When page loads, prepend the search image to beginning of span. This is due to floating both elements right
    jQuery('span#dnn_sharedHeader1_dnnSEARCH_ClassicSearch').prepend(jQuery('a#dnn_sharedHeader1_dnnSEARCH_cmdSearch'));

    // Click event to search button that slides out the search input field
    jQuery('a#dnn_sharedHeader1_dnnSEARCH_cmdSearch').click(function(event) {
        //Get the current text input value. Check if the input is empty or not.
        var inputValue = jQuery('input#dnn_sharedHeader1_dnnSEARCH_txtSearch').val();
        if (inputValue == '') {
            event.preventDefault();
            //If the text input is hidden, then animate.
            if (jQuery('input#dnn_sharedHeader1_dnnSEARCH_txtSearch').css('display') == 'none') {
                animateSearch(event);
            }
        } else {
            if (jQuery('input#dnn_sharedHeader1_dnnSEARCH_txtSearch').css('display') == 'none') {
                event.preventDefault();
                animateSearch(event);
            }
        }
    });
    // animate function for the search bar
    function animateSearch(event) {
        event.preventDefault();
        jQuery('input#dnn_sharedHeader1_dnnSEARCH_txtSearch').animate({
            opacity: 1,
            'padding-right': '25px',
            'padding-left': '5px',
            width: '140px'
        }, 'fast', function() {
            jQuery('div#header-links div.exit-btn').fadeIn();
        }).show();
    }

    // When the exit button is clicked, animate the search bar back to 0
    jQuery('div#header-links div.exit-btn').click(function() {
        jQuery(this).fadeOut();
        jQuery('input#dnn_sharedHeader1_dnnSEARCH_txtSearch').animate({
            'width': '0px',
            'padding-right': '0',
            'padding-left': '0',
            opacity: 0
        }, 'fast', function() {
            jQuery('input#dnn_sharedHeader1_dnnSEARCH_txtSearch').hide();
        });
    });

    // Add click event to buttons to show the replybox
    jQuery('div#topic-view div.add-reply a, div#topic-view a.af-reply').click(function(event) {
        showReplyBox(event);
    });

    // Change the select box contents on the topiceditor template
    jQuery.each(jQuery('select#dnn_ctr1387_ActiveForums_ctl00_post_ctlForm_aftopicstatus_drpStatus option'), function() {
        if (jQuery(this).attr('value') == '0') {
            jQuery(this).text('Staff Pick');
        } else if (jQuery(this).attr('value') == '1' || jQuery(this).attr('value') == '3') {
            jQuery(this).css('display', 'none');
        }
    });

    // User single topic, move status to correct position
    jQuery.each(jQuery('ul#forumUserStatus li'), function() {
        var tempStatus = jQuery('div.forumUserStatus', this).text();
        var tempUserId = jQuery('div.forumUserID', this).text();
        jQuery('.user-status:contains(' + tempUserId + ')').text(tempStatus);
    });

    // Convert the date to ex: June 13, 2011 for all member-info in topic view
    jQuery.each(jQuery('div#topic-view div.member-info li.join-date span.date'), function() {
        var joinDate = jQuery(this).text();
        jQuery(this).html(joinDate.substr(3, 8));
    });

    // Toggle the reply box slide up and down
    function showReplyBox(event) {
        event.preventDefault();
        // When the button is clicked, move the user's screen to the reply box.
        goToByScroll('div#topic-view div#reply-box');
        if (jQuery('div#topic-view div#reply-box div.amimagebutton').is(":visible")) {
            jQuery('div#topic-view div#reply-box div.amimagebutton').fadeOut();
        }
        jQuery('div#topic-view div#reply-box').slideToggle('slow', function() {
            // If the reply box is visible, then fadeIn the reply button at the end.
            if (jQuery('div#topic-view div#reply-box').is(":visible")) {
                jQuery('div#topic-view div#reply-box div.amimagebutton').fadeIn();
            }
        });
    }

    /*
    * Event Ticker Carousel
    */
    if (jQuery('div#event-ticker ul.jcarousel')[0]) {
        jQuery('div#event-ticker ul.jcarousel').jcarousel({
            auto: 2,
            wrap: 'circular',
            scroll: 1,
            controls_container_id: 'div#event-ticker-controls'
        });
    }

    /*
    * Event Featured Carousel
    */
    if (jQuery('div#featured-events ul.jcarousel')[0]) {
        jQuery('div#featured-events ul.jcarousel').jcarousel({
            auto: 0,
            wrap: 0,
            scroll: 1,
            controls_container_id: 'div#event-featured-controls'
        });
    }

    /*
    * Photo Slider Carousel
    */
    if (jQuery('div#photo-slider-wrapper ol#photo-slider')[0]) {
        jQuery('div#photo-slider-wrapper ol#photo-slider').jcarousel({
            auto: 0,
            wrap: 0,
            scroll: 1,
            controls_container_id: 'div#photo-slider-wrapper div#photo-slider-controls'
        });
    }

    function goToByScroll(selector) {
        //if (jQuery('div.belted').length > 0) {
            jQuery('html,body').animate({ scrollTop: jQuery(selector).offset().top }, 'slow');
        //}
    }

    // Toggler
    jQuery("div.toggle").hide();
    jQuery("h4.toggler").click(function() {
        jQuery(this).next("div.toggle").slideToggle("fast");
    });

    // Add links to social media on profile
    jQuery("#bio-social li:not(:empty)").wrapInner(function() {
        return '<a href="' + jQuery(this).text() + '"></a>';
    });

    // Add comma and space where needed    
    if (jQuery("span.comma").text().length) {
        jQuery("span.comma").append(', ');
        jQuery("span.comma").show();
    }

    jQuery("div#container div.profile div#dnn_ContentPane div.DnnModule-XModPro").remove().appendTo('div.biometa');
    jQuery("div#container div.profile div#dnn_ContentPane div.biometa dl").show();
    jQuery("div#container div.profile div#dnn_ContentPane div.DnnModule-XModPro").show();


    /*jQuery("div#content div.belted").show();*/
    jQuery("div#dnn_FinderPane").show();
    jQuery("div#dnn_FinderPane div.box").show();


    // Set height/expand for bio in profile
    jQuery("div.bio-entry").show();

    jQuery("div.bio-entry .more-less").condense({
        moreSpeed: 'slow',
        lessSpeed: 'slow',
        moreText: '&raquo; Read More',
        lessText: '&raquo; Read Less',
        ellipsis: "...",
        condensedLength: 700
    });

    // Trim blog posts on Profile
    jQuery('li.buzz-blog blockquote').condense({
        moreSpeed: 'fast',
        lessSpeed: 'slow',
        ellipsis: "<span class='more'>...</span>"
    });
    jQuery('li.buzz-blog blockquote br').remove();
    if (jQuery('li.buzz-blog blockquote p')) {
        jQuery('li.buzz-blog blockquote span.more').prev().append('...');
        jQuery('li.buzz-blog blockquote span.more').remove();

        jQuery('li.buzz-blog blockquote p').each(function() {
            var $this = jQuery(this);
            if ($this.html().replace(/\s|&nbsp;/g, '').length == 0)
                $this.remove();
        });
    }


    // Home page "Latest News"
    jQuery('.widget-slider').cycle({
        fx: 'fade',
        speed: 'slow',
        timeout: 10000,
        pause: 1,
        next: '#next',
        prev: '#prev'
    });


    // Clean up dates from 07-11-2011 to July 11, 2011
    jQuery(".post-date").each(function() {
        jQuery(this).text(jQuery(this).text().replace(/ AM/, "am"));
        jQuery(this).text(jQuery(this).text().replace(/ PM/, "pm"));
        jQuery(this).text(jQuery(this).text().replace(/-/, " "));
        jQuery(this).text(jQuery(this).text().replace(/01 /, "January "));
        jQuery(this).text(jQuery(this).text().replace(/02 /, "February "));
        jQuery(this).text(jQuery(this).text().replace(/03 /, "March "));
        jQuery(this).text(jQuery(this).text().replace(/04 /, "April "));
        jQuery(this).text(jQuery(this).text().replace(/05 /, "May "));
        jQuery(this).text(jQuery(this).text().replace(/06 /, "August "));
        jQuery(this).text(jQuery(this).text().replace(/07 /, "July "));
        jQuery(this).text(jQuery(this).text().replace(/08 /, "August "));
        jQuery(this).text(jQuery(this).text().replace(/09 /, "September "));
        jQuery(this).text(jQuery(this).text().replace(/10 /, "October "));
        jQuery(this).text(jQuery(this).text().replace(/11 /, "November "));
        jQuery(this).text(jQuery(this).text().replace(/12 /, "December "));
        jQuery(this).text(jQuery(this).text().replace(/20November/, "2011"));
        jQuery(this).text(jQuery(this).text().replace(/20December/, "2012"));
        jQuery(this).text(jQuery(this).text().replace(/-/, ", "));
    });

    // Profile Photos
    jQuery('#myphotos').cycle({
        fx: 'fade',
        speed: 'slow',
        timeout: 0,
        pager: '#myphotosnav',
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
            return '#myphotosnav li:eq(' + (idx) + ') a';
        }
    });

    //File Preview functionality to show the image next to upload button
    if (jQuery('div.share-trade-form li.file span.file-upload span').text().length > 0) {
        var imagePreviewSrc = jQuery('div.share-trade-form li.file span.file-upload span').text();
        jQuery('div.share-trade-form div.file-preview img').attr('src', '/Portals/3/trades/' + imagePreviewSrc);
        jQuery('div.share-trade-form div.file-preview').fadeIn('slow');
    }

    //Add classes to radio labels for the short term and long term buttons
    jQuery('div.share-trade-form li.term-box span.trend:first label').addClass('short-term down');
    jQuery('div.share-trade-form li.term-box span.trend:first label:first').removeClass().addClass('short-term up');
    jQuery('div.share-trade-form li.term-box span.trend:first label:last').removeClass().addClass('short-term sideways');
    jQuery('div.share-trade-form li.term-box span.trend:last label').addClass('short-term down');
    jQuery('div.share-trade-form li.term-box span.trend:last label:first').removeClass().addClass('long-term up');
    jQuery('div.share-trade-form li.term-box span.trend:last label:last').removeClass().addClass('long-term sideways');

    //When radio button changes, change active class on that label
    jQuery('#dnn_ctr1393_XMPFormView_ctl00_ctl00_ctl00_short_term_trend_0').change(function() {
        jQuery('div.share-trade-form li.term-box span.trend:first label').removeClass('active');
        jQuery('div.share-trade-form li.term-box span.trend:first label:first').addClass('active');
    });
    jQuery('#dnn_ctr1393_XMPFormView_ctl00_ctl00_ctl00_short_term_trend_1').change(function() {
        jQuery('div.share-trade-form li.term-box span.trend:first label').addClass('active');
        jQuery('div.share-trade-form li.term-box span.trend:first label:first').removeClass('active');
        jQuery('div.share-trade-form li.term-box span.trend:first label:last').removeClass('active');
    });
    jQuery('#dnn_ctr1393_XMPFormView_ctl00_ctl00_ctl00_short_term_trend_2').change(function() {
        jQuery('div.share-trade-form li.term-box span.trend:first label').removeClass('active');
        jQuery('div.share-trade-form li.term-box span.trend:first label:last').addClass('active');
    });
    jQuery('#dnn_ctr1393_XMPFormView_ctl00_ctl00_ctl00_long_term_trend_0').change(function() {
        jQuery('div.share-trade-form li.term-box span.trend:last label').removeClass('active');
        jQuery('div.share-trade-form li.term-box span.trend:last label:first').addClass('active');
    });
    jQuery('#dnn_ctr1393_XMPFormView_ctl00_ctl00_ctl00_long_term_trend_1').change(function() {
        jQuery('div.share-trade-form li.term-box span.trend:last label').addClass('active');
        jQuery('div.share-trade-form li.term-box span.trend:last label:first').removeClass('active');
        jQuery('div.share-trade-form li.term-box span.trend:last label:last').removeClass('active');
    });
    jQuery('#dnn_ctr1393_XMPFormView_ctl00_ctl00_ctl00_long_term_trend_2').change(function() {
        jQuery('div.share-trade-form li.term-box span.trend:last label').removeClass('active');
        jQuery('div.share-trade-form li.term-box span.trend:last label:last').addClass('active');
    });

    //When page loads, check if any radio buttons are selected and add active class to that label 
    if (jQuery('#dnn_ctr1393_XMPFormView_ctl00_ctl00_ctl00_short_term_trend_0').is(':checked')) {
        jQuery('div.share-trade-form li.term-box span.trend:first label:first').addClass('active');
    }
    if (jQuery('#dnn_ctr1393_XMPFormView_ctl00_ctl00_ctl00_short_term_trend_1').is(':checked')) {
        jQuery('div.share-trade-form li.term-box span.trend:first label:last').addClass('active');
    }
    if (jQuery('#dnn_ctr1393_XMPFormView_ctl00_ctl00_ctl00_long_term_trend_0').is(':checked')) {
        jQuery('div.share-trade-form li.term-box span.trend:last label:first').addClass('active');
    }
    if (jQuery('#dnn_ctr1393_XMPFormView_ctl00_ctl00_ctl00_long_term_trend_1').is(':checked')) {
        jQuery('div.share-trade-form li.term-box span.trend:last label:last').addClass('active');
    }

    //Show advanced trade form section when user clicks on link
    jQuery('div.share-trade-form div.grouping.advanced h2 a').click(function() {
        // Set a class to the advanced link to show arrow
        jQuery(this).toggleClass('show');

        //Toggle divs to slide up and down.
        jQuery('div.share-trade-form div.grouping.advanced div.toggle-wrapper').slideToggle('slow');
    });

    // add in rating buttons if the user has not rated the trade yet
    if (jQuery('div.wide-left ul.trade-rating li.submit')) {
        jQuery('div.wide-left ul.trade-rating li.submit.btn-thumbs-down').prepend(jQuery('div.DnnModule-1421'));
        jQuery('div.wide-left ul.trade-rating li.submit.btn-thumbs-up').prepend(jQuery('div.DnnModule-1422'));
    }

    //Checks the if the admin is logged in, remove the first div for the rating modules. 
    if (jQuery('div#dnn_ctr1422_ModuleContent div:first-child').attr('style') == "border: 1px solid black; background-color: rgb(238, 238, 238); padding: 8px; margin: 4px; width: 95%;") {
        jQuery('div#dnn_ctr1422_ModuleContent div:first-child, div#dnn_ctr1421_ModuleContent div:first-child').remove();
    }

    //Leave a comment button, once clicked it slides to the form below
    jQuery('a.leave-a-comment').click(function() {
        goToByScroll('div.trade-comments-form');
    });
    /*
    //Check Single Trade page image/video section. If file extension is video, then hide image tag and show video and vise versa
    if (jQuery('div.stock-image img').attr('src')) {
    //Create 2 arrays with the file types I am testing for
    var imageTypes = [".gif", ".jpg", ".png"];
    var videoTypes = [".mp4", ".avi", ".mov", "mpeg"];

        //Get the file type from the source.
    var filename = jQuery('div.stock-image img').attr('src');
    var extensionIndex = filename.lastIndexOf('.');
    var extension = filename.substr(extensionIndex);

        //check if the extension matches any of the values in my arrays. 
    if (jQuery.inArray(extension, imageTypes) >= "0") {
    jQuery('div.stock-image div.video-container').remove();
    } else if (jQuery.inArray(extension, videoTypes) >= "0") {
    jQuery('div.stock-image img').remove();
    } else {
    jQuery('div.stock-image').remove();
    }
    }
    */
    //Event Locator - Show the zip code input depending on the country
    jQuery('div.event-locator-form select').change(function() {
        // Create array of the countries to check for.
        var countries = ["United States", "Canada"];
        //Get the selected country when the user chooses an option from the drop down.
        var selectedCountry = jQuery("div.event-locator-form select option:selected").val();
        //Checks if the selected country is in the countries array, if it is fadeIn the zip code input, else fade it out.
        if (jQuery.inArray(selectedCountry, countries) >= "0") {
            jQuery('div.event-locator-form table td.zipcode').fadeIn();
        } else {
            jQuery('div.event-locator-form table td.zipcode').fadeOut();
            jQuery('div.event-locator-form table td.zipcode input').val('');
        }

    });

    //Follow Functionality: When follow button is clicked, replace with greyed out 'Following' link.
    jQuery('input.follow').click(function() {
        //Set a short delay for the ajax to finish, then fade out button and fade in the 'Following' link
        jQuery(this).fadeOut('slow', function() {
            jQuery(this).next().fadeIn();
            jQuery('div.forum-follow').show();
        });
    });

    //Append the follow button on the profile page to the bio section.
    jQuery('div#amsocial ul.actions-friend').append("<li class='follow'></li>");
    jQuery('div#amsocial ul.actions-friend li.follow').append(jQuery('div.profile-follow-user').parent('div'));

    //Append the follow button on the single blog page to the top near the title. Blog Follow
    if (jQuery('div#page div.blog div#divAddComments').length > 0) {
        jQuery('div.blog-follow').parent('div').addClass('blog-follow-wrapper');
        jQuery('div.blog-follow').show();
        jQuery('div.post p.postmetadata').prepend(jQuery('div.blog-follow-wrapper'));
    }

    //Append the follow button on the single forum post to the title area.
    if (jQuery('div#topic-view div.aftitlelg').length > 0) {
        jQuery('div.forum-follow').parent('div').addClass('forum-follow-wrapper');
        jQuery('div#topic-view div.aftitlelg').append(jQuery('div.forum-follow-wrapper'));
        jQuery('div.forum-follow').show();
        jQuery('div.forum-follow-wrapper').show();
    }


    //MyFollowers block. This controls the fading in and out of the following/followers
    jQuery('div#dnn_FollowerPane h4 a.following').click(function() {
        jQuery('div#dnn_FollowerPane h4 a.followers').removeClass('current');
        jQuery(this).addClass('current');

        if (jQuery('div#dnn_FollowerPane ul.followers li.follower').length) {
            jQuery('div#dnn_FollowerPane ul.followers li.follower').fadeOut(function() {
                jQuery('div#dnn_FollowerPane ul.followers li.following').fadeIn();
            });
        } else {
            jQuery('div#dnn_FollowerPane ul.followers li.following').fadeIn();
        }
    });
    jQuery('div#dnn_FollowerPane h4 a.followers').click(function() {
        jQuery('div#dnn_FollowerPane h4 a.following').removeClass('current');
        jQuery(this).addClass('current');

        if (jQuery('div#dnn_FollowerPane ul.followers li.following').length) {
            jQuery('div#dnn_FollowerPane ul.followers li.following').fadeOut(function() {
                jQuery('div#dnn_FollowerPane ul.followers li.follower').fadeIn();
            });
        } else {
            jQuery('div#dnn_FollowerPane ul.followers li.follower').fadeIn();
        }


    });

    //Filters on trades list view with change events
    jQuery('div.tradeslist div.trade-filters select#asset-class-filter').change(function() {
        var value = jQuery('div.tradeslist div.trade-filters select#asset-class-filter option:selected').text();
        location.href = '/TraderExchange/Trades.aspx?ac=' + value;
    });
    jQuery('div.tradeslist div.trade-filters select#exchange-filter').change(function() {
        var value = jQuery('div.tradeslist div.trade-filters select#exchange-filter option:selected').text();
        location.href = '/TraderExchange/Trades.aspx?exchange=' + value;
    });

    //Alphabetical navigation on glossary
    jQuery('#alpha').listnav({
        showCounts: false
    });

    //Add colorbox popup to all links
    jQuery('a.colorbox').colorbox({});
    //Add colorbox popup to screencast links
    if (jQuery('a.screencast').length) {
        jQuery('a.screencast').colorbox({ iframe: true, innerWidth: 600, innerHeight: 400 });
    }
    //Move the badgesList to the appropriate spot(s)
    jQuery('#badges-list-wrapper').remove().insertAfter('#badges-wrapper').show();

    //Check if the url is on the trader exchange and scroll down to the belted section
    if (document.location.href.indexOf("TraderExchange/") > 0 && document.location.href.indexOf("/pg/") == -1  && document.location.href.indexOf("TraderExchange/Share") == -1) {
        goToByScroll("div.belted");
    }

    //Registration form: Step 1
    //If user selects certain dropdown option, then show the zip code input.
    if (jQuery("select.DynamicRegistration_Country").length > 0) {

        // Create array of the countries to check for.
        var countries = ["United States", "Canada", "India"];
        //Get the selected country when the user chooses an option from the drop down.
        var selectedCountry = jQuery("select.DynamicRegistration_Country option:selected").val();
        //Checks if the selected country is in the countries array, if it is fadeIn the zip code input, else fade it out.
        if (jQuery.inArray(selectedCountry, countries) >= "0") {
            jQuery('input#dnn_ctr1358_DynamicRegistration_TBR_GUID0dc2965b-92e4-44d4-a51a-9ec02d58a538ZipCode').parent("td").fadeIn();
            jQuery('input#dnn_ctr1358_DynamicRegistration_TBR_GUID0dc2965b-92e4-44d4-a51a-9ec02d58a538ZipCode').val('');
        } else {
            jQuery('input#dnn_ctr1358_DynamicRegistration_TBR_GUID0dc2965b-92e4-44d4-a51a-9ec02d58a538ZipCode').parent("td").fadeOut();
            jQuery('input#dnn_ctr1358_DynamicRegistration_TBR_GUID0dc2965b-92e4-44d4-a51a-9ec02d58a538ZipCode').val('N/A');
        }

    }

    //Registration form: Step 2
    jQuery('#dnn_ctr1360_ContentPane tr#dnn_ctr1360_DynamicRegistration_a8cc058f-0693-4b7f-9b65-3f2f31029bd8 td:not(:first) table.DynamicRegistration_QuestionTable').each(function(i) {
        if (i == 0) {
            jQuery(this).addClass('columnFirstOption');
        }
        jQuery(this).remove().appendTo('tr#dnn_ctr1360_DynamicRegistration_a8cc058f-0693-4b7f-9b65-3f2f31029bd8 td:first');
    });
    jQuery('#dnn_ctr1360_ContentPane tr#dnn_ctr1360_DynamicRegistration_79952b6a-6466-4c48-a88a-19d206fdb5c4 td:not(:first) table.DynamicRegistration_QuestionTable').each(function(i) {
        if (i == 0) {
            jQuery(this).addClass('columnFirstOption');
        }
        jQuery(this).remove().appendTo('tr#dnn_ctr1360_DynamicRegistration_79952b6a-6466-4c48-a88a-19d206fdb5c4 td:first');
    });

    //Push title, description, keywords into trades iframe also handle switching between options
    if ((jQuery('.screenshot ul li.file .file-upload input[type=file]').length > 0) || (jQuery('.screenshot .file-preview').is(':visible'))) {
        //User has indicated they want to attach a screenshot and have clicked to upload a file
        jQuery('.screenshot ul li.file').show();
        jQuery("#tradeUploaderChooser").hide();
    }
    jQuery('#tradeUploaderChooser a#pickedSS').click(function() {
        jQuery('.screenshot ul li.video').hide();
        jQuery('.screenshot ul li.file').show();
        jQuery("#tradeUploaderChooser").hide();
    });
    jQuery('td#dnn_ctr1306_Login_tdRegister').hide(); jQuery('a#pickedV').click(function() {
        jQuery('.screenshot ul li.video').show();
        jQuery('.screenshot ul li.file').hide();
        jQuery("#tradeUploaderChooser").hide();
    });

    //Remove 4 of the 5 stars from Forum Rating Stars
    jQuery('div.forumslist div#topic-view ul#af-rater li:not(:first-child)').hide();

    //Forum Rating Checker
    if (jQuery('div.exchange span#forumStarRatingDetails')) {
        //If they are logged in, and they have not voted
        if (jQuery('div.exchange span#forumStarRatingDetails').hasClass('forum-rating-logged-in need-rating') == true) {
            //add the class no-rating to the ul to make it empty
            jQuery('div.forumslist div#topic-view ul#af-rater').addClass('no-rating');
            //When the user mousesout of the li AND the span does not have 'clicked' then set it to no-rating
            jQuery('div.forumslist div#topic-view ul#af-rater li:first-child').mouseout(function() {
                if (jQuery('div.exchange span#forumStarRatingDetails').hasClass('clicked') == false) {
                    jQuery(this).parent().addClass('no-rating');
                }
            });
            jQuery('div.forumslist div#topic-view ul#af-rater li:first-child').click(function() {
                jQuery('div.exchange span#forumStarRatingDetails').addClass('clicked');
                jQuery('div.forumslist div#topic-view ul#af-rater li:first-child').css('cursor', 'default');
            });
        }
        //If they are logged in, and they have voted
        if (jQuery('div.exchange span#forumStarRatingDetails').hasClass('forum-rating-logged-in rated') == true) {
            jQuery('div.forumslist div#topic-view ul#af-rater li:first-child').css('cursor', 'default');
        }
        //If they are logged out
        if (jQuery('div.exchange span#forumStarRatingDetails').hasClass('forum-rating-logged-out') == true) {
            jQuery('div.forumslist div#topic-view div.rating-system').remove();
        }
    }

    //Forum Rating Count Logic
    if (jQuery('span#rating-count-wrapper').length > 0) {
        var countChecker = false;
        //Gets the rating count and appends to the wrapper up above. Its near the share this icons.
        var count = jQuery('span#rating-count').html();
        jQuery('span#rating-count-wrapper').html(count);

        //Checks to see if the user is logged in and has not rated before.
        if (jQuery('div.exchange span#forumStarRatingDetails').hasClass('forum-rating-logged-in need-rating') == true) {
            //If they have not rated, add the click event to the empty star.
            jQuery('div.rating-system ul#af-rater li:first-child').click(function() {
                //This checks so the counter won't keep going up. Only the 1st time.
                if (countChecker === false) {
                    var count = jQuery('span#rating-count-wrapper').html();
                    count = parseInt(count);
                    count = count + 1;
                    jQuery('span#rating-count-wrapper').html(count);
                    countChecker = true;
                }
            });
        }
    }


    // Remove Welcome Center notification links if value = 0
    jQuery("ul#notifications li a em").filter(function() {
        return jQuery(this).text() == '0';
    }).remove();


    // Remove Message Center notification links if value = 0
    jQuery("ul#notify li a em").filter(function() {
        return jQuery(this).text() == '0';
    }).remove();

    //Welcome Pane Followers. It checks if the anchor tag exists, and if it does, append it to the follower count li
    if (jQuery('div#dnn_WelcomePane a.followers-count')) {
        jQuery('div#dnn_WelcomePane a.followers-count').clone().appendTo(jQuery('ul#notify li.count-followers'));
        jQuery('div#dnn_WelcomePane a.followers-count').clone().appendTo(jQuery('div#dnn_WelcomePane ul#notifications li.count-followers'));
    }

    //Welcome Pane My Feed Alerts. It checks if the anchor tag exists, and if it does, append it to the feed count li
    if (jQuery('div#dnn_WelcomePane a.feed-count')) {
        jQuery('div#dnn_WelcomePane a.feed-count').clone().appendTo(jQuery('ul#notify li.count-alert'));
        jQuery('div#dnn_WelcomePane a.feed-count').clone().appendTo(jQuery('div#dnn_WelcomePane ul#notifications li.count-alert'));
    }

    jQuery("ul#notifications li a:empty").addClass('inactive');
    jQuery("ul#notify li a:empty").addClass('inactive');

    //Sets the new feed counter for the my feed panel. ex: You have 3 new feed items.
    if (jQuery('div.mystuff div#dnn_FeedPane span.new-alerts')) {
        var count = jQuery('div#dnn_WelcomePane a.feed-count em').html();
        if (count > 0) {
            jQuery('div.mystuff div#dnn_FeedPane span.new-alerts span.count').html(count);
        } else {
            jQuery('div.mystuff div#dnn_FeedPane span.new-alerts span.count').html('0');
        }

    }

    /*My Followers Page Actions
    When page loads, hide all but people you are following
    Actions for the tabs
    */
    jQuery('div#followers-view-all ul.tabs li').click(function() {
        //Add the current class to the clicked tab to highlight
        jQuery(this).addClass('current');
        //Remove the current class name from all tabs
        jQuery(this).siblings().removeClass('current');

        var className = jQuery(this).attr('id');
        //Check to see which tab was clicked and hide/show items
        switch (className) {
            case 'following':
                jQuery('div#followers-view-all ul.followers').fadeOut(function() {
                    jQuery('div#followers-view-all ul.followers>li').hide();
                    jQuery('div#followers-view-all ul.followers li.following').show();
                    jQuery(this).fadeIn();
                });
                break;
            case 'followers':
                jQuery('div#followers-view-all ul.followers').fadeOut(function() {
                    jQuery('div#followers-view-all ul.followers>li').hide();
                    jQuery('div#followers-view-all ul.followers li.follower').show();
                    jQuery('div#followers-view-all ul.followers li.new-follower input').hide();
                    jQuery(this).fadeIn();
                });
                break;
            case 'new-followers':
                jQuery('div#followers-view-all ul.followers').fadeOut(function() {
                    jQuery('div#followers-view-all ul.followers>li').hide();
                    jQuery('div#followers-view-all ul.followers li.new-follower input').show();
                    jQuery('div#followers-view-all ul.followers li.new-follower').show();
                    jQuery(this).fadeIn();
                });
                break;
        } // end of switch
    });

    //actions for the hide notification. When clicked have xmod do the ajax, and because of a bug in xmod,
    //It doesnt full refresh page. So I have to manually set the count down 1, and show/hide the new followers.
    jQuery('div#followers-view-all ul.followers li.new-follower input').live('click', function() {
        var count = jQuery('div#followers-view-all ul.tabs li#new-followers span.count').html() - 1;
        jQuery('div#followers-view-all ul.tabs li#new-followers span.count').html(count);
        jQuery('div#followers-view-all ul.followers').fadeOut(function() {
            jQuery('div#followers-view-all ul.followers>li').hide();
            jQuery('div#followers-view-all ul.followers li.new-follower').show();
            jQuery(this).fadeIn();
        });
    });

    //For page: Admin/RecognitionEditUserStatus
    jQuery('input.recognition-status-input').keypress(function(event) {
        if (event.which == 13) {
            event.preventDefault();
        }
    });

    //Locations Locator - Show the zip code input depending on the country
    jQuery('div.locations div.location-locator-form select').change(function() {
        // Create array of the countries to check for.
        var countries = ["United States", "Canada"];
        //Get the selected country when the user chooses an option from the drop down.
        var selectedCountry = jQuery("div.locations div.location-locator-form select option:selected").val();
        //Checks if the selected country is in the countries array, if it is fadeIn the zip code input, else fade it out.
        if (jQuery.inArray(selectedCountry, countries) >= "0") {
            jQuery('div.locations div.location-locator-form td.zipcode').fadeIn();
        } else {
            jQuery('div.locations div.location-locator-form td.zipcode').fadeOut();
            jQuery('div.locations div.location-locator-form td.zipcode input[type="text"]').val('');
        }

    });

    //Locations Page Search Form Logic
    if (jQuery('div.locations div.location-locator-form input[type="text"]').length > 0) {
        var zip = getUrlVars()["zip"];
        jQuery('div.locations div.location-locator-form input[type="text"]').val(zip);
        var country = getUrlVars()["country"];
        //Loop through each option, and set the correct country.
        jQuery('div.locations div.location-locator-form select option').each(function() {
            if (jQuery(this).val().replace(' ', '+') == country) {
                jQuery(this).attr('selected', 'selected');
            }
        });
        // Create array of the countries to check for.
        var countries = ["United States", "Canada"];
        //Checks if the selected country is in the countries array, if it is fadeIn the zip code input, else fade it out.
        if (jQuery.inArray(country.replace('+', ' '), countries) >= "0") {
            jQuery('div.locations div.location-locator-form td.zipcode').fadeIn();
        }

    }

    //Returns the array of get variables from the url. I used this in the locations page search form logic.
    function getUrlVars() {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        if (hashes.length > 1) {
            for (var i = 0; i < hashes.length; i++) {
                hash = hashes[i].split('=');
                vars.push(hash[0]);
                vars[hash[0]] = hash[1];
            }
            return vars;
        }
    }

    //Contact Us Sidebar Location Logic
    //When user presses enter on search. Then add value as hash value.
    jQuery("div#contact-us-sidebar div.zip-code input").keypress(function(event) {
        var searchValue = jQuery(this).val().replace(' ', '+');

        if (event.which == 13 && searchValue != '') {
            var pageUrl = '/Locations.aspx?zip=' + searchValue + '&country=United+States';
            window.location = pageUrl;
        }
    });
    jQuery("div#contact-us-sidebar div.zip-code a.submit").click(function(event) {
        event.preventDefault();
        var searchValue = jQuery("div#contact-us-sidebar div.zip-code input").val().replace(' ', '+');
        var pageUrl = '/Locations.aspx?zip=' + searchValue + '&country=United+States';
        window.location = pageUrl;
    });

    /****************Power Trader Radio Logic**************/
    //When page loads on PTR page, highlight 1st video and set the text in the video-wrapper
    if (jQuery('div#container div.radio div.video-wrapper').length > 0) {
        var ptrTitle = "";
        var ptrDate = "";
        var ptrDescription = "";
        ptrTitle = jQuery('div#container div.radio div.video-list ul.episodes li:first h4 a').html();
        ptrDate = jQuery('div#container div.radio div.video-list ul.episodes li:first span.date').html();
        ptrDescription = jQuery('div#container div.radio div.video-list ul.episodes li:first p.description').html();
        //Check if the clicked episode is the current live video. If it is, show/hide the live banner div.
        if (jQuery('div#container div.radio div.video-list ul.episodes li:first').hasClass('live') == true) {
            jQuery('div#container div.radio div.video-wrapper div.live-banner').fadeIn();
        }

        jQuery('div#container div.radio div.video-wrapper h3.title').html(ptrTitle);
        jQuery('div#container div.radio div.video-wrapper span.date').html(ptrDate);
        jQuery('div#container div.radio div.video-wrapper p.description').html(ptrDescription);
        jQuery('div#container div.radio ul.postmetadata li.sharer span.st_twitter_hcount').attr('st_title', ptrTitle);
        jQuery('div#container div.radio ul.postmetadata li.sharer span.st_facebook_hcount').attr('st_title', ptrTitle);
        jQuery('div#container div.radio ul.postmetadata li.sharer span.st_sharethis_hcount').attr('st_title', ptrTitle);

        //Start my timer to check if a live video is playing or not.
        startLiveVideoChecker();
    }

    //Video List Logic
    //When user clicks on video, it pushes the data to the video-wrapper
    jQuery('div#container div.radio div.video-list ul.episodes li h4 a').click(function() {
        ptrTitle = jQuery(this).html();
        ptrDate = jQuery(this).parent().parent().find('span.date').html();
        ptrDescription = jQuery(this).parent().parent().find('p.description').html();
        //Check if the clicked episode is the current live video. If it is, show/hide the live banner div.
        if (jQuery(this).parent().parent().hasClass('live') == true) {
            jQuery('div#container div.radio div.video-wrapper div.live-banner').fadeIn();
        } else {
            jQuery('div#container div.radio div.video-wrapper div.live-banner').fadeOut();
        }

        jQuery('div#container div.radio div.video-wrapper h3.title').html(ptrTitle);
        jQuery('div#container div.radio div.video-wrapper span.date').html(ptrDate);
        jQuery('div#container div.radio div.video-wrapper p.description').html(ptrDescription);
        jQuery('div#container div.radio ul.postmetadata li.sharer span.st_twitter_hcount').attr('st_title', ptrTitle);
        jQuery('div#container div.radio ul.postmetadata li.sharer span.st_facebook_hcount').attr('st_title', ptrTitle);
        jQuery('div#container div.radio ul.postmetadata li.sharer span.st_sharethis_hcount').attr('st_title', ptrTitle);
    });
    //Toggle Buttons for upcoming events or previous episodes
    jQuery('div#container div.radio div.toggle-buttons a').click(function() {
        //Remove the current class name from all tabs
        jQuery('div#container div.radio div.toggle-buttons a').removeClass('current');
        var className = jQuery(this).attr('class');
        //Add the current class to the clicked tab to highlight
        jQuery(this).addClass('current');
        //Check to see which tab was clicked and hide/show items
        switch (className) {
            case 'upcoming':
                jQuery('div#container div.radio div.video-list ul.episodes').fadeOut(function() {
                    jQuery('div#container div.radio div.video-list ul.episodes li').hide();
                    if (jQuery('div#container div.radio div.video-list ul.episodes li.upcoming').length == 0) {
                        jQuery('div#container div.radio div.video-list ul.episodes').append("<li class='upcoming'><h4>There are no upcoming episodes scheduled. <br />Check back later.</h4></li>");
                    }
                    jQuery('div#container div.radio div.video-list ul.episodes li.upcoming').show();
                    jQuery(this).fadeIn();
                });
                break;
            case 'archive':
                jQuery('div#container div.radio div.video-list ul.episodes').fadeOut(function() {
                    jQuery('div#container div.radio div.video-list ul.episodes li').hide();
                    jQuery('div#container div.radio div.video-list ul.episodes li.archive').show();
                    jQuery(this).fadeIn();
                });
                break;
        } // end of switch
    });
    //Power Trading Radio Search Form
    //When page loads, make sure the form fields show the get variables correctly.
    if (jQuery('div#container div.radio div.video-search-form input[type="text"]').length > 0) {
        //If there are get variables in the url, then push those values into the input fields.
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        if (hashes.length > 1) {
            var search = getUrlVars()["q"].replace(/\+/g, " ");
            var video = getUrlVars()["video"];
            var audio = getUrlVars()["audio"];
            jQuery('div#container div.radio div.video-search-form input[type="text"]').val(search);
            jQuery('div#container div.radio div.video-search-form input[type="checkbox"]').each(function() {
                if (video == 'True') {
                    jQuery('div#container div.radio div.video-search-form span.video-checkbox input[type="checkbox"]').attr('checked', 'checked');
                }
                if (audio == 'True') {
                    jQuery('div#container div.radio div.video-search-form span.audio-checkbox input[type="checkbox"]').attr('checked', 'checked');
                }
            });
        }
    }
    /****************End of Power Trader Radio Logic**************/

    //Event Registration Form Logic
    //If user selects certain dropdown option, then show the zip code input.
    jQuery('div.event-registration-form select').change(function() {
        // Create array of the countries to check for.
        var countries = ["United States", "Canada", "India"];
        //Get the selected country when the user chooses an option from the drop down.
        var selectedCountry = jQuery("div.event-registration-form select option:selected").val();
        //Checks if the selected country is in the countries array, if it is fadeIn the zip code input, else fade it out.
        if (jQuery.inArray(selectedCountry, countries) >= "0") {
            jQuery('div.event-registration-form ul li.zip-code').fadeIn();
            jQuery('div.event-registration-form ul li.zip-code input').val('');
        } else {
            jQuery('div.event-registration-form ul li.zip-code').fadeOut();
            jQuery('div.event-registration-form ul li.zip-code input').val('N/A');
        }

    });

    //Member Directory Logic
    //When page loads on Member Directory, if there are any get variables, then load those into the input fields.
    if (jQuery('div.member-search').length > 0) {
        var e = getUrlVars()["e"]; //email
        var fn = getUrlVars()["fn"]; //first name
        var ln = getUrlVars()["ln"]; //last name
        var c = getUrlVars()["c"]; //city
        var r = getUrlVars()["r"]; //region
        var st = getUrlVars()["st"]; //swing trader
        var dt = getUrlVars()["dt"]; //day trader
        var lt = getUrlVars()["lt"]; //long term investor
        var sc = getUrlVars()["sc"]; //stocks
        var oc = getUrlVars()["oc"]; //options
        var foc = getUrlVars()["foc"]; //forex
        var fuc = getUrlVars()["fuc"]; //futures
        jQuery('div.member-search div.box div:nth-child(1) input').val(fn);
        jQuery('div.member-search div.box div:nth-child(2) input').val(ln);
        jQuery('div.member-search div.box div:nth-child(3) input').val(c);
        jQuery('div.member-search div.box div:nth-child(4) input').val(r);
        jQuery('div.member-search div.box div:nth-child(5) input').val(unescape(e));
        if (st == "True") {
            jQuery('div.member-search div.box div:nth-child(6) div.toggle input:eq(0)').attr('checked', 'checked');
        }
        if (dt == "True") {
            jQuery('div.member-search div.box div:nth-child(6) div.toggle input:eq(1)').attr('checked', 'checked');
        }
        if (lt == "True") {
            jQuery('div.member-search div.box div:nth-child(6) div.toggle input:eq(2)').attr('checked', 'checked');
        }
        if (sc == "True") {
            jQuery('div.member-search div.box div:nth-child(7) div.toggle input:eq(0)').attr('checked', 'checked');
        }
        if (oc == "True") {
            jQuery('div.member-search div.box div:nth-child(7) div.toggle input:eq(1)').attr('checked', 'checked');
        }
        if (foc == "True") {
            jQuery('div.member-search div.box div:nth-child(7) div.toggle input:eq(2)').attr('checked', 'checked');
        }
        if (fuc == "True") {
            jQuery('div.member-search div.box div:nth-child(7) div.toggle input:eq(3)').attr('checked', 'checked');
        }

    }

    //Mastermind Market Instructions. When the more info button is clicked, it slide toggles the instructions.
    jQuery('div#market-levels a.more-info').click(function() {
        jQuery('div#dnn_MarketLevelsPane div.DnnModule-1526').slideToggle();
        if (jQuery(this).html() == 'More Info') {
            jQuery(this).html('Close');
        } else {
            jQuery(this).html('More Info');
        }
    });

    //Market Levels Admin Page
    //Get all market headings from the recent market levels table and put it into the input fields above in the form.
    if (jQuery('table.admin-market-levels').length > 0) {
        jQuery('div#admin-market-levels div#market-levels table.market-data thead td').each(function(index, value) {
            var value = jQuery(this).html();
            value = jQuery('<div />').html(value).text();
            jQuery('table.market-headers input[type="text"]:eq(' + index + ')').val(value);
        });
    }
    //Get all data importance from the recent market levels table and put it into the input fields above in the form.
    if (jQuery('table.admin-market-levels').length > 0) {
        jQuery('div#admin-market-levels div#market-levels table.market-data tbody td span.data').parent().each(function(index, value) {
            var importance = jQuery(this).attr("class").split(" ")[0];
            if (importance == "normal") {
                jQuery('table.market-data td.data:eq(' + index + ') span.normal input').attr('checked', true);
                jQuery('table.market-data td.data:eq(' + index + ') span.strong input').attr('checked', false);
                jQuery('table.market-data td.data:eq(' + index + ') span.very-strong input').attr('checked', false);
            }
            if (importance == "strong") {
                jQuery('table.market-data td.data:eq(' + index + ') span.normal input').attr('checked', false);
                jQuery('table.market-data td.data:eq(' + index + ') span.strong input').attr('checked', true);
                jQuery('table.market-data td.data:eq(' + index + ') span.very-strong input').attr('checked', false);
            }
            if (importance == "very-strong") {
                jQuery('table.market-data td.data:eq(' + index + ') span.normal input').attr('checked', false);
                jQuery('table.market-data td.data:eq(' + index + ') span.strong input').attr('checked', false);
                jQuery('table.market-data td.data:eq(' + index + ') span.very-strong input').attr('checked', true);
            }
        });
    }
    //Get all data from the recent market levels table and put it into the input fields above in the form.
    if (jQuery('table.admin-market-levels').length > 0) {
        jQuery('div#admin-market-levels div#market-levels table.market-data span.data').each(function(index, value) {
            var value = jQuery(this).html();
            jQuery('table.market-data input[type="text"]:eq(' + index + ')').val(value);
        });
    }

    //Mastermind Market Levels Table Logic
    //Loop through each td and see if any spans have a class of True on it, meaning Data Change, if so, add class to td
    jQuery('div#market-levels table.market-data span.data').each(function(index, value) {
        if (jQuery(this).hasClass('True')) {
            jQuery(this).parent().addClass('data-change');
        }
    });

    //Mastermind Links Logic.
    //The Trade Rooms link needs slide down to trade rooms module
    jQuery('div#dnn_LinksMastermindPane ul li a.rooms').click(function() {
        goToByScroll('div#dnn_RoomsPane');
    });


});



var startLiveVideoCheckerCounter = 0;
//PTR live video checker. Checks to see if its 5pm EST, reload the page to view live video.
function startLiveVideoChecker() {
    var timer = setTimeout("startLiveVideoChecker()", 30000);
    var currentTime = new Date();
    //Check to see if its 5pm EST and if for some reason the video has not gone live after 5 minutes. 
    //If its after 3 minutes and no live video, stop refreshing page. 
    if (currentTime.getUTCHours() - 5 == 18 && currentTime.getMinutes() <= 3) {
        if (jQuery('div#container div.radio div.video-wrapper div.live-banner').css("display") == "none") {
            if (startLiveVideoCheckerCounter > 0) {
                window.location.reload();
            }            
        }
    }
    startLiveVideoCheckerCounter++;
}
