﻿
$(document).ready(function() {

    //    var curr_fact_id = 1;
    //    var total = $('.scrollWrapper li').size();
    //    var isAnimating = true;
    //    $(".componentFactOfWeek").everyTime(4000, function(i) {
    //        //i = i % (total);

    //        if (curr_fact_id > total) {
    //            curr_fact_id = 1;
    //            $(".scrollWrapper ul").animate({ right: '-=720px' }, 1000);
    //        }
    //        else {
    //            //if (!isAnimating)
    //                $(".scrollWrapper ul").animate({ right: '+=240px' }, 1000);

    //            curr_fact_id++;
    //            //isAnimating = true;
    //        }
    //        //        $(".scrollWrapper ul").animate({ right: '+=240px' }, 1000);
    //        //        curr_fact_id++;
    //        //console.log(curr_fact_id);

    //        //$(this).html(i);
    //    });

    var heroBanners = {
        aboutus: 1,
        contact: 2,
        expertise: 2,
        home: 6,
        newsmedia: 2,
        people: 2,
        publications: 2,
        careers:2,
        random: 5
    };

    //tTwoColumns Subpage Hero
    var totalHeroes = 1,
    tempSrc = "";

    var $banner = $('#subpageHeroes .banner'),
    bannerTimeout = 8000,
    delayTimeout = 3000,
    bannerClass = "";

    if ($banner.length == 0) {
        //try to see if this is homepage banner
        $banner = $('#homepageBanner');
        bannerTimeout = 5000;
    }
    
    if ($banner.length > 0) {
        bannerClass = $banner.attr('class').replace('banner ', '');
        totalHeroes = heroBanners[bannerClass];
        delayTimeout = totalHeroes * 1000;
        if (totalHeroes == 1) {
            //leave it
        }
        else if (totalHeroes > 1) {
            for (var i = 1; i < totalHeroes; i++) {
                $banner.append('<img src="/images/SubpageHero/' + bannerClass + '/' + i + '.jpg" />');
            }

            setTimeout(function() {
                $banner.cycle({ fx: 'fade', speed: 1000, timeout: bannerTimeout });
            }, delayTimeout);
        }
        else {
            //show random image
            var randomImage = Math.round(Math.random() * heroBanners["random"]);
            $banner.html('<img src="/images/SubpageHero/random/' + randomImage + '.jpg" />');            
        }
    }

    if ($('.scrollWrapper').length > 0) {
        $('.scrollWrapper').cycle({ fx: 'scrollLeft', timeout: 8000 });
    }

    $('.componentSitemap ul li').each(function() {
        var exp = $('.componentSitemap div.expertise');
        var staff = $('.componentSitemap div.people');
        var pub = $('.componentSitemap div.publication');
        var career = $('.componentSitemap div.careers');
        
        if ($(this).attr('title') == $('.componentSitemap div.expertise').attr('title')) {
            $(this).after(exp.html())
            exp.remove();
        }
        if ($(this).attr('title') == $('.componentSitemap div.people').attr('title')) {
            $(this).hide();
        }
        // if ($(this).attr('title') == $('.componentSitemap div.people').attr('title')) {
        // $(this).after(staff.html())
        // staff.remove();
        // }
        if ($(this).attr('title') == $('.componentSitemap div.publication').attr('title')) {
            $(this).after(pub.html())
            pub.remove();
        }

        if ($(this).attr('title') == $('.componentSitemap div.careers').attr('title')) {
            $(this).after(career.html())
            career.remove();
        }
    });

    $('.staffList:first div:first').after("<div style='font-size: 1.2em;'><a href='/david-kearney.aspx'><img src='/images/message.png' title='a message from the managing partner'/></a></div>");

    $('.componentPublication').find('div.item:last').addClass('last');
    $('.componentExpertise').find('div.item:last').addClass('last');
    $('.componentStaff').find('div.staffList:last').addClass('last');
    
    /*
    if ($('.containerLeftColumn .componentMedia').size() > 0) {
    $('h1#banner').addClass('news');
    }
	
    $(".componentHomeFlash h1 a").flash(
    {width:950, height:284, autoplay:true, wmode: 'transparent'},
    {},
    function(htmlOptions) {
    $this = $(this);
    htmlOptions.src = $this.attr('href');
    $this.before($.fn.flash.transform(htmlOptions));						
    }
    );
    */
});

