﻿
var currentNewsItem = 0;
var newItemLimit = 3;
var newsFeed = baseURL  +'News/rss/Default.aspx';
var stringLength = 70;


$(document).ready(function () {

    $("#subNav .lastTabItem:last").addClass('lastTab');

    $(".searchInput").focus(function () {
        if ($(this).val() == 'SEARCH') {
            $(this).attr('value', '');
            $(this).css({ color: "black" });
        }
    });

    $(".searchInput").blur(function () {
        if ($(this).val() == "") {
            $(this).attr('value', 'SEARCH');
            $(this).css({ color: "#9E9E9E" });
        }
    });


    $("li.main-trigger").hover(
      function () {
          $(this).children("ul:first").show();
      },
      function () {
          $(this).children("ul:first").hide();
      }
    );

    $("li.main-trigger ul li").hover(
      function () {
          $(this).children("ul").show();
      },
      function () {
          $(this).children("ul").hide();
      }
    );
    $('ul.sub-section-nav li ul li.selected ul:first').show();
    $('ul.sub-section-nav li ul li.selected').siblings().children('ul').remove();
    $('ul.sub-section-nav li ul li.selected').parent().parent().siblings().children('ul').remove();
    $('ul.sub-section-nav li ul li.selected').parent().show();
    $('ul.sub-section-nav li ul li.selected li ul').children().remove();
    $('ul.sub-section-nav li ul li.selected').parent().parent().children('a').addClass('active');
    $('ul.sub-section-nav li ul li.selected ul:first').show();




    $('#footer ul li:last').css('border', 'none');
    $('ul.sub-section-nav li ul li ul li').click(function () { $(this).siblings().show(); });

    if ($('#newsItem').length != 0) {
        loadnewsItem();
        window.setInterval('loadnewsItem()', 5000);
    }

});
function loadnewsItem() {

    if (currentNewsItem > newItemLimit)

        currentNewsItem = 0;


    loadNewsFeed(newsFeed, currentNewsItem);

    currentNewsItem += 1;

}






function loadNewsFeed(path, currentItem) {


    $.jGFeed(path,
    function (feeds) {
        // Check for errors
        if (!feeds) {
            // there was an error
            return false;
        }
    

       var item = feeds.entries[currentItem];
       var html = '';

       html += '<a href="'
                + item.link
                + '">'
       if (item.title.length > stringLength) {

           html += item.title.substring(0, stringLength) + "...";
       }
       else {
           html += item.title;
       }


       html += '</a>';

       jQuery('#newsItem').html(html);


    }, 10);

  }



function adminPreviewClick() {
    $(".bodyContent").show();
    $("#contentWrap").removeClass("Edit");
    $("#contentWrap").removeClass("History");
}

function adminEditClick() {
    $(".bodyContent").show();
    if (typeof IsEditable == 'undefined' || IsEditable != "false")
        $("#contentWrap").addClass("Edit");
    $("#contentWrap").removeClass("History");
}

function adminHistoryClick() {
    $(".bodyContent").hide();
    $("#contentWrap").removeClass("Edit");
    $("#contentWrap").addClass("History");
}

function doSlideToggle() {
    $(".loginWrap").slideToggle("fast");
    $(".loginDrawer").toggleClass("open");
}

function doCultureSlide() {
    $(".cultureBtns").slideToggle("fast");
}
