$(document).ready(function () {
  $(".rollFade").hover(function() {
      $(this).stop().fadeTo(300, .65);},
    function() {
      $(this).stop().fadeTo(200, 1);});
  $('#peopleScroller').cycle({fx:'fade',speed:400});
  $('#realEstateScroller').cycle({fx:'fade',speed:400, delay: 200});   
    $('#environmentScroller').cycle({fx:'fade',speed:400, delay: 400});
    $('.sponsorGallery').cycle('fade');
  $('.ic_container').capslide({
  caption_color  : 'white',
                    caption_bgcolor  : 'black',
                    overlay_bgcolor : 'transparent',
                    border      : 'none',
                    showcaption      : true});
    $('.button').button();
   //Gallery Javascript to make popups
  $("a[rel=gallery]").fancybox({
        'transitionIn'  : 'elastic',
        'transitionOut'  : 'elastic',
        'titlePosition'  : 'inside',
        'titleFormat'    : function(title, currentArray, currentIndex, currentOpts) {
          return '<div id="fancybox-title-inside">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + '<p>' + title + '</p>' + '</div>';
        }
      });
    // $('input:submit').button();
   //     $('input:button').button();
    $('.whoIsComing').button({ icons: { primary: "ui-icon-help", secondary: "ui-icon-newwin"} });
    $('.linkButtonSubmit').button({ icons: { secondary: "ui-icon-circle-triangle-e"} });
    $('.question').button({ icons: { primary: "ui-icon-help" }, text: false });
    var questionTitle = $('.instructionPane h3');
    var questionDlg = $('.instructionPane').dialog({ autoOpen: false, width: 700, show: "blind", title: questionTitle.text() });
    questionTitle.hide();
    $('.question').click(function (event) {
        event.preventDefault();
        questionDlg.dialog("open");
    });

    var dlgFrgtPass = $('.forgotPassword').dialog({ autoOpen: false, width: 500, height: 200, show: "blind", title: $('#forgotPasswordTitle').html() });
    dlgFrgtPass.parent().appendTo($("form:first"));
    $('#forgotPasswordTitle').hide();
    $("#PasswordRecoveryLink").click(function (event) {
        event.preventDefault();
        dlgFrgtPass.dialog("open");
    });

    $(".linkButton").button();
    //$('.linkButton').button({ icons: { secondary: "ui-icon-circle-triangle-e"} });
    $('.eventDetailsItem').hide();
    $('.eventDetails span').button({ icons: { primary: "ui-icon-circle-plus"} }).click(function (event) {
        event.preventDefault();
        $(this).next().slideToggle();
        $(this).toggleClass("clicked");
        if ($(this).hasClass("clicked"))
            $(this).button("option", "icons", { primary: "ui-icon-circle-minus" });
        else
            $(this).button("option", "icons", { primary: "ui-icon-circle-plus" });

    }).css("font-size", 11);
    $("#tabs").tabs();
  
  $(".clsproducts th").each(function () { $(this).addClass("ui-state-default"); });
    //$(".clsproducts td").each(function() { $(this).addClass("ui-widget-content"); });
    $(".clsproducts tr").hover(function () { $(this).children("td").addClass("ui-state-hover"); }, function () { $(this).children("td").removeClass("ui-state-hover"); });
    $(".clsproducts tr").click(function () { $(this).children("td").toggleClass("ui-state-highlight"); });


    $(".modalOpen").click(function (event) {
        event.preventDefault();
        var url = $(this).attr("href");
        var title = $(this).attr('title')
        var newDiv = $('<iframe frameBorder="0"></iframe>').attr('src', url).dialog({
            title: title,
            width: 560,
            height: 370,
            modal: true
        }).css({ width: "530px", height: "350px" });

    });
    //    $("#linksResources ul").hide();
    //    $("#linksResources h4").click(function (e) {
    //        e.preventDefault();
    //        $(this).next().slideToggle();
    //        $(this).toggleClass("clicked");
    //    });
    $(".accordion").accordion({
        autoHeight: false,
        collapsible: true,
        active: false
    });

    //Job Postings
    $('.postingSection').hide();
    $('.postingSection:first').show();
     $('input#btnNext').click(function () {
        if (Page_ClientValidate('posting'))
            $(this).parents('.postingSection').first().slideToggle("slow").next().slideToggle("slow");
    });
    $('input#btnPrevious').click(function () {
        $(this).parents('.postingSection').first().slideToggle("slow").prev().slideToggle("slow");
    });
    $('.highlight').focus(function () {
        $(this).parent().parent().parent().stop().animate({
            backgroundColor: "#ececec"
        }, 500);
    });
    $('.highlight').blur(function () {
        $(this).parent().parent().parent().stop().animate({
            backgroundColor: "transparent"
        }, 300);
    });
    //$('input:submit').button().css("font-size", 12);
    $('#btnNext').button({ icons: { secondary: "ui-icon-circle-triangle-e"} }).css("font-size", 12);
    $('#btnPrevious').button({ icons: { primary: "ui-icon-circle-triangle-w"} }).css("font-size", 12);
    $('.postingTable tr:odd').css("background-color", "#EBEAE8");
    //End JobPostings
    $('.datepicker').datepicker();
    /*Style Tables with jQuery UI*/
    $(".postingTable th").each(function () { $(this).addClass("ui-state-default"); });
    //$("#postingTable td").each(function() { $(this).addClass("ui-widget-content"); });
    $(".postingTable tr").hover(function () { $(this).children("td").addClass("ui-state-hover"); }, function () { $(this).children("td").removeClass("ui-state-hover"); });
    $(".postingTable tr").click(function () { $(this).children("td").toggleClass("ui-state-highlight"); });

    $("[id$='chkbxCheque']").click(function () {
        $("[id$='pnlCreditCard']").slideToggle();
        $("[id$='pnlCardExists']").slideToggle();
    });

});

//Purchase Services
function FirejQuery() {

    /* image popup action */

    $(".prodImgHolder").hover(function () {

        var pos = $(this).position();
        var imageWidth = $(this).next(".largeImage").find('img').width();

        $(this).next(".largeImage").css({
            'top': pos.top,
            left: pos.left + 80
        });

        $(this).next(".largeImage")
        /* Add class of "hover", then stop animation queue buildup*/
        .animate({
            marginTop: '13',
            /* The next 4 lines will vertically align this image */
            marginLeft: '0',
            top: pos.top,
            left: pos.left + 80,
            //            width: imageWidth, /* Set new width */
            //            height: imageWidth, /* Set new height */
            opacity: "show"
        }, 300);
        /* this value of "200" is the speed of how fast/slow this hover animates */

    }, function () {

        var pos2 = $(this).position();

        $(this).next(".largeImage")
        /* Remove the "hover" class , then stop animation queue buildup*/
        .animate({
            marginTop: '0',
            /* Set alignment back to default */
            marginLeft: '0',
            top: pos2.top,
            left: pos2.left + 80,
            //            width: '100px', /* Set width back to default */
            //            height: '100px', /* Set height back to default */
            opacity: "hide"
        }, 100);

    });

    /* toggle recipient panel actions */

    $("#btnChangeRecipient").click(function () {
        $("[id$='_pnlRecipientInfo']").hide();
        $("[id$='_pnlSearchRecp']").show();
        $("[id$='_tbxEmail']").focus();
    });

    //        $("#btnAddRecipient").click(
    //        function() {
    //            $("[id$='_pnlRecipientInfo']").hide();
    //            $("[id$='_pnlSearchRecp']").show();
    //            $("[id$='_tbxEmail']").focus();
    //            $("#btnAddRecipient").hide();
    //        });
    $("#btnCancelSearch").click(function () {
        $("[id$='_pnlRecipientInfo']").show();
        $("[id$='_pnlSearchRecp']").hide();
        $("[id$='_RblSearchMethod'] input[type=radio]")[0].checked = true;
        $("#btnAddRecipient").show();
        $("[id$='_emailSearchBox']").show();
        $("[id$='_btnEmailSearchRecp']").show();
        $("[id$='_nameSearchBox']").hide();
        $("[id$='_btnSearchRecp']").hide();
        $("[id$='_tbxEmail']").val("");
        $("[id$='_tbxEmail']").focus();
        $("[id$='_tbxSearchFname']").val("");
        $("[id$='_tbxSearchLname']").val("");
        $("#emptyEmailError").hide();
        $("#errorSearchText").hide();
        $("[id$='_regexEmailValidator']").hide();
    });

    /*toggle the email and name search box */
    $("[id$='_RblSearchMethod']").click(function () {
        var emailSearchBoxDiv = $("[id$='_emailSearchBox']");
        var nameSearchBoxDiv = $("[id$='_nameSearchBox']");

        if ($("[id$='_RblSearchMethod'] input[type=radio]:checked").val() == "0") {
            nameSearchBoxDiv.hide();
            $("[id$='_btnSearchRecp']").hide();
            emailSearchBoxDiv.show();
            $("[id$='_btnEmailSearchRecp']").show();
            $("[id$='_tbxEmail']").focus();

        } else {
            nameSearchBoxDiv.show();
            $("[id$='_btnSearchRecp']").show();
            emailSearchBoxDiv.hide();
            $("[id$='_btnEmailSearchRecp']").hide();
            $("[id$='_tbxEmail']").val("");
            $("#emptyEmailError").hide();
            $("[id$='_regexEmailValidator']").hide();
        }
        $("#errorSearchText").hide();
    });

    /* validate EmailSearch text input */
    $("[id$='_btnEmailSearchRecp']").click(function () {
        if ($.trim($("[id$='_tbxEmail']").val()).length < 1) {
            $("#emptyEmailError").html("Email Required");
            $("#emptyEmailError").show();
            return false;
        } else {
            $("#emptyEmailError").hide();
            if ($("[id$='_regexEmailValidator']").is(':visible')) {

                return false;
            } else { }
        }

    })

    $("[id$='_btnSearchRecp']").click(function () {
        if (($("[id$='_tbxSearchFname']").val().replace(/ /g, '') == '') && ($("[id$='_tbxSearchLname']").val().replace(/ /g, '') == '')) {
            $("#errorSearchText").html("Either the first or last name is required");
            $("#errorSearchText").show();
            return false;
        } else {
            $("#errorSearchText").hide();
        }

    })

    $("[id$='_btnAddToCart']").click(function () {
        var quantityTxtBox = $(this).prev();
        var errorObj = $(this).siblings(':first');
        if ((isNaN(quantityTxtBox.val(), 10)) || (quantityTxtBox.val().indexOf('.') > -1)) {
            errorObj.show();
            return false;
        } else {

            if (parseInt(quantityTxtBox.val()) > 0) {
                errorObj.hide();
                return true;
            } else {
                errorObj.show();
                return false;
            }
        }

    })

}

function FirejQueryShipping() {

    $("[id$='_rblShippingMethod'] input").change(function () {

        var checkedBtnValue = $("[id$='_rblShippingMethod'] input[type=radio]:checked").val();
        var nextToPaymentPanel = $("[id$='_pnlNext']");
        if (checkedBtnValue == 2) {

            $("#AddressInfoPanel").show();
            $("#pickupInfoPanel").hide();
            if ($.trim($("[id$='lblShipStreetLine1']").val()).length < 1) {
                $("[id$='_btnGotoPayment']").attr("disabled", true);
            } else {
                $("[id$='_btnGotoPayment']").removeAttr("disabled");
            }
            $("[id$='_hfShippingMethod']").val("2");
            nextToPaymentPanel.hide();
        } else {

            $("#AddressInfoPanel").hide();

            $("#pickupInfoPanel").show();
            $("[id$='_btnGotoPayment']").removeAttr("disabled");
            $("[id$='_hfShippingMethod']").val("3");
            nextToPaymentPanel.show();

        }

    })

}

function FirejQueryPayment() {

    $("#imgbtnOrderExpandDown").click(function () {
        if ($("#purchReviewHolder").is(':visible') && $('#purchReviewHolder').parents(':hidden').length == 0) {
            $("#imgbtnOrderExpandDown").hide();
            $("#imgbtnOrderCollapseUp").show();
        } else {
            $("#purchReviewHolder").animate({
                height: 'toggle'
            }, 300);
            $("#imgbtnOrderExpandDown").hide();
            $("#imgbtnOrderCollapseUp").show();
        }
    })

    $("#imgbtnOrderCollapseUp").click(function () {

        $("#purchReviewHolder").hide();
        $("#imgbtnOrderCollapseUp").hide();
        $("#imgbtnOrderExpandDown").show();
    })
}

function checkPurchases() {
}
(function () {
    var twitterURL = "http://search.twitter.com/search.json";
    var refreshURL = "";
    var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    var hours = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
    var twitterSearch = "";
    var promotedUser = "";

    namespace('SSU');

    String.prototype.hashtagify = function () {
        return this.replace(/[#]+[A-Za-z0-9-_]+/g,
        function (h) {
            var hashtag = h.replace("#", "")
            return '<a href="https://twitter.com/#!/search/%23' + hashtag + '" target="_blank">#' + hashtag + '</a>';
        });
    };

    String.prototype.linkify = function () {
        return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g,
        function (l) {
            return '<a href="' + l + '" target="_blank">' + l + '</a>';
        });
    };

    function getHour(hour) {
        if (hour > 12) { return hours[(hour - 13)] } else if (hour === 0) { return 12 } else { return hour }
    }

    function newTweets() {
        $.ajax({
            url: twitterURL + refreshURL,
            dataType: "jsonp",
            jsonpCallback: "SSU.PrintTweets"
        });
    };

    SSU.PrintTweets=function(data) {
        if (data.results.length > 0) {
            refreshURL = data.refresh_url;
            $.each(data.results.reverse(), function (index, value) {
                var dateCreated = new Date(value.created_at);
                var container = $("#twitter-timeline");
                var tweetText = value.text;
                tweetText = tweetText.linkify().hashtagify();
                var html = "<div class='tweet well clearfix' style='display:none;'>";
                html += "<img height='48px' width='48px' src='" + value.profile_image_url + "' class='profile-pic pull-left'>";
                html += "<div class='tweetBody'>";
                html += "<div>@" + value.from_user + "&nbsp;" + value.from_user_name + "</div><div class='text'>" + tweetText + "</div>";
                html += "<div><img src='/images/bird_16_gray.png'>&nbsp;";
                html += monthNames[dateCreated.getMonth()] + " " + dateCreated.getDate() + " " + getHour(dateCreated.getHours()) + ":" + ((dateCreated.getMinutes() < 10) ? "0" + dateCreated.getMinutes() : dateCreated.getMinutes()) + "&nbsp;";
                html += "<a href='https://twitter.com/intent/tweet?in_reply_to=" + value.id_str + "&via=" + promotedUser.substr(1) + "&hashtags=" + twitterSearch + "' class='twitter-action' target='_blank'><i class='icon-share-alt'></i> Reply</a>&nbsp;<a href='https://twitter.com/intent/retweet?tweet_id=" + value.id_str + "' class='twitter-action' target='_blank'><i class='icon-retweet'></i> Retweet</a>&nbsp;<a href='https://twitter.com/intent/favorite?tweet_id=" + value.id_str + "' class='twitter-action' target='_blank'><i class='icon-star-empty'></i> Favorite</a>";
                html += "</div>";
                html += "</div>";
                html += "</div>";
                container.prepend(html);
            });
            $("#twitter-timeline .tweet:hidden").slideDown();
            twttr.anywhere(function (T) {
                T("#twitter-timeline").hovercards();
                $("a[href^='http://']").attr("target", "_blank");
            });


        }
    };

    SSU.DisplayStreamingVideoWithTwitter = function () {
        

        promotedUser = $("#twitter-timeline .promoted-user").text();
        twitterSearch = $("#twitter-timeline .search-criteria").text();
        refreshURL = "?q=" + encodeURIComponent("#" + twitterSearch);

        twttr.anywhere(function (T) {
            T('#follow-twitterapi').followButton(promotedUser);
            T("#tbox").tweetBox({
                height: 80,
                defaultContent: " #" + twitterSearch,
                label: "Get in the Conversation",
                data: { include_entities: true },
                onTweet : function(plaintext, html) {
                  newTweets();
                  $('#tweet-box').val(" #" + twitterSearch);
                }
            });
        });

        newTweets();
        var t = setInterval(newTweets, 15000);
    };
})();
if ($('#streamingVideoWithTwitter').length > 0) {
    SSU.DisplayStreamingVideoWithTwitter();
};    

