/**
 * @author jwhitcraft
 */

function openLiveTimingScoring(e) {
    try {
        var event = e || window.event;
        event.preventDefault();
    } catch(err) {}
    var win = window.open("http://scoring.indycar.com/flash/?site=ims","timing","top=100,left=100,width=1000,height=730,resizable=no");
}

function setLeadClip(clip) { Ext.fly('lead_stories_image').addClass(clip); }
function removeLeadClip(clip) { Ext.fly('lead_stories_image').removeClass(clip); }
function pauseTimer() { Ext.fly('newsswitcher').dom.pauseTimer(); }

function timerComplete(type) {
    if(type == "next") {
        _curStory++;
        if(_curStory > (_stories.length-1)) _curStory = 0;
    } else {
        _curStory--;
        if(_curStory < 0) _curStory = (_stories.length-1);
    }
    switchStory();
}

function switchStory() {
    var s = _stories[_curStory];

    var _copy = Ext.fly('lead_stories_copy_inner');
    _copy.child('h1').update(s.headline);
    _copy.child('div').update(s.blurb);

    if(Ext.fly('lead_stories_image').hasClass('leadclip')) {
        removeLeadClip('leadclip');
        removeLeadClip('ts_leadclip');
        removeLeadClip('chat_leadclip');
    }
    var flashvars = {};
    var width = 574;
    var height = 323;

    if(s.type_id == 19 || s.type_id == 24) {
        width = 900;
        height = 696;
        if(s.type_id == 24) {
            var flashvars = _RMFlashVars;
        }
    }
    if (Ext.fly('flashLeadContainer') == null) {
        Ext.DomHelper.insertFirst('lead_stories_image_inner', {
            id: 'flashLeadContainer',
            tag: 'div'
        });
    }
    swfobject.removeSWF('leadStorySwf');

    if(s.showmorelink == "yes") {
        flashvars.linkurl = s.link
    }
    var attributes = {};
    var params = {};
    params.wmode = "transparent";
    params.allowScriptAccess = "sameDomain";
    attributes.id = "leadStorySwf";
    swfobject.embedSWF(s.img_path, "flashLeadContainer", width, height, "9.0.115", false, flashvars, params, attributes);

    Ext.fly('newsswitcher').dom.resetTimer();
}

function addDesignClip(e) {
    try {
        var event = e || window.event;
        event.preventDefault();
    } catch(err) {}

    Ext.fly("designit_container_clip").replaceClass("designit_no_clip", "designit_clip");
}

function removeDesignClip(e) {
    try {
        var event = e || window.event;
        event.preventDefault();
    } catch(err) {}

    Ext.fly("designit_container_clip").replaceClass("designit_clip", "designit_no_clip");
}

function gotoURL(url)
{
    document.location.href = url;
}

Ext.onReady(function(){
    var els = Ext.select('#sidebar_tabs_inner li');
    els.addClassOnOver('hover');
    els.addListener('click', function(e) {
        if(e.getTarget().id != active_tab) {
            try {
                pageTracker._trackPageview('/tabchange/' + e.getTarget().id);
            } catch (e) {}
            var el = e.getTarget(null, null, true);
            Ext.fly(active_tab).removeClass('active');
            Ext.fly(active_tab+'_content').removeClass('tc_active');
            el.addClass('active');
            Ext.fly(el.id+'_content').addClass('tc_active');
            active_tab = el.id;
        }
    });

    var flashvars = {};
    var params = {};
    params.wmode = "transparent";
    params.allowScriptAccess = "sameDomain";
    var attributes = {};
    attributes.id = "newsswitcher";
    swfobject.embedSWF("/images/homepage/newsswitcher.swf", "nhc_replace", "110", "30", "9.0.115", false, flashvars, params, attributes);

    var flashvars = {};
    var params = {};
    params.wmode = "transparent";
    var attributes = {};
    attributes.id = "sponsor_bar";
    swfobject.embedSWF("/images/flash/sponsor_bar.swf?v=1.0.1", "sb_container", "900", "42", "9.0.0", false, flashvars, params, attributes);
});


