/* jQuery Coda-Slider v2.0 - http://www.ndoherty.biz/coda-slider Copyright (c) 2009 Niall Doherty This plugin available for use in all personal or commercial projects under both MIT and GPL licenses. */ /* Modification history: Jenny Ho @20100517 - to change the style for external trigger also when clicked Jenny Ho @20100705 - to change to load the relatived div after external trigger */ $(function(){ // Remove the coda-slider-no-js class from the body $("body").removeClass("coda-slider-no-js"); // Preloader $(".coda-slider").children('.panel').hide().end().prepend('

Loading...
loading...

'); }); var sliderCount = 1; $.fn.codaSlider = function(settings) { settings = $.extend({ autoHeight: true, autoHeightEaseDuration: 1000, autoHeightEaseFunction: "easeInOutExpo", autoSlide: false, autoSlideInterval: 7000, autoSlideStopWhenClicked: true, crossLinking: true, dynamicArrows: true, dynamicArrowLeftText: "« left", dynamicArrowRightText: "right »", dynamicTabs: true, dynamicTabsAlign: "center", dynamicTabsPosition: "top", externalTriggerSelector: "a.xtrig", firstPanelToLoad: 1, panelTitleSelector: "h2.title", slideEaseDuration: 1000, slideEaseFunction: "easeInOutExpo" }, settings); return this.each(function(){ // Uncomment the line below to test your preloader // alert("Testing preloader"); var slider = $(this); // If we need arrows if (settings.dynamicArrows) { slider.parent().addClass("arrows"); slider.before('
' + settings.dynamicArrowLeftText + '
'); slider.after('
' + settings.dynamicArrowRightText + '
'); }; var panelWidth = slider.find(".panel").width(); var panelCount = slider.find(".panel").size(); var panelContainerWidth = panelWidth*panelCount; var navClicks = 0; // Used if autoSlideStopWhenClicked = true var panelLoaded = new Array(panelCount+1); // Surround the collection of panel divs with a container div (wide enough for all panels to be lined up end-to-end) $('.panel', slider).wrapAll('
'); // Specify the width of the container div (wide enough for all panels to be lined up end-to-end) $(".panel-container", slider).css({ width: panelContainerWidth }); // Specify the current panel. // If the loaded URL has a hash (cross-linking), we're going to use that hash to give the slider a specific starting position... if (settings.crossLinking && location.hash && parseInt(location.hash.slice(1)) <= panelCount) { var currentPanel = parseInt(location.hash.slice(1)); var offset = - (panelWidth*(currentPanel - 1)); $('.panel-container', slider).css({ marginLeft: offset }); // If that's not the case, check to see if we're supposed to load a panel other than Panel 1 initially... } else if (settings.firstPanelToLoad != 1 && settings.firstPanelToLoad <= panelCount) { var currentPanel = settings.firstPanelToLoad; var offset = - (panelWidth*(currentPanel - 1)); $('.panel-container', slider).css({ marginLeft: offset }); // Otherwise, we'll just set the current panel to 1... } else { var currentPanel = 1; }; /**Added by Jenny Ho @20100705 **************************/ //alert("at first:"+currentPanel); var moveRandom = Math.floor(Math.random()*7); loadPanel(currentPanel, moveRandom); /***********************************************/ // Left arrow click $("#coda-nav-left-" + sliderCount + " a").click(function(){ navClicks++; if (currentPanel == 1) { offset = - (panelWidth*(panelCount - 1)); alterPanelHeight(panelCount - 1); currentPanel = panelCount; slider.siblings('.coda-nav').find('a.current').removeClass('current').parents('ul').find('li:last a').addClass('current'); } else { currentPanel -= 1; alterPanelHeight(currentPanel - 1); offset = - (panelWidth*(currentPanel - 1)); slider.siblings('.coda-nav').find('a.current').removeClass('current').parent().prev().find('a').addClass('current'); }; $('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction); if (settings.crossLinking) { location.hash = currentPanel; }; // Change the URL hash (cross-linking) return false; }); // Right arrow click $('#coda-nav-right-' + sliderCount + ' a').click(function(){ navClicks++; if (currentPanel == panelCount) { offset = 0; currentPanel = 1; alterPanelHeight(0); slider.siblings('.coda-nav').find('a.current').removeClass('current').parents('ul').find('a:eq(0)').addClass('current'); } else { offset = - (panelWidth*currentPanel); alterPanelHeight(currentPanel); currentPanel += 1; slider.siblings('.coda-nav').find('a.current').removeClass('current').parent().next().find('a').addClass('current'); }; $('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction); if (settings.crossLinking) { location.hash = currentPanel }; // Change the URL hash (cross-linking) return false; }); // If we need a dynamic menu if (settings.dynamicTabs) { var dynamicTabs = '
'; switch (settings.dynamicTabsPosition) { case "bottom": slider.parent().append(dynamicTabs); break; default: slider.parent().prepend(dynamicTabs); break; }; ul = $('#coda-nav-' + sliderCount + ' ul'); // Create the nav items $('.panel', slider).each(function(n) { ul.append('
  • ' + $(this).find(settings.panelTitleSelector).text() + '
  • '); }); navContainerWidth = slider.width() + slider.siblings('.coda-nav-left').width() + slider.siblings('.coda-nav-right').width(); ul.parent().css({ width: navContainerWidth }); switch (settings.dynamicTabsAlign) { case "center": ul.css({ width: ($("li", ul).width() + 2) * panelCount }); break; case "right": ul.css({ float: 'right' }); break; }; }; // If we need a tabbed nav $('#coda-nav-' + sliderCount + ' a').each(function(z) { // What happens when a nav link is clicked $(this).bind("click", function() { navClicks++; $(this).addClass('current').parents('ul').find('a').not($(this)).removeClass('current'); offset = - (panelWidth*z); alterPanelHeight(z); currentPanel = z + 1; $('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction); if (!settings.crossLinking) { return false }; // Don't change the URL hash unless cross-linking is specified }); }); // External triggers (anywhere on the page) $(settings.externalTriggerSelector).each(function() { // Make sure this only affects the targeted slider if (sliderCount == parseInt($(this).attr("rel").slice(12))) { $(this).bind("click", function() { navClicks++; targetPanel = parseInt($(this).attr("href").slice(1)); offset = - (panelWidth*(targetPanel - 1)); if (panelLoaded[targetPanel] == 'y') { alterPanelHeight(targetPanel - 1); } loadPanel(targetPanel, moveRandom); currentPanel = targetPanel; // Switch the current tab: slider.siblings('.coda-nav').find('a').removeClass('current').parents('ul').find('li:eq(' + (targetPanel - 1) + ') a').addClass('current'); // Slide $('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction); // Added by Jenny @20100517 - to change the style for external trigger // first close the header live div $('#gh-nav #live a').removeClass("current"); $('#globallive').hide("fast"); $(settings.externalTriggerSelector).removeClass('current'); if (targetPanel == 1) { highlightPanel = 2; } else if (targetPanel == 2) { highlightPanel = 1; } else { highlightPanel = targetPanel; } $(settings.externalTriggerSelector).parent().parent().find('a:eq('+(highlightPanel-1)+')').addClass('current'); // Stop the jwplayer and tv player when click to another page if (typeof(homeplayer) != "undefined" && homeplayer && targetPanel != 2) stopHomePlayer(); if (typeof(player) != "undefined" && player && targetPanel != 4) stopPlayer(); if (panelLoaded[3] == 'y') { if (targetPanel != 3) { document.getElementById('iframe-tvplayer').src="include2010/blank.htm"; } else { document.getElementById('iframe-tvplayer').src="http://programme.rthk.hk/rthk/tv/index_iframe.php?c=tv"; } } if (!settings.crossLinking) { return false }; // Don't change the URL hash unless cross-linking is specified }); }; }); // Specify which tab is initially set to "current". Depends on if the loaded URL had a hash or not (cross-linking). if (settings.crossLinking && location.hash && parseInt(location.hash.slice(1)) <= panelCount) { $("#coda-nav-" + sliderCount + " a:eq(" + (location.hash.slice(1) - 1) + ")").addClass("current"); // Added by Jenny @20100517 - to change the style for external trigger //$(settings.externalTriggerSelector).parent().parent().find('a:eq('+(location.hash.slice(1) - 1)+')').addClass('current'); if (location.hash.slice(1) == 1) { highlightPanel = 2; } else if (location.hash.slice(1) == 2) { highlightPanel = 1; } else { highlightPanel = location.hash.slice(1); } if (highlightPanel == 3) { //document.getElementById('iframe-tvplayer').src="http://programme.rthk.hk/rthk/tv/index_iframe.php?c=tv"; } $(settings.externalTriggerSelector).parent().parent().find('a:eq('+(highlightPanel - 1)+')').addClass('current'); // If there's no cross-linking, check to see if we're supposed to load a panel other than Panel 1 initially... } else if (settings.firstPanelToLoad != 1 && settings.firstPanelToLoad <= panelCount) { $("#coda-nav-" + sliderCount + " a:eq(" + (settings.firstPanelToLoad - 1) + ")").addClass("current"); // Added by Jenny @20100517 - to change the style for external trigger //$(settings.externalTriggerSelector).parent().parent().find('a:eq('+(settings.firstPanelToLoad - 1)+')').addClass('current'); if (settings.firstPanelToLoad == 1) { highlightPanel = 2; } else if (settings.firstPanelToLoad == 2) { highlightPanel = 1; } else { highlightPanel = settings.firstPanelToLoad; } // Stop the tv player //document.getElementById('iframe-tvplayer').src="include2010/blank.htm"; $(settings.externalTriggerSelector).parent().parent().find('a:eq('+(highlightPanel - 1)+')').addClass('current'); // Otherwise we must be loading Panel 1, so make the first tab the current one. } else { $("#coda-nav-" + sliderCount + " a:eq(0)").addClass("current"); // Added by Jenny @20100517 - to change the style for external trigger $(settings.externalTriggerSelector).parent().parent().find('a:eq(0)').addClass('current'); // Stop the tv player //document.getElementById('iframe-tvplayer').src="include2010/blank.htm"; }; // Set the height of the first panel if (settings.autoHeight) { panelHeight = $('.panel:eq(' + (currentPanel - 1) + ')', slider).height(); //alert(currentPanel + ":" + panelHeight); slider.css({ height: panelHeight }); }; // Trigger autoSlide if (settings.autoSlide) { slider.ready(function() { setTimeout(autoSlide,settings.autoSlideInterval); }); }; function alterPanelHeight(x, minHeight) { if (!minHeight) minHeight = 0; if (settings.autoHeight) { panelHeight = $('.panel:eq(' + x + ')', slider).height(); if (minHeight>0 && minHeight>panelHeight) panelHeight = minHeight; //alert("panel: "+ x + ":" + panelHeight); slider.animate({ height: panelHeight }, settings.autoHeightEaseDuration, settings.autoHeightEaseFunction); }; }; function autoSlide() { if (navClicks == 0 || !settings.autoSlideStopWhenClicked) { if (currentPanel == panelCount) { var offset = 0; currentPanel = 1; } else { var offset = - (panelWidth*currentPanel); currentPanel += 1; }; alterPanelHeight(currentPanel - 1); // Switch the current tab: //slider.siblings('.coda-nav').find('a').removeClass('current').parents('ul').find('li:eq(' + (currentPanel - 1) + ') a').addClass('current'); $('.coda-nav').find('a').removeClass('current').parents('ul').find('li:eq(' + (currentPanel - 1) + ') a').addClass('current'); // Slide: $('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction); setTimeout(autoSlide,settings.autoSlideInterval); }; }; // Added by Jenny Ho @20100705 - to change to load the relatived div after external trigger function loadPanel(panelno, moveRandom) { if (panelLoaded[panelno] == 'y') { return; } switch (panelno) { case 1 : $("#main-radio").load("/include2010/radio_panel.htm?"+Math.random(), function() { /* control radio live show / hide media buttons */ $(".ch-radio .listen a").click(function() { $(".ch-radio .format").hide(); $(".ch-radio .time").show(); $(this).parent().parent().prev().find('.time').hide(); $(this).parent().parent().prev().find('.format').fadeIn('slow'); }); /* control ranking tabs */ $("#item-radio-ranking-tabs:first").tabs("#item-radio-rank-panels:first > div"); /* control radio nav-radio scroll */ var itemrH = $(".nav-radio div.scrollable").scrollable({vertical: true, size: 3}).circular().mousewheel().autoscroll({steps:1, interval:6000, autoplay:false}).navigator({ api: true }); // if the vip banner is set, it first move to that banner, then random move var firstMove = moveRandom; var radio_vip = parseInt($('#item-radio-highlights-vip').html()); if (radio_vip >= 0) { firstMove = radio_vip+3; } /* control whatsnew show banner */ $(".nav-radio div.scrollable .items img").click(function() { // calclulate large image's URL var url = $(this).attr("src"); var alt = $(this).attr("alt"); var rel = $(this).attr("rel"); // get handle to element that wraps the image and make it semitransparent //var wrap = $("#ad-radio h2").fadeTo("medium", 0.5); var wrap = $("#ad-radio"); var img = new Image(); // call this function after it's loaded img.onload = function() { // make wrapper fully visible wrap.fadeTo("fast", 1); // change the image and other attributes wrap.find("img").attr("src", url); wrap.find("img").attr("title", alt); wrap.find("a").attr("href", rel); }; // begin loading the image img.src = url; $("#ad-radio .desc").html(alt); // when page loads simulate a "click" on the random image }).eq(firstMove).click(); //}).eq(moveRandom).click(); //}); if (radio_vip >= 0) { //special placement of the "display ordering" with actual ordering (+3), found it by trial and error var iterhHwait = setTimeout(function() { $(".nav-radio div.scrollable .items img").eq(moveRandom).click(); setTimeout(function() { itemrH.play(); }, 6000); }, 6000); } else { //$(".nav-radio div.scrollable .items img").eq(moveRandom).click(); var iterhHwait = setTimeout(function() { itemrH.play(); }, 6000); } itemrH.onSeek(function() { var imgVis = this.getVisibleItems(); var second = imgVis.filter(":eq(1)"); second.click(); }); /* control text looping in ranking tabs */ $(".rank-today a.rankItem, .rank-week a.rankItem").hover( function(e) { var textNode = $(this).find('.rank-prog-name-title')[0]; if(titleLoopRunning != 0){clearTimeout(titleLoopRunning);titleLoopRunning = 0;} if(!this.loopText){this.loopText = new JqueryUtil.LoopText(textNode,8);} var loopText = this.loopText; if(loopText.mustLoop){titleLoopRunning = setTimeout(function(){loopText.loopText();},500);} }, function(e) { if(this.loopText){this.loopText.reset();} } ); /* alter the panel height after the last element is loaded */ $("#item-radio-highlights img:last").load( function () { alterPanelHeight(panelno-1); }); $("#item-radio-portals img:last").load( function () { alterPanelHeight(panelno-1); }); panelLoaded[panelno] = 'y'; }); $("#gh-fb-links #cht a").attr("href", "http://rthk.hk/index.htm#1"); $("#gh-fb-links #chs a").attr("href", "http://gbcode.rthk.org.hk/TuniS/rthk.hk/index.htm#1"); $("#gh-fb-links #eng a").attr("href", "http://rthk.hk/index_eng.htm"); /*webtrends*/ dcsMultiTrack('DCS.dcsuri', '/dcsRadio_c.htm', 'WT.ti', 'Radio%20Main%20Chinese'); break; case 2 : $("#main").load("/include2010/home_panel_20100810.htm?"+Math.random(), function() { /* control home-item-highlights scroll */ var itemhH = $("#item-home-highlights").scrollable({size:1, clickable:false}).circular().mousewheel().navigator({ // select to be used as navigator navi: "#item-home-highlights-navi", // select A tags inside the navigator to work as items (not direct children) naviItem: 'a', // assign "active" class name for the active A tag inside navigator activeClass: 'active' }).autoscroll({steps:1, interval:6000, autoplay:false, api: true}); /*itemhH.move(moveRandom); itemhH.play();*/ // if the vip banner is set, it first move to that banner, then random move var home_vip = parseInt($('#item-home-highlights-vip').html(),10); if (home_vip >= 0) { itemhH.move(home_vip); var itemhHwait = setTimeout(function() { itemhH.move(moveRandom); setTimeout(function(){ itemhH.play() }, 6000); }, 6000); } else { itemhH.move(moveRandom); var itemhHwait = setTimeout(function() { itemhH.play(); }, 6000); } $('#item-home-highlights-navi li, .item-home-highlights-panels .banner img').click(function() { itemhH.stop(); }); /* control item-rthk-highlights scroll */ var itemrhH = $("#item-rthk-highlights").scrollable({size:1, clickable:false}).circular().mousewheel().navigator({ // select to be used as navigator navi: "#item-rthk-highlights-navi", // select A tags inside the navigator to work as items (not direct children) naviItem: 'a', // assign "active" class name for the active A tag inside navigator activeClass: 'active' }).autoscroll({steps:1, interval:8000, autoplay:false, api: true}); /*itemrhH.move(moveRandom); itemrhH.play();*/ // if the vip banner is set, it first move to that banner, then random move var home_vip = parseInt($('#item-home-highlights-vip').html(),10); if (home_vip >= 0) { itemrhH.move(home_vip); var itemrhHwait = setTimeout(function() { itemrhH.move(moveRandom); setTimeout(function(){ itemrhH.play() }, 8000); }, 8000); } else { itemrhH.move(moveRandom); var itemhHwait = setTimeout(function() { itemrhH.play(); }, 8000); } $('#item-rthk-highlights-navi li, #item-rthk-highlights .banner img').click(function() { itemrhH.stop(); }); /* control ranking tabs */ $("#item-home-ranking-tabs:first").tabs("#item-home-rank-panels:first > div"); /* refresh today news */ var todaynews_refresh = setInterval(function() { $('#item-home-todaynews').fadeOut('slow').load('/include2010/gen_htm/item_home_todaynews_c.htm?'+Math.random()).fadeIn("slow"); /*if (typeof(homeplayer) == "undefined" || homeplayer == null) {*/ if (homeplayer == null) { /* try to make it really refreshes by adding random number */ $('#item-home-videonews').fadeOut('slow').load('/include2010/gen_htm/item_home_videonews.htm?'+Math.random()).fadeIn("slow"); //$('#item-home-videonews span').addClass('playerframe'); //$('#home-placeholder').prepend(''); } }, 300000); /* control text looping in ranking tabs */ $(".rank-today a.rankItem, .rank-week a.rankItem").hover( function(e) { var textNode = $(this).find('.rank-prog-name-title')[0]; if(titleLoopRunning != 0){clearTimeout(titleLoopRunning);titleLoopRunning = 0;} if(!this.loopText){this.loopText = new JqueryUtil.LoopText(textNode,8);} var loopText = this.loopText; if(loopText.mustLoop){titleLoopRunning = setTimeout(function(){loopText.loopText();},500);} }, function(e) { if(this.loopText){this.loopText.reset();} } ); //$(".topicbox img:last").load( function () { alterPanelHeight(panelno-1, 700); //}); panelLoaded[panelno] = 'y'; }); /*webtrends*/ dcsMultiTrack('DCS.dcsuri', '/dcsMain_c.htm', 'WT.ti', 'Main%20Chinese'); break; case 3 : $("#main-tv").load("/include2010/tv_panel.htm?"+Math.random(), function() { /* control ranking tabs */ $("#item-tv-ranking-tabs:first").tabs("#item-tv-rank-panels:first > div"); /* load iframe */ $('#iframe-tvplayer').attr("src","http://programme.rthk.hk/rthk/tv/index_iframe.php?c=tv"); /* control text looping in ranking tabs */ $(".rank-today a.rankItem, .rank-week a.rankItem").hover( function(e) { var textNode = $(this).find('.rank-prog-name-title')[0]; if(titleLoopRunning != 0){clearTimeout(titleLoopRunning);titleLoopRunning = 0;} if(!this.loopText){this.loopText = new JqueryUtil.LoopText(textNode,8);} var loopText = this.loopText; if(loopText.mustLoop){titleLoopRunning = setTimeout(function(){loopText.loopText();},500);} }, function(e) { if(this.loopText){this.loopText.reset();} } ); /* alter the panel height after the last element is loaded */ $("#item-special img:last").load( function () { alterPanelHeight(panelno-1); }); panelLoaded[panelno] = 'y'; }); $("#gh-fb-links #cht a").attr("href", "http://rthk.hk/index.htm#3"); $("#gh-fb-links #chs a").attr("href", "http://gbcode.rthk.org.hk/TuniS/rthk.hk/index.htm#3"); $("#gh-fb-links #eng a").attr("href", "http://rthk.hk/index_eng.htm#3"); /* webtrends */ dcsMultiTrack('DCS.dcsuri', '/dcsTV_c.htm', 'WT.ti', 'TV%20Main%20Chinese'); break; case 4 : $("#main-webit").load("/include2010/webit_panel.htm?"+Math.random(), function() { /* control webit-item-highlights scroll */ var itemwH = $("#item-webit-highlights").scrollable({size: 1, clickable:false}).circular().mousewheel().navigator({ // select to be used as navigator navi: "#item-webit-highlights-navi", // select A tags inside the navigator to work as items (not direct children) naviItem: 'a', // assign "active" class name for the active A tag inside navigator activeClass: 'active' }).autoscroll({steps:1, interval:6000, autoplay:false, api:true}); /*itemwH.move(moveRandom); itemwH.play();*/ // if the vip banner is set, it first move to that banner, then random move var webit_vip = parseInt($('#item-webit-highlights-vip').html(),10); if (webit_vip >= 0) { itemwH.move(webit_vip); var itemwHwait = setTimeout(function() { itemwH.move(moveRandom); setTimeout(function(){ itemwH.play() }, 6000); }, 6000); } else { itemwH.move(moveRandom); var itemhHwait = setTimeout(function() { itemwH.play(); }, 6000); } $('#item-webit-highlights-navi li, .item-webit-highlights-panels .banner img').click(function() { itemwH.stop(); }); /* control ranking tabs */ $("#item-webit-ranking-tabs:first").tabs("#item-webit-rank-panels:first > div"); /* control text looping in ranking tabs */ $(".rank-today a.rankItem, .rank-week a.rankItem").hover( function(e) { var textNode = $(this).find('.rank-prog-name-title')[0]; if(titleLoopRunning != 0){clearTimeout(titleLoopRunning);titleLoopRunning = 0;} if(!this.loopText){this.loopText = new JqueryUtil.LoopText(textNode,8);} var loopText = this.loopText; if(loopText.mustLoop){titleLoopRunning = setTimeout(function(){loopText.loopText();},500);} }, function(e) { if(this.loopText){this.loopText.reset();} } ); /* alter the panel height after the last element is loaded */ $("#item-special-wide img:last").load( function () { alterPanelHeight(panelno-1); }); //alterPanelHeight(panelno-1, 1181); panelLoaded[panelno] = 'y'; }); $("#gh-fb-links #cht a").attr("href", "http://rthk.hk/index.htm#4"); $("#gh-fb-links #chs a").attr("href", "http://gbcode.rthk.org.hk/TuniS/rthk.hk/index.htm#4"); $("#gh-fb-links #eng a").attr("href", "http://rthk.hk/index_eng.htm#4"); /* webtrends */ dcsMultiTrack('DCS.dcsuri', '/dcsWebplus_c.htm', 'WT.ti', 'Webplus%20Main%20Chinese'); break; default: }; }; // Kill the preloader $('.panel', slider).show().end().find("p.loading").remove(); slider.removeClass("preload"); sliderCount++; }); };