// ------------------------ // FUNCTIONS // ------------------------ // PRELOAD IMAGES if (document.images){ pic1= new Image(778,515); pic1.src="http://espndeportes-assets.espn.go.com/i/espndeportesplayer/skin_deportes_live2.gif"; pic2= new Image(778,515); pic2.src="http://espndeportes-assets.espn.go.com/i/espndeportesplayer/skin_podcenter_dep2.gif"; pic3= new Image(778,515); pic3.src="http://espndeportes-assets.espn.go.com/i/espndeportesplayer/skin_more.gif)"; pic4= new Image(778,515); pic4.src="http://espndeportes-assets.espn.go.com/i/espndeportesplayer/skin_deportes_live2.gif"; } function addEvent(obj, evType, fn){ if (obj.addEventListener){ obj.addEventListener(evType, fn, false); return true; } else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r; } else { return false; } } function rescaleApp(){ window.resizeTo(masterWidth,masterHeight); } function populateStations(st,loadFirstStation, loadnum){ var param = ''; if ( st.toLowerCase() != 'all' ){ param = '?state='+st.toLowerCase(); } stationsXML = '/espndeportesradio/player/stations.xml'+param; // PULL IN STATIONS $.ajax({ url: stationsXML, type: 'GET', dataType: 'xml', timeout: 3000, error: function(){ errorWithRequest('loadingbox') }, success: function(xml){ // WEBCAM LOCKED NATIONAL //if ( getCurrentTab() == 'tLive' ){ $('#stations').html(''); //} else if ( getCurrentTab() == 'tWebcams' ){ // $('#wc_stations').html(''); //} count = 0; $(xml).find('station').each(function(){ if ( $(this).attr('state') == st || st == 'all' ){ sel = ''; // IF FIRST PARSE if ( count == 0 ){ // IF WE'RE LOADING THE CURRENT STATION if ( loadFirstStation && ((loadnum == -1) || (loadnum == 0)) ){ // BUILD INFO BOX //log ($(this).attr('location')); getAndBuildInfo($(this).attr('location'), true); } else { // APPEND TO APPROPRIATE SELECT // WEBCAM LOCKED NATIONAL //if ( getCurrentTab() == 'tLive' ){ $('#stations').append(''); //} else if ( getCurrentTab() == 'tWebcams' ){ // $('#wc_stations').append(''); //} } } else if (loadnum > -1) { if ( count == loadnum ){ getAndBuildInfo($(this).attr('location'), true); sel = 'selected' } } // APPEND OPTIONS TO APPROPRIATE SELECT ELEMENT // WEBCAM LOCKED NATIONAL //if ( getCurrentTab() == 'tLive' ){ $('#stations').append(''); //} else if ( getCurrentTab() == 'tWebcams' ){ $('#wc_stations').append(''); //} count++; } }); $('#stations').attr({ disabled: false }); // WEBCAM LOCKED NATIONAL // $('#wc_stations').attr({ disabled: false }); } }); } function errorWithRequest(elemnt){ //$('#'+elemnt).html('Hubo un error procesando su petición. Click aquí para reintentar'); $('#'+elemnt).html('Hubo un error procesando su petición. Intente de nuevo'); } function swapStation(){ $('#thumbImg').hide(); $('#showbox').hide(); $('#loadingbox').show(); $('#selecthelp').hide(); if ( getCurrentTab() == 'tWebcams' ){ stationXML = $('#wc_stations').val(); } else { stationXML = $('#stations').val(); } // AD HANDLE eq = stationXML.indexOf('='); adName = stationXML.substring(eq+1); grabAd('live', adName); if ( stationXML != '' ){ $.ajax({ url: stationXML, type: 'GET', dataType: 'xml', timeout: 3000, error: function(){ errorWithRequest('loadingbox') }, success: function(xml){ $(xml).find('station').each(function(){ var vars = $(this).attr('callsign'); $('#blurb').html($(this).attr('blurb')); rebuildPlayer(vars,true); // IMAGES $(this).find('images').each(function(){ $(this).find('header').each(function(){ setStationHeaderImage($(this).attr('value')); }); $(this).find('generic').each(function(){ setGeneric90Img($(this).attr('value')); }); if ( getCurrentTab() != 'tWebcams' ){ $(this).find('background').each(function(){ setStationLiveBgnd($(this).attr("value")); }); } }); $('#blurb').html($(this).attr('blurb')); parseBuildInfo(xml); }); } }); } } function getAndBuildInfo(loc, loadFirstStation){ $.ajax({ url: loc, type: 'GET', dataType: 'xml', timeout: 3000, error: function(){ log('error getting xml.'); }, success: function(xml){ // LOAD FIRST STATION IN DROP DOWN if ( loadFirstStation ){ var vars = $(xml).find('station').attr('callsign'); $('#blurb').html($(xml).find('station').attr('blurb')); rebuildPlayer(vars,true); // IMAGES $(xml).find('station').find('images').each(function(){ $(this).find('header').each(function(){ setStationHeaderImage($(this).attr('value')); }); $(this).find('generic').each(function(){ setGeneric90Img($(this).attr('value')); }); $(this).find('background').each(function(){ if ( getCurrentTab == 'tLive' ){ setStationLiveBgnd($(this).attr("value")); } }); }); } // BUILD INFO $('#blurb').html($(xml).find('station').attr('blurb')); parseBuildInfo(xml); } }); } function parseBuildWebcams(){ $.ajax({ url: '/espndeportesradio.xml', type: 'GET', dataType: 'xml', timeout: 3000, error: function(){ log('error getting xml.'); }, success: function(xml){ count = 0; var found = false; currentId = -1; /*if ( getCurrentTab() == 'tWebcams' ){ setWebcamUrl('http://query-origin.andohs.net/8000A6/content-root3.andomedia.com/origin/wm/asx/webcams.asx'); } else { setWebcamUrl(''); }*/ $('#webcamScroll').html(''); $(xml).find('day').each(function(){ today = $(this).attr("value"); if ( $(this).attr("value").toLowerCase() == getCurrentDay().toLowerCase() || found ){ $(this).find('show').each(function(){ ems = parseInt(getETimeMS()); // local time - client side ms = parseInt(getTimeMS()); //ms = ms - timezone; var start = parseInt($(this).attr("startms")) + ems; var end = parseInt($(this).attr("endms")) + ems; if ( $(this).attr('multiday') == 'true' ){ end = end + 86400000; } //log('time: '+start+' < '+ms+' < '+end); if ( ms >= start && (ms < end ) && !found ){ currentId = $(this).attr('id'); found = true; } if ( currentId >= $(this).attr('id') || found ){ found = true; // SHOW HAS WEBCAM if ( $(this).attr('webcam') == 'true' ){ // SHOW IS LIVE? var live = ''; var iborder = ''; if ( currentId == $(this).attr('id') ){ live = '' iborder = 'style="border: 2px solid #FF0000;"' } // TIME IF NOT LIVE if ( live == '' ){ live = webcamTime($(this).attr('start'), $(this).attr('end')); } // WEBCAM GRAPIC var wcImg = "http://assets.espn.go.com/i/espnradio/08/player/webcamNav_generic.jpg"; if ( $(this).attr('webcamGraphic') != '' && $(this).attr('webcamGraphic') != undefined ){ wcImg = $(this).attr('webcamGraphic'); } wcImg = ''; // UPDATE DOM var wcTitle = '

'+$(this).attr('name')+'

'+today+'
'+live+''; var htmlString = '
'+wcImg+'
'; $('#webcamScroll').html($('#webcamScroll').html()+htmlString+wcTitle); count = count + 1; } } }); } }); // SET THE NAV WIDTH var navWidth = (count * 172) + 7; if ( navWidth == 7 ){ // MSG IF NO MORE CAMS THIS WEEK navWidth = 179; var noneMsg = '
There are currently no webcams scheduled for this station. Tune in
next week for more live webcams!
'; $('#webcamScroll').html(noneMsg); //log('testB'); $('#webcamiframe').attr({src: 'webcamFrame?url=null' }); //log('testA'); } else { // SHOW WEBCAM FRAME, SET URL OF IFRAME if ( getCurrentTab() == 'tWebcams' ){ //$('#webcamiframe').attr({src: 'webcamFrame?url='+getWebcamUrl() }); nationalWebcam(); } //log('test2'); $('#webcamiframe').show(); } $('#webcamScroll').width(navWidth+'px'); //log('testC'); } }); } var webcamURL = null; function blankWebcam(){ $('#webcamiframe').attr({src: 'webcamFrame?url=null' }); } function nationalWebcam(){ $('#webcamiframe').attr({src: 'webcamFrame?url=http://query-origin.andohs.net/8000A6/content-root3.andomedia.com/origin/wm/asx/webcams.asx' }); } function setWebcamUrl(st){ webcamURL = st; } function getWebcamUrl(){ // WECAMS LOCKED NATIONAL return webcamURL; } function webcamTime(s,e){ pos = s.indexOf(':'); s.charAt(pos+1) > 0 ? s = s : s = s.substring(0,pos)+s.substring(pos+3); pos = e.indexOf(':'); e.charAt(pos+1) > 0 ? e = e : e = e.substring(0,pos)+e.substring(pos+3); return s+' - '+e+' ET'; } function parseBuildInfo(xml){ //var wcUrl = $(xml).find('station').attr('webcamStream'); var wcUrl = ''; // PULL SHOWS BY THE CORRECT DAY $(xml).find('schedule').each(function(){ var timezone = $(this).attr('timezone'); $(this).find('day').each(function(){ if ( $(this).attr("value").toLowerCase() == getCurrentDay().toLowerCase() ){ log('Today is '+$(this).attr("value")+'.'); nextShow=false; $(this).find('show').each(function(){ if ( nextShow ){ nextShowInfo($(this).attr('name'),$(this).attr('link')); nextShow = false; } ems = parseInt(getETimeMS()); // local time - client side ms = parseInt(getTimeMS()); //ms = ms - timezone; var start = parseInt($(this).attr("startms")) + ems; var end = parseInt($(this).attr("endms")) + ems; if ( $(this).attr('multiday') == 'true' ){ end = end + 86400000; } //log($(this).attr('name')+' - time: '+start+' < '+ms+' < '+end); if ( ms >= start && (ms < end) ){ //log('CURRENT SHOW-> '+$(this).attr('name')); $('#loadingbox').hide(); $('#selecthelp').hide(); $('#showbox').show(); setShowInfo($(this).attr('name'),$(this).attr('link')); setShowImage($(this).attr('graphic'),$(this).attr('link')); // not sure why this is setTimeout //timeout = setTimeout("countdown("+Math.abs((end - ms))+")", 1000); countdown(Math.abs((end - ms))); $('#showThumb').fadeIn('slow'); $('#showbox').fadeIn('slow'); $('#timeremain').fadeIn('slow'); // WEBCAMS CALL //if ( getCurrentTab() == 'tWebcams' ){ parseBuildWebcams(); //} nextShow = true; } }); } }); }); } function setShowImage(img, link){ //log('image: '+img); if ( img != null && img != '' ){ $('#thumbImg').hide(); if ( link != null ){ $('#thumbLink').attr({ onclick: "openURL('"+link+"');" }); } else { $('#thumbLink').attr({ onclick: "void(0);" }); } $('#thumbImg').attr({ src: img }); $('#thumbImg').fadeIn('slow'); } else { $('#thumbImg').hide(); } } function setShowInfo(showname, showlink){ //log('info: '+showname); $('#currentLink').hide(); if ( showlink != null ){ $('#currentLink').attr({ onclick: "openURL('"+showlink+"');" }); } else { $('#currentLink').attr({ onclick: "return false;" }); } $('#currentLink').html(showname); $('#currentLink').fadeIn('slow'); } function nextShowInfo(nextname, nextlink){ //log('next: '+nextname); $('#nextLink').hide(); if ( nextlink != null ){ $('#nextLink').attr({ onclick: "openURL('"+nextlink+"');" }); } else { $('#nextLink').attr({ onclick: "return false;" }); } $('#nextLink').html(nextname); $('#nextLink').fadeIn('slow'); } //helper function toSt(n) { s="" if(n<10) s+="0" return s+n.toString(); } function countdown(ms){ //log('countdown '+ms); count = Math.floor(ms / 1000); if (count > 0) { sec=toSt(count%60); count=Math.floor(count/60); min=toSt(count%60); count=Math.floor(count/60); hr=toSt(count%24); txt = hr + ":" + min + ":" + sec; $("#timeremain").html(txt); timeout = clearTimeout(timeout); timeout = setTimeout("countdown(" + (ms - 1000) + ")", 1000); } else { $('#timeremain').fadeOut('slow'); getAndBuildInfo($('#stations').val(), false); } } // FUNCTIONS FOR PLAYER function setStationHeaderImage(img){ $("#stationImage").attr({ src: img }); } function setStationLiveBgnd(img){ $('body').attr({ style: 'background: transparent url('+img+') no-repeat scroll 0% 0%;' }); } function setGeneric90Img(img){ generic90Img = img; } function getGeneric90Img(){ return generic90Img; } function getCurrentTab(){ return currentTab; } function setCurrentTab(tab){ currentTab = tab; } function getCurrentDay(){ days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); // SET DATE OBJECT TO GET SHOW SCHEDULE FOR TODAY onairdate = new Date(); onairdate.setHours(0); onairdate.setMinutes(0); onairdate.setSeconds(0); onairdate.setMilliseconds(0); mil = onairdate.getTime(); // Get Milliseconds since midnight Jan 1 1970 to onairdate tzone = onairdate.getTimezoneOffset(); // Minutes difference from GMT tzone >= 0 ? gmttime = mil - (tzone * 60 * 1000) : gmttime = mil + (tzone * 60 * 1000); // Convert tzone to GMT time in Milliseconds // ADJUST FOR DAYLIGHT SAVINGS TIME etimems = gmttime + 14400000; // Convert GMT time to eastern time in Milliseconds (DST) //etimems = gmttime + 18000000; // Convert GMT time to eastern time in Milliseconds // SET DATE AND GET CURRENT TIME EASTERN now = new Date(); nowmil = now.getTime(); nowtz = now.getTimezoneOffset(); nowtz >= 0 ? gmtnow = nowmil - (nowtz * 60 * 1000) : gmtnow = nowmil + (nowtz * 60 * 1000); // CONVERT TO DATE OBJECT enow = new Date(); enow.setTime(nowmil); eday = enow.getDay(); // Current day EST return days[eday]; } function getTimeMS(){ now = new Date(); nowmil = now.getTime(); nowtz = now.getTimezoneOffset(); nowtz >= 0 ? gmtnow = nowmil - (nowtz * 60 * 1000) : gmtnow = nowmil + (nowtz * 60 * 1000); return nowmil; } function getETimeMS(){ // SET DATE OBJECT TO GET SHOW SCHEDULE FOR TODAY onairdate = new Date(); onairdate.setHours(0); onairdate.setMinutes(0); onairdate.setSeconds(0); onairdate.setMilliseconds(0); mil = onairdate.getTime(); // Get Milliseconds since midnight Jan 1 1970 to onairdate tzone = onairdate.getTimezoneOffset(); // Minutes difference from GMT tzone >= 0 ? gmttime = mil - (tzone * 60 * 1000) : gmttime = mil + (tzone * 60 * 1000); // Convert tzone to GMT time in Milliseconds // ADJUST FOR DAYLIGHT SAVINGS TIME //etimems = gmttime + 14400000; // Convert GMT time to eastern time in Milliseconds (DST) etimems = gmttime + 18000000; // Convert GMT time to eastern time in Milliseconds return etimems; } function swapTab(c){ switch ( getCurrentTab() ) { case "tLive": stopStreaming(); $('#liveTab').hide(); $('#tabnav1').hide(); break; case "tCast": stopPodcast(); $('#podcastTab').hide(); $('#tabnav2').hide(); break; case "tMore": stopAudio(); $('#espnaudioTab').hide(); break; case "tWebcams": $('#webcamiframe').attr({src: 'webcamFrame?url=null' }); hideWebcams(); break; } var b = ""; tabs = new Array("tCast","tLive","tMore","tWebcams"); switch (c){ case "tCast": b="http://espndeportes-assets.espn.go.com/i/espndeportesplayer/skin_podcenter_dep2.gif"; $('#podcastTab').show(); $('#tabnav2').show(); trackPageView('podcenter'); break; case "tLive": b="http://espndeportes-assets.espn.go.com/i/espndeportesplayer/skin_deportes_live2.gif"; $('#liveTab').show(); $('#tabnav1').show(); trackPageView('live'); break; case "tMore": b="http://espndeportes-assets.espn.go.com/i/espndeportesplayer/skin_more.gif"; $('#espnaudioTab').show(); trackPageView('audio'); break; case "tWebcams": //$('#webcamiframe').attr({src: 'webcamFrame?url='+getWebcamUrl() }); nationalWebcam(); b="http://espndeportes-assets.espn.go.com/i/espndeportesplayer/skin_deportes_live2.gif"; showWebcams(); trackPageView('webcam'); break; default: b="http://espndeportes-assets.espn.go.com/i/espndeportesplayer/skin_deportes_live2.gif"; $('#liveTab').show(); $('#tabnav1').show(); trackPageView('live'); } try{ $('body').attr({ style: 'background: transparent url('+b+') no-repeat scroll 0% 0%;' }); $('#'+getCurrentTab()).removeClass("realm"); $('#'+c).toggleClass("realm"); } catch(e) { errorWithRequest('loadingbox') } setCurrentTab(c); } function log(err){ try { console.log(err); } catch (e) {} } function rebuildPlayer(vars, auto){ volume_param = ''; $('#tempControl').hide(); $('#streaming-player-home').show(); if ( getStreamVolume() > -1 ){ volume_param = '&vol='+getStreamVolume(); } streamingPlayer.flashVars=vars+volume_param; streamingPlayer.useDOM = true; streamingPlayer.targetElement = "streaming-player-home"; streamingPlayer.render(true); } function stationsByState(){ // WEBCAM LOCKED NATIONAL //if ( getCurrentTab() == 'tLive' ){ populateStations($('#states').val(), false, -1); //} else if ( getCurrentTab() == 'tWebcams' ){ // populateStations($('#wc_states').val(), false, -1); //} } /* HANDLERS */ $(function(){$('#stations').change(swapStation);}); $(function(){$('#states').change(stationsByState);}); // WEBCAM LOCKED NATIONAL // $(function(){$('#wc_stations').change(swapStation);}); // $(function(){$('#wc_states').change(stationsByState);}); // AD HANDLING function grabAd(type,name){ param = ''; if ( type == 'null' || type == null || name == 'undefined' || name == null || name == 'null' ){ type = ''; name = ''; } if ( type != '' ){ param = '?'+type+'='+name; } var url = 'http://sports.espn.go.com/espnradio/thisIsAnAd'+param // randomly generate a timeout time, THIS IS NEEDED? // time = (Math.floor(Math.random()*20) + 1); // adTimeout = setTimeout("delayAd('"+url+"')", time); externalAd(url); } /* function playStream(vars, auto){ if(vars != null ){ streamingPlayer.flashVars=vars+'&autoplay='+auto; streamingPlayer.useDOM = true; streamingPlayer.targetElement = "streaming-player-home"; streamingPlayer.render(true); clearTimeout(tmo); tmo = setTimeout(nextShow,1000); if (auto){ document.getElementById('liveiframe').style.display = 'none'; document.getElementById('liveFrame').style.display = 'none'; document.getElementById('streaming-player-home').style.display = 'block'; document.getElementById('swap').innerHTML = 'Flash | Windows Media'; } } } */ // ------------ // Links, Ads // ------------ function openURL(url){ var newWindowHeight = 500; var openedWindow = null; if(screen.availHeight){ newWindowHeight = screen.availHeight; } var newWindowWidth = 1024; if(screen.availHeight && screen.availHeight<1024){ newWindowWidth = screen.availHeight; } if(opener){ try{ openedWindow=opener.window.open(url); } catch (e) { window.open(url, 'newWindow', 'status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1,scrollbars=1,top=0,left=0,height='+newWindowHeight+',width='+newWindowWidth); } } else{ try{ openedWindow=window.open(url, 'newWindow', 'status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1,scrollbars=1,top=0,left=0,height='+newWindowHeight+',width='+newWindowWidth); } catch (e) { window.open(url, 'newWindow', 'status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1,scrollbars=1,top=0,left=0,height='+newWindowHeight+',width='+newWindowWidth); } } if(openedWindow){ try{ openedWindow.focus(); } catch (e) { } } } function trackPageView(tab){ if ( tab == 'live' ){ if ( currentStation == 'chicago'){ tab = 'espnradio1000:live'; prop5 = 'stations:espnradio1000'; } else if (currentStation == 'dallas'){ tab = 'espn1033:live'; prop5 = 'stations:espnradio1033'; } else if (currentStation == 'la'){ tab = '710espn:live'; prop5 = 'stations:710espn'; } else if (currentStation == 'nyc'){ tab = '1050espnradio:live'; prop5 = 'stations:1050espnradio'; } else if (currentStation == 'pittsburgh'){ tab = 'espnradio1250:live'; prop5 = 'stations:espnradio1250'; } else if (currentStation == 'espnradio'){ tab = "live"; prop5 = 'player'; } else { tab = currentStation+':live'; prop5 = 'player'; } } try { anClearVars(); s_omni.pageName="espnradio:espnradio:player:"+tab s_omni.server = window.location.host s_omni.channel = "espnradio" s_omni.prop1 = "espnradio" s_omni.prop5 = 'espnradio:'+prop5; s_omni.prop17 = "en" s_omni.prop25 = "none" s_omni.prop30 = "n" s_omni.hier1 = 'espnradio:'+prop5; var s_code=s_omni.t();if(s_code)document.write(s_code) } catch (e) {} } // ------------------------- // NEW AD HANDLE FROM FLASH // ------------------------- function externalAd(url){ if ( url.indexOf('null') > -1 || url == null ){ url = "http://sports.espn.go.com/espnradio/thisIsAnAd"; } $("#adFrame").hide(); $("#adFrame").attr({ src: url }); $("#adFrame").fadeIn('slow'); } // ------------- // Swap Helpers // ------------- function hideWebcams(){ $('#scoreboard').show(); $('#headlines').show(); $('#webcamsTab').hide(); $('#webcamFrame').hide(); $('#webcamiframe').hide(); $('#webnav').hide(); } function showWebcams(){ $('#scoreboard').hide(); $('#headlines').hide(); $('#webcamsTab').show(); $('#webcamFrame').show(); $('#webcamiframe').show(); $('#webnav').show(); } // --------- // Scroll // --------- var scrollInterval = null; function startScroll(direction, ivl) { if (direction == "left"){ x = -5 - ivl document.getElementById("webnavContainer").scrollLeft += x } else if (direction == "right"){ x = 5 + ivl document.getElementById("webnavContainer").scrollLeft += x } else if (direction == "up"){ y = -5 - ivl document.getElementById("headlinesScroll").scrollTop += y } else{ y = 5 + ivl document.getElementById("headlinesScroll").scrollTop += y } newInterval = ivl + 1 var functionCall = "startScroll(\"" + direction + "\", " + newInterval + ")" scrollInterval = setTimeout(functionCall, 50) return false; } function endScroll() { if (scrollInterval != null){ scrollInterval = clearTimeout(scrollInterval) } return false; } /* function trackPageView(){ // do nothing for now } */ // --------------- // FLASH FUNCTIONS // --------------- // this one works function stopStreaming() { try{ getFlashMovie("streamingPlayer").callTurnOff(); //log('successfully turned off streaming with js call to flash'); } catch (e) {} } // VOLUME TO PASS INTO FLASH var stream_vol = -1; function setStreamVolume(vol) { stream_vol = vol; try{ getFlashMovie("streamingPlayer").callSetStreamVolume(vol); //log('successfully set the volume with js call to flash'); } catch (e) {} } function getStreamVolume() { return stream_vol; } // VOLUME TO PASS INTO FLASH var podcast_vol = null; function setPodcastVolume(vol) { podcast_vol = vol; } function getPodcastVolume() { return podcast_vol; } // ESPN Standard function getFlashMovie(flashObjName){ if( window.document[flashObjName] ){ return window.document[flashObjName]; } if( navigator.appName.indexOf("Microsoft Internet") == -1 ){ if( document.embeds&&document.embeds[flashObjName] ){ return document.embeds[flashObjName]; } } else { return document.getElementById(flashObjName); } }