/*ARTICLE YWA*/
var YWATracker = YWA.getTracker("10001399099462"); // YAHOO EDUCATION

function captureWizardOnclick(type,position) {
    YWATracker.setAction("02");
    YWATracker.setCF(17,type);
    YWATracker.setCF(29,position);
    YWATracker.submit_action(); 
}
function captureRelatedOnclick(type,position) {
    YWATracker.setAction("03");
    YWATracker.setCF(17,type);
    YWATracker.setCF(29,position);
    YWATracker.submit_action(); 
}
function captureExternalOnclick(type,position) {
    YWATracker.setAction("04");
    YWATracker.setCF(17,type);
    YWATracker.setCF(29,position);
    YWATracker.submit_action(); 
}

$(document).ready(function() {

    YWATracker.setDocumentGroup("Article");
    
    var YWAArticleVersion = $('input#YWAArticleVersion').val();
    YWATracker.setCF(1,YWAArticleVersion);
    YWATracker.submit();

    // ARTICLE LINK
    $('span#article-text a.title').each(function(index) {
        $(this).click(function() {
            captureWizardOnclick('Title',index+1);
        });
    });
    $('span#article-text a.cta').each(function(index) {
        $(this).click(function() {
            captureWizardOnclick('CTA',index+1);
        });
    });
    $('span#article-text a.related-degrees').each(function(index) {
        $(this).click(function() {
            captureWizardOnclick('Related Degrees',index+1);
        });
    });
    
    // WIDGET LINK
    $('span#article-text form').each(function(index) {
        $(this).submit(function() {
            captureWizardOnclick('Widget Inline',index+1);
        });
    });
    
    // NEXT ARTICLE LINK
    $('span#article-text a.next-article').each(function(index) {
        $(this).click(function() {
            captureRelatedOnclick('Next Article',index+1);
        });
    });
    
    // EXTERNAL LINK
    $('span#article-text a.external').each(function(index) {
        $(this).click(function() {
            captureExternalOnclick('Inline External',index+1);
        });   
    });
});

/* FAS */
$(document).ready(function() {

    var vipToProdid = {3000:600,1000:601,10000:602,11000:611,6000:603,8000:610,2000:601,5000:605,9000:607,4000:608,7000:606}

    $('body').append('<div id="bwfasgrey" style="position: fixed; top: 0; left: 0; opacity: 0.6; z-index: 5; background: #000; display: none;"></div>')
    $('body').append('<div id="bwfas" style="position: fixed; width: 940px; z-index: 10; display: none;"></div>')

    $('.bwfasclose').live('click',function() {
        $('#bwfas').fadeOut('normal');
        $('#bwfasgrey').hide();
    });
    $('span#article-text a.title,span#article-text a.cta').each(function(index) {
        $(this).click(function() {
            var split = Math.ceil(Math.random()*10);
            if (split<=2 || window.location.search.substring(1).match(/yahoofas/)!=null) {
                $(this).attr('target','_blank');
                var u = $(this).attr('href');
                id = u.match(/programCategoryId=(\d+)/)[1];
                if (id && vipToProdid[id]) {
                    $('#bwfasgrey').width($(window).width()).height($(window).height());
                    $('#bwfasgrey').show();
                    $('#bwfas').height($(window).height()-80).css('top',20).css('left',$(window).width()/2-470);
                    $('#bwfas').html('<div class="bwfasclose" style="background-color: #000; color: #fff; float: right; margin-right: 20px; clear: both; padding: 8px 10px; font-weight: bold; font-size: 14px; cursor: hand; cursor: pointer;">Close window</div><iframe src="http://i.vantage-media.net/e/portals/yep/fas.html?prodid='+vipToProdid[id]+'" style="border: none; width: 940px; height: 100%;"></iframe>');
                    $('#bwfas').fadeIn('normal');
                }
            }
        });
    });
});

