﻿// JScript File
$(document).ready(function () {
    var cWidth = $('p.calibri').width();
    var aWidth = $('p.arial').width();

    if (cWidth != null && cWidth == aWidth) { $('body').css('font-size', '82%') }
});

$(document).ready(function () {

  

    //================= Search =====================

    $('div.globalNav input').focus(function () {
        if ($(this).val() == 'Search') {
            $(this).val('');
        }
    });

    $('div.globalNav input').blur(function () {
        if ($(this).val() == '') {
            $(this).val('Search');
        }
    });
    
    $('div.ecom-prod-line ul.row').each(function(){
        $(this).find('li:last').css('margin-right','0px')
    })
    

    //================= Image Long Desc Decoration =====================

    $('img.img-snippet').each(function () {
        var longText = $(this).attr('longdesc');
        $(this).wrap("<div class='snippet-block'><span class='generic-snippet'></span></div>");
        $("<span class='left'>&nbsp;</span><span class='right'>&nbsp;</span><span class='top'>&nbsp;</span><span class='bottom'>&nbsp;</span><span class='topleft'>&nbsp;</span><span class='topright'>&nbsp;</span><span class='bottomleft'>&nbsp;</span><span class='bottomright'>&nbsp;</span>").insertBefore($(this));
        $("<span class='snippet-text'></span>").insertAfter($(this).parent());
        $(this).parent().siblings('.snippet-text').text(longText);
    });

    $('.ediatable').each(function () {
        $(this).addClass('clearfix');
    })
    //    $('.treeNodeText').each(function(){
    //        $(this).closest('td').css('width','100%');
    //    });
    //   $('.treeNodeText').click(function(){
    //        $('.treeNodeText').each(function(){
    //        $(this).closest('td').css('width','100%');
    //    });
    //    });

    //================= Image scroll  =====================


    $('div.anythingFader').mouseover(function () {
        $('#thumbNav').css('display', 'block');
        $('#start-stop').css('display', 'block');
    })
    $('div.anythingFader').mouseout(function () {
        $('#thumbNav').css('display', 'none');
        $('#start-stop').css('display', 'none');
    });

    //================= Author Style Table  =====================

    $('.striped-table tr:even').addClass('even')
    $('.striped-table tr:odd').addClass('odd')
    $('.gridview-table tr:first-child').addClass('firstHead')
    $('.striped-table tr:first-child').addClass('firstHead')

    //================= News Date Styling  =====================

//    $('.articleContent').each(function () {
//        var dateStr = $(this).find('span.teasertext').html();
//        $(this).find('span.teasertext').next('p').prepend(dateStr);
//        $(this).find('span.teasertext').hide();

    //    });

        $('.articleContent').each(function () {
            $('<br/><br/>').insertAfter('.articleContent p');

        });
    //================= UI level Script: Featured Content grid =====================

    $("div.featuredContent li:odd").addClass('noMargin');


    //================= Generic Snippet =====================
    var snippetImgWidth = $('.generic-snippet img').width()
    snippetImgWidth += 'px'
    $('.snippet-text').css('width', snippetImgWidth)


    //================= UI level Script: Membership Steps =====================

    $("ul.membershipSteps li:last").addClass('noPadding');

    $("div.searchDetail:last").addClass('searchDetailLast')


    //================= Equal Heights =====================
    var currentTallest = 0;

    $('.textdwnldTabs li').each(function () {
        if ($(this).find('a span').height() >= currentTallest) {
            currentTallest = $(this).height();
        }
    });
    $('.textdwnldTabs li a span').css('height', currentTallest)

    var currentTallestDown = 0;

    $('.dwnldTabs li').each(function () {

        if ($(this).find('a span').height() > currentTallestDown) { currentTallestDown = $(this).height(); }
        $('.dwnldTabs li a span').css('height', currentTallestDown)

    });

    //================= Right Column Resourse slider =====================

    var imgWid = $('.sliderCont li').width();
    var imgLeng = $('.sliderCont li').length
    $('.sliderCont ul').css('width', imgWid * imgLeng)

    $('.scroller a.next').click(function (ev) {
        ev.preventDefault();
        if ($('.sliderCont ul:animated').length == 0)
            var margCurr = parseInt($('.sliderCont ul').css('margin-left'))
        if (margCurr >= -($('.sliderCont li').length - 2) * 200)
            $('.sliderCont ul').animate({
                "margin-left": (margCurr - 167)
            })
    });

    $('.scroller a.prev').click(function (ev) {
        ev.preventDefault();
        if ($('.sliderCont ul:animated').length == 0)
            var margCurr = parseInt($('.sliderCont ul').css('margin-left'))
        if (margCurr != 0)
            $('.sliderCont ul').animate({
                "margin-left": (margCurr + 167)
            })
    });



});

//================= Homepage Tab Slider =====================

//array to store IDs of our tabs
var tabs = [];
//index for array
var ind = 0;
//store setInterval reference
var inter;

//change tab and highlight current tab title
function change(stringref) {
    //hide the other tabs
    jQuery('.tab:not(#' + stringref + ')').hide();
    //show proper tab, catch IE6 bug
    if (jQuery.browser.msie && jQuery.browser.version.substr(0, 3) == "6.0")
        jQuery('.tab#' + stringref).show();
    else
        jQuery('.tab#' + stringref).fadeIn();
    //clear highlight from previous tab title
    jQuery('.tabs a:not(#' + stringref + 't)').removeClass('select');
    //highlight currenttab title
    jQuery('.tabs a[href=#' + stringref + ']').addClass('select');
}
function next() {
    //call change to display next tab
    change(tabs[ind++]);
    //if it's the last tab, clear the index
    if (ind >= tabs.length)
        ind = 0;
}


jQuery(document).ready(function () {
    //store all tabs in array
    jQuery(".tab").map(function () {
        tabs[ind++] = jQuery(this).attr("id");
    })
    //set index to next element to fade
    ind = 1;
    //initialize tabs, display the current tab
    jQuery(".tab:not(:first)").hide();
    jQuery(".tab:first").show();
    //highlight the current tab title
    jQuery('#' + tabs[0] + 't').addClass('select');
    //handler for clicking on tabs
    jQuery(".tabs a").click(function () {

        //if tab is clicked, stop rotating 
        clearInterval(inter);
        //store reference to clicked tab
        stringref = jQuery(this).attr("href").split('#')[1];
        //display referenced tab
        change(stringref);
        return false;
    });
    //start rotating tabs
    inter = setInterval("next()", 5000);
});


//================= Download Page Tabs =====================
$(document).ready(function () {
    $("ul.dwnldTabs li a").click(function (e) {
        e.preventDefault();
    })

    //When page loads...
    $(".tab_content").hide(); //Hide all content
    $("ul.dwnldTabs li:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.dwnldTabs li").click(function (e) {
        e.preventDefault();
        $("ul.dwnldTabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("class"); ; //Find the href attribute value to identify the active tab + content				
        activeTab = $.trim(activeTab);
        $('div.' + activeTab).fadeIn(); //Fade in the active ID content
    });





    //When page loads...
    $(".texttab_content").hide(); //Hide all content
    $("ul.textdwnldTabs li:first").addClass("active").show(); //Activate first tab
    $(".texttab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.textdwnldTabs li").click(function (event) {
        event.preventDefault();
        $("ul.textdwnldTabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".texttab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("class"); ; //Find the href attribute value to identify the active tab + content				
        activeTab = $.trim(activeTab);
        $('div.' + activeTab).fadeIn(); //Fade in the active ID content
    });

    $("ul.textdwnldTabs li a").click(function (event) {
        event.preventDefault();
    })



    //================= Drop Down Menu =====================
    $('.DDMenu').hide();
    //    $('ul.main li').mouseover(function(){
    //        $(this).find('span.DDMenu').css('display','block')
    //    });
    //    $('ul.main li').mouseout(function(){
    //        $(this).find('span.DDMenu').css('display','none')
    //    });

    $('ul.main li').hover(
        function () {
            $(this).find(".DDMenu:hidden").slideDown(300);
            $(this).addClass("imgD")
        },
        function () {
            $(this).find(".DDMenu:visible").fadeOut(300);
            $(this).removeClass("imgD")
            $.clearQueue();
        });

});


$(document).ready(function () {

    $("a.mainNav").hover(function () {
        var img = $(this).find("img");
        var Imgsrc = "/images/AAD/menu-icon2.png"
        img.attr("src", Imgsrc);
        img.addClass("downarow");

    }, function () {
        var img = $(this).find("img");
        var Imgsrc2 = "/images/AAD/menu-icon1.png"
        //  alert(Imgsrc2);
        img.attr("src", Imgsrc2);
        img.removeClass("downarow");
    });

    $('ul.featured-list-ul li:even').addClass('even');
    $('ul.featured-list-ul li:odd').addClass('odd');

    $('ul.featured-list-ul li:even').each(function () {
        var evenHeight = $(this).height();

        var oddHeight = $(this).next('.odd').height();

        if (evenHeight > oddHeight) { $(this).css('min-height', evenHeight); $(this).next('.odd').css('min-height', evenHeight) }
        if (evenHeight < oddHeight) { $(this).css('min-height', oddHeight); $(this).next('.odd').css('min-height', oddHeight) }
    });

    $('div.products-col div.box-prod:even').addClass('even');
    $('div.products-col div.box-prod:odd').addClass('odd');

    $('div.products-col div.box-prod:even').each(function () {
        var evenHeight = $(this).height();

        var oddHeight = $(this).next('.odd').height();

        if (evenHeight > oddHeight) { $(this).css('min-height', evenHeight); $(this).next('.odd').css('min-height', evenHeight) }
        if (evenHeight < oddHeight) { $(this).css('min-height', oddHeight); $(this).next('.odd').css('min-height', oddHeight) }
    });
});

$(window).load(function () {

    //================= Generic Snippet =====================
    //    var snippetImgWidth = $('.generic-snippet img').width();
    //    snippetImgWidth += 'px';
    //    $('.snippet-text').css('width', snippetImgWidth);

    $('.snippet-block').each(function () {
        var snippetImgWidth = $(this).find('.generic-snippet img').width();
        snippetImgWidth += 'px';
        $(this).find('.snippet-text').css('width', snippetImgWidth);
    }
    );

}) 
// Image Mouseover script
$(document).ready(function(){
   $(".box-prod").hover(
    function() {
    $(this).find("img.a").stop().animate({"opacity": "0"}, "fast");
    },
    function() {
    $(this).find("img.a").stop().animate({"opacity": "1"}, "fast");
    });
});
 

//================= jPlayer integration =====================
$(document).ready(function () {
	if (jQuery().jPlayer && $(".jplayer").length) {
		$(".jplayer").jPlayer({ 
			ready: function () {
				$(this).jPlayer("setMedia", {
					mp3: $(this).attr("data-mp3-url"),
					oga: $(this).attr("data-ogg-url"),
					m4a: $(this).attr("data-m4a-url")
				});
			}, 

			swfPath: "http://www.aad.org/js/jplayer/",
			supplied: "mp3, oga, m4a"
		});
	}
});


