(function($){ function commonDocumentReady()
{
    $("ul#jqPrimaryLink > li:has(div.jqSubNav)").mouseenter(
        function()
        {
            var current         = $(this);
            var currentOffset   = current.position();
            var currentSubmenu  = current.children("div.jqSubNav");

            if(currentSubmenu.length > 0 && currentSubmenu.is(":hidden"))
            {
                //var submenuLeft = currentOffset.left + current.outerWidth() - currentSubmenu.outerWidth();


                    currentSubmenu.css({
                                            position : "absolute",
                                            'z-index' : '10000',
                                            top : (currentOffset.top + current.outerHeight()),
                                            left : currentOffset.left
                                        }).show();
                                        //.slideDown("fast");
            }

        })
    .mouseleave(
            function()
            {
                    var current			= $(this);
                    var currentSubmenu	= current.children("div.jqSubNav");

                    if(currentSubmenu.length > 0 && currentSubmenu.is(":visible"))
                    {
                            currentSubmenu.hide(); //.slideUp("slow");
                    }
            });
     $("div.jqSubNav").mouseenter(
                        function()
                        {
                            var current			= $(this);
                            var currentParent	= current.parent();
                            var currentChild    = current.children();
                            var anchorClass = currentParent.find("a").attr('class');
                            var addClass = '';
                            switch (anchorClass){
                                case 'home' :addClass = 'home-active';break;
                                case 'about-us' :addClass = 'about-us-active';break;
                                case 'programs' :addClass = 'programs-active';break;
                                case 'resources' :addClass = 'resources-active';break;
                                case 'events' :addClass = 'events-active';break;
                                case 'advertise-with-us' :addClass = 'advertise-with-us-active';break;
                                case 'news' :addClass = 'news-active';break;
                            }
                            currentParent.find("a").addClass(addClass);
                            currentChild.find("a").removeClass(addClass);

                        }
                );
        $("div.jqSubNav").mouseleave(
            function()
            {
                var current			= $(this);
                var currentParent	= current.parent();
                var currentChild    = current.children();
                var anchorClass = $.trim(currentParent.find("a").attr('class'));
                var aremoveClass = '';
                var addClass = '';
                switch (anchorClass){
                    case 'home-active' : 
                        case 'home home-active' :
                        aremoveClass = 'home-active';addClass = 'home';break;
                    case 'about-us-active' :
                    case 'about-us-active' :
                    case 'about-us about-us-active' :
                        aremoveClass = 'about-us-active';addClass = 'about-us';break;
                    case 'programs-active' :aremoveClass = 'programs-active';addClass = 'programs';break;
                    case 'resources-active' :aremoveClass = 'resources-active';addClass = 'resources';break;
                    case 'events-active' :aremoveClass = 'events-active';addClass = 'events';break;
                    case 'advertise-with-us-active' :aremoveClass = 'advertise-with-us-active';addClass = 'advertise-with-us';break;
                    case 'news news-active' :aremoveClass = 'news-active';addClass = 'news news-active';break;
                }//alert(aremoveClass + '===' + addClass);
                currentParent.find("a").removeClass(aremoveClass);
                currentParent.find("a").addClass(addClass);
                currentChild.find("a").removeClass(addClass);
            }
    );


    //$("div#jqCarousel").carousel({nextBtn:"<img src=\"/wp-content/themes/blackpress/images/carousel-left-arrow.gif\" />", btnsPosition:"outside", prevBtn:"<img src=\"/wp-content/themes/blackpress/images/carousel-right-arrow.gif\" />"});
    /*try {
        $("#jqCarousel").jCarouselLite({
            btnNext: "#jqNext",
            btnPrev: "#jqPrevious",
            circular: true,
            visible : 4
        }).width(890);
    }
    catch(e) {
    alert(e.message)
    }
    try {
        $("#jqtimeLineCarousel").jCarouselLite({
            btnNext: "#jqNext",
            btnPrev: "#jqPrevious",
            circular: true,
            visible : 4
        }).width(1000);
    }
    catch(e) {
    alert(e.message)
    }*/

            $("a#jqTimeLinePrevious").click(previousHistoryItem);
            $("a#jqTimeLineNext").click(nextHistoryItem);
            $("a#jqNext").click(nextFooterItem);
            $("a#jqPrevious").click(previousFooterItem);
//setTimeout(function(){
            var footerLogoSlider = $("ul#jqFooterCarousel");

            if(footerLogoSlider.length > 0)
            {
                var footerLogoSliderWidth = 0;

                footerLogoSlider.children("li").each(function()
                    {//console.log($(this).outerWidth())
                        footerLogoSliderWidth += $(this).outerWidth();
                    });
                    
                footerLogoSlider.width(footerLogoSliderWidth);
            }
            $('.jqSearch').focus(    function(){
                                    if($.trim($(this).val()) == 'SEARCH') {
                                        $(this).val('');
                                    }
                                })
                     .blur(    function(){
                                    if($.trim($(this).val()) == '') {
                                        $(this).val('SEARCH');
                                    }
                                })
   // }, 3e3);
}

$(document).ready(commonDocumentReady);
})(jQuery); 
function previousHistoryItem()
{
    var timeline = jQuery("ul#jqtimeLineCarousel");
    var start = timeline.children("li.jqHistoryTimelineStart");
    var end = timeline.children("li.jqHistoryTimelineEnd");
    var previous = start.prev("li");
    if(previous.length > 0)
    {

        previous.show();
        previous.prev("li").hide();
        timeline.animate({
            left: "+=158"
        }, 500);

        start.removeClass("jqHistoryTimelineStart");
        end.removeClass("jqHistoryTimelineEnd");

        previous.addClass("jqHistoryTimelineStart");
        end.prev("li").addClass("jqHistoryTimelineEnd");
    }

    return false;
}

function nextHistoryItem()
{
    var timeline = jQuery("ul#jqtimeLineCarousel");
    var start = timeline.children("li.jqHistoryTimelineStart");
    var end = timeline.children("li.jqHistoryTimelineEnd");
    var nextTimeline = end.next("li");
    
    if(nextTimeline.length > 0)
    {

        nextTimeline.show();
        //nextTimeline.prev("li").hide();
        timeline.animate({
            left: "-=158"
        }, 500, function(){
            start.hide();
        });

        start.removeClass("jqHistoryTimelineStart");
        end.removeClass("jqHistoryTimelineEnd");

        start.next("li").addClass("jqHistoryTimelineStart");
        nextTimeline.addClass("jqHistoryTimelineEnd");
    }

    return false;
}
function nextFooterItem()
{
    var footerLogoSlider    = jQuery("ul#jqFooterCarousel");
    var footerLogoSliderBox = jQuery("div#jqCarousel");
    var currentItem         = footerLogoSlider.children("li.current");
    if(currentItem.length == 0)
    {
        currentItem         = footerLogoSlider.children("li:first");
    }

    var rightDiff = (footerLogoSlider.offset().left + footerLogoSlider.outerWidth()) - (footerLogoSliderBox.offset().left + footerLogoSliderBox.outerWidth());

    var moveDistance = Math.min(rightDiff, currentItem.outerWidth());

    if(currentItem.next().length > 0)
    {
        currentItem.removeClass("current");
        currentItem.next().addClass("current");
    }

    footerLogoSlider.animate({
        left : "-=" +moveDistance
    }, 1);

    return false;
}

function previousFooterItem()
{

    var footerLogoSlider    = jQuery("ul#jqFooterCarousel");
    var footerLogoSliderBox = jQuery("div#jqCarousel");
    var currentItem         = footerLogoSlider.children("li.current");
    if(currentItem.length == 0)
    {
        currentItem         = footerLogoSlider.children("li:first");
    }
    else if(currentItem.prev("li").length > 0)
    {
        currentItem         = currentItem.prev("li");
    }

    var leftDiff = footerLogoSliderBox.offset().left - footerLogoSlider.offset().left;

    var moveDistance = Math.min(leftDiff, currentItem.outerWidth());

    footerLogoSlider.children("li.current").removeClass("current");
    currentItem.addClass("current");

    footerLogoSlider.animate({
        left : "+=" +moveDistance
    }, 1);

    return false;
}

function showSidebarLogin()
{
    jQuery('.sidebar-login-form').show();
    return false;
}


