
//**********************************
// TechCentral Carousel Motion 2010
//**********************************


function dbugScripts(baseurl, libs) {
    var value = document.cookie.match('(?:^|;)\\s*jsdebug=([^;]*)');
    var debugCookie = value ? unescape(value[1]) : false;
    if (window.location.href.indexOf("basePath=this") > 0) 
    {
        var path = baseurl.substring(baseurl.substring(7, baseurl.length).indexOf("/") + 8, baseurl.length);
        var href = window.location.href;
        baseurl = href.substring(href.substring(7, href.length).indexOf("/") + 8, href.length)
    }
    if (window.location.href.indexOf("jsdebug=true") > 0 || window.location.href.indexOf("jsdebugCookie=true") > 0 || debugCookie == 'true') 
    {
        for (var i = 0; i < libs.length; i++) 
        {
            document.write("<scri" + "pt src=\"" + baseurl + libs[i] + "\" type=\"text/javascript\"></script>")
        }
        return true
    } return false 
    
    };
if (!dbugScripts("/videos/js", ["techcentral.carou.js"])) {
    function refreshMpu(ncat) {
        try {
            dbug.log("Refresh MPU for: " + ncat);
            var ptype = PageVars.data.pageType; window.addEvent('domready',
function() {
    var mpu = new Request({ url: '/9740-1_53-0.html?ncat=' + ncat + '&ptype=' + ptype, onComplete: function(responseText) { try { $('metaMpu').set('html', responseText) } catch (e) { } }, method: 'get' }).send();
    var marquee = $('marquee');
    if (marquee != null) { var marq = new Request({ url: '/9740-1_53-0.html?sp=110&width=300&height=70&ncat=' + ncat + '&ptype=' + ptype, onComplete: function(responseText) { try { marquee.set('html', responseText) } catch (e) { } }, method: 'get' }).send() }
})
        } catch (e) { }
    } function thisMovie(movieName) {
        var isIE = navigator.appName.indexOf("Microsoft") != -1;
        return (isIE) ? window[movieName] : document[movieName]
    } function makeCall(name, type, value) { thisMovie("techPlayer").showClipsFromPage(name, type, value) } function subNavClick(name, type, value, o) {
        trackEvent("NavMenuItem;" + o.getAttribute("rev") + ";" + name + ";" + pageName());
        thisMovie("techPlayer").showClipsFromPage(name, type, value)
    } function promoClick(name, type, value, o) {
        trackEvent("Slide;" + o.getAttribute("id") + ";" + value + ";" + escape(name));
        if (value == "live") type = "live"; if (type != "url") { thisMovie("techPlayer").showClipsFromPage(name, type, value) } else { document.location = value }
    } function previousLiveClick(name, type, value) { thisMovie("universalPlayer0").showClipsFromPage(name, type, value) } function addHoverClass(nav) {
        var navroot = document.getElementById(nav);
        var currentMenu = null;
        if (navroot != null) {
            var lis = navroot.getElementsByTagName("LI");
            for (i = 0; i < lis.length; i++) {
                try {
                    if (lis[i].childNodes.length > 1 && lis[i].childNodes[2].tagName == "UL") {
                        var myParent = lis[i].childNodes[0].firstChild.nodeValue; lis[i].childNodes[0].onmouseover = function() {
                            if (this.firstChild.nodeValue != currentMenu) {
                                trackEvent("NavMenuExpand;" + this.firstChild.nodeValue + ";" + pageName());
                                currentMenu = this.firstChild.nodeValue
                            }
                        }; lis[i].onmouseout = lis[i].onclick = function() { this.className = "" };
                        lis[i].onmouseover = function() { this.className = "over" }
                    } else { lis[i].firstChild.setAttribute('rev', myParent) }
                } catch (e) { }
            }
        }
    } 
    
    function dwTrack(cval, ctype) {
    var dwUrl = "http://www.techcentral.com.my?destUrl=" + escape("../images/b.gif?" + Math.floor(Math.random() * 1000));
    dwUrl += "&ctype=" + ctype;
    dwUrl += "&cval=" + cval;
    var dwImg = new Image; dwImg.src = dwUrl;
    dbug.log("dwTrack: " + cval)
}
function trackEvent(cval) {
    cval = escape(cval);
    var dwUrl = "http://www.techcentral.com.my?destUrl=" + escape("../images/b.gif?" + Math.floor(Math.random() * 1000));

    dwUrl += "&ctype=event"; dwUrl += "&cval=" + cval;
    var dwImg = new Image;
    dwImg.src = dwUrl;
    dbug.log("trackEvent: " + cval)
}
function trackPageImpression(cval) {
    cval = escape(cval);
    var dwUrl = "http://www.techcentral.com.my?destUrl=" + escape("../images/b.gif?" + Math.floor(Math.random() * 1000));
    dwUrl += "&ctype=pageImpression";
    dwUrl += "&cval=" + cval;
    var dwImg = new Image;
    dwImg.src = dwUrl
}

function doVideoSearch() {
    var kw = document.videoSearchForm.vkw.value;
    if (kw != "") {
        document.getElementById('vidSearch').style.height = "338px";
        document.getElementById('vidSearch').style.width = "286px";
        document.getElementById('vidSearchId').style.height = "338px";
        document.getElementById('vidSearchId').style.width = "286px";
        document.getElementById('mostwatch').style.visibility = "hidden";
        thisMovie("vidSearchId").showSearchClips(kw)
    }
}
function hideSearchResults() {
    document.getElementById('vidSearch').style.height = "1px";
    document.getElementById('vidSearch').style.width = "1px";
    document.getElementById('vidSearchId').style.height = "1px";
    document.getElementById('vidSearchId').style.width = "1px";
    document.getElementById('mostwatch').style.visibility = "visible"
}
function pageName() {
    return "FrontDoor" 
}

function loadNewsHeadlines(tilename, nodeid) {
    var url = '/9741-1_53-' + nodeid + '.html?_siteid_=53&_editionid_=3&_tilename_=' + tilename;
    try {
        dbug.log("Load " + tilename + " tile for: " + nodeid);
        var news = new Request.HTML({ url: url, update: $('newsheadlines') }).send()
    } catch (e) { } 
} function loadTabSwapper(idx) {
    dbug.log("Load tabSwapper");
    var tabSetElement = $('tabSet');
     var tabs = $$(tabSetElement.childNodes);
     tabs.each(function(tab, index) {
         dbug.log("index: " + index + " idx: " + idx);
         if (index != idx) { tab.removeClass('on') } else { tab.addClass('on') } 
     })
 } function GetValue(varName) {
     squery = location.search; idx = squery.indexOf(varName);
     var theValue = null;
      if (idx != -1) {
         squery = squery.substr(idx + 1 + varName.length, squery.length);
         if (squery.length > 0) {
             nextParam = squery.indexOf("&");
             if (nextParam != -1) { theValue = squery.substr(0, nextParam) } else { theValue = squery.substr(0, squery.length) } 
         } 
     } return theValue
 } function watchQc(name, type, id) {
     var setArray = new Array();
     $$('#thumbScroller ul.active li').each(function(el, idx) { setArray.include(el.id.substring(3)) });
     setArray.erase(id);
     setArray.unshift(id);
     dbug.log("set: " + setArray);
     thisMovie("techPlayer").showClipsFromPage(name, type, setArray.toString());
     dwTrack('QCVideoItem;' + quickClicks.getTabName() + ";" + id + ';', 'event')
 } function loadNewsHeadlinesv21(tilename, nodeid) {
     var url = '/9741-1_53-' + nodeid + '.html?_siteid_=53&_editionid_=3&_tilename_=' + tilename;
     try {
         dbug.log("Load " + tilename + " tile for: " + nodeid);
         new Request.HTML({ url: url, update: $('newsheadlines') }).send()
     } catch (e) { } 
 } function doVideoSearchBox(keyword) {
     var kw = keyword;
     if (kw != "") {
         document.getElementById('vidSearch').style.height = "338px";
         document.getElementById('vidSearch').style.width = "286px";
         document.getElementById('vidSearchId').style.height = "338px";
         document.getElementById('vidSearchId').style.width = "286px";
         thisMovie("vidSearchId").showSearchClips(kw);
         $('vidSearchResults').injectInside($('video_results'))
     } 
 } var QC = {};
 QC = new Class({ Implements: Options, currentTop: 0, options: { thumbContainer: 'productThumbs', thumbScroller: 'thumbScroller', leftArrow: 'scrollLeft', rightArrow: 'scrollRight' }, initialize: function(options) {
     this.setOptions(options);
     this.container = $(this.options.thumbContainer);
     this.scroller = $(this.options.thumbScroller); this.scroll = new Fx.Scroll(this.container);
     $(this.options.rightArrow).addEvent('click', this.scrollRight.bind(this));
     $(this.options.leftArrow).addEvent('click', this.scrollLeft.bind(this));
     $(this.options.leftArrow).className = "end";
     $(this.options.rightArrow).className = "";
     $E('#thumbScroller ul').className = "set active";
     this.viewWidth = this.container.getStyle('width').toInt();
     this.currentPos = 0; this.contentWidth = null;
     this.displaySegment = 1; this.tabName = null;
     this.subsetVisible = this.viewWidth / $E('#thumbScroller ul li').getStyle('width').toInt();
     this.resetContent();
     this.imageLocker = new Object()
 }, scrollLeft: function() {
     if ($(this.options.leftArrow).className != "end") {
         this.scroll.start(this.getNewX(-1), false);
         this.showItemsCount();
         dwTrack('ScrollArrow;' + this.getTabName() + ';left;' + this.displaySegment + ';', 'event')
     } 
 }, scrollRight: function() {
     if ($(this.options.rightArrow).className != "end") {
         this.scroll.start(this.getNewX(1), false);
         this.showItemsCount();
         dwTrack('ScrollArrow;' + this.getTabName() + ';right;' + this.displaySegment + ';', 'event')
     } 
 }, showItemsCount: function() {
     dbug.log("showItemsCount: this.contents: " + this.contents);
     if (this.contents != null) {
         var start = ((this.displaySegment - 1) * this.subsetVisible) + 1;
         var end = start + this.subsetVisible - 1;
         if (end > this.contents.length) {
             end = this.contents.length;
             start = end - this.subsetVisible
         } $('qcCount').set({ html: "<b>" + start + " - " + end + "</b> of " + this.contents.length + "" })
     } 
 }, getNewX: function(direction) {
     var newPos = this.currentPos + (this.viewWidth * direction);
     var endPos = this.getEndPosition(direction);
     this.currentPos = ((newPos * direction) < endPos) ? newPos : endPos;
     this.displaySegment = this.displaySegment + direction;
     dbug.log("newPos: " + newPos + " endPos: " + endPos);
     if ((newPos * direction) < endPos) {
         this.currentPos = newPos;
         $(this.options.leftArrow).className = "";
         $(this.options.rightArrow).className = ""
     } else {
         this.currentPos = endPos;
         if (direction == -1) {
             $(this.options.leftArrow).className = "end";
             if (newPos == endPos) { $(this.options.rightArrow).className = "" } 
         } else { if (newPos == endPos) { $(this.options.leftArrow).className = "" } $(this.options.rightArrow).className = "end" } 
     } return this.currentPos
 }, getContentWidth: function() {
     var tWidth = 0;
     this.contents.each(function(el) { tWidth += el.getStyle('width').toInt() });
     return tWidth
 }, getEndPosition: function(direction) {
     if (this.contentWidth == null) this.contentWidth = this.getContentWidth();
     return (direction == 1) ? this.contentWidth - this.viewWidth : 0
 }, resetContent: function() {
     dbug.log("resetContent2: " + this.imageLocker);
     this.currentPos = 0;
     this.displaySegment = 1;
     this.contentWidth = null;
     this.contents = $$('#thumbScroller .active li');
     this.popUpDesc = $$('#thumbScroller .active li .description');
     this.scroll.start(0, false);
     $(this.options.leftArrow).className = "end";
     $(this.options.rightArrow).className = "";
     var t = "";
     $('qcTabs').getElements("li").each(function(el, idx) { if (el.className == "on") { t = el.get('text') } });
     this.tabName = t;
     dbug.log("Selected tab is: " + this.tabName);
     this.contents.each(function(el) {
         el.addEvent('mouseover', function() { this.addClass('hover') });
         el.addEvent('mouseout', function() { this.removeClass('hover') });
         try {
             var i = el.getElement('.qcImg');
             if (i.src.length < 1) {
                 try {
                     i.src = this.imageLocker[el.id];
                     dbug.log("Load image: " + this.imageLocker[el.id])
                 } catch (err) { dbug.log("No image available") } 
             } 
         } catch (err) { } 
     }, this);
     this.showItemsCount()
 }, getTabName: function() { return escape(this.tabName) }, addToLocker: function(i) {
     dbug.log("imageLocker. Adding " + i.length + " items.");
     for (var loop = 0; loop < i.length; loop++) { this.imageLocker[i[loop].name] = i[loop].imgSrc } this.resetContent()
 } 
});
function swap(o) {
    $('qcTabs').getElements("li").each(function(el, idx) {
        if (el.get('text') == o.parentNode.get('text')) {
            el.className = "on";
            $$('#thumbScroller .set')[idx].className = "set active";
            dwTrack('QCButton;' + escape(el.get('text')), 'event')
        } else { el.className = ""; $$('#thumbScroller .set')[idx].className = "set" } 
    }); quickClicks.resetContent()
} function renderSvPromo() {
    var svCount = $$('#logoBox div.ads_lb_vidSpon').length; var promoCount = 5 - svCount;
    var displayPromoArray = new Array();
    if (typeof ordered == 'undefined') {
        var promoArrayCopy = $A(promoArray);
        for (i = 0; promoCount > i; i++) {
            var randomPromo = promoArrayCopy.getRandom();
            displayPromoArray.push(randomPromo);
            promoArrayCopy.splice(promoArrayCopy.indexOf(randomPromo), 1)
        } displayPromoArray.each(function(promo) { dbug.log('randomPromoItem: ' + promo.name) })
    } else { displayPromoArray = promoArray } if (svCount > 0) {
        var mColWidth = svCount * 128 + 2;
        var svWidth = svCount * 128 + 2;
        if (svCount == 1) {
            mColWidth = mColWidth + 2;
            svWidth = svWidth + 2
        } dbug.log('svWidth:' + svWidth);
        $$('#logoBox, #logoBox #cap, #logoBox #cap #svLeft, #logoBox #cap #svRight, #logoBox #foot, #logoBox #foot #svLeft, #logoBox #foot #svRight').setStyle('width', svWidth + 'px');
        $$('#mcol-l').setStyle('width', mColWidth + 'px')
    } else { dbug.log('svCount:' + svCount) } for (i = 0; promoCount > i; i++) {
    var promoUnitEl = new Element('div', { 'id': 'promoUnit' });
    var promoLinkEl = new Element('a', { 'href': '#', 'index': i });
    promoLinkEl.addEvent('click', function(i) {
        dbug.log("getting promoArray at index: " + i);
        var name = displayPromoArray[i].name;
        var type = displayPromoArray[i].type;
        var value = displayPromoArray[i].value;
        var memo = displayPromoArray[i].memo;
        dwTrack('MidPromo;' + value + ';' + memo + ';', 'event');
        if (type == "url") { window.location.href = value } else { makeCall(name, type, value) } 
    } .pass(i));
    var promoImgEl = new Element('img', { 'src': displayPromoArray[i].imgPath, 'alt': displayPromoArray[i].imgAlt, 'width': '125', 'height': '125', 'border': '0' });
    promoImgEl.injectInside(promoLinkEl);
    promoLinkEl.injectInside(promoUnitEl);
    promoUnitEl.injectAfter($('mcol-l'))
}
}

window.addEvent('domready', function() 
{
    if ($('thumbScroller')) {
        quickClicks = new QC() 
    } 
    var p = $$('#featuredVideo .promo');
    p.each(function(el, idx) { el.id = idx + 1 });
    addHoverClass('mainMenu')
}

);
 function doVideoSearchHH(w, h) {
    if (w == undefined) w = "286";
    if (h == undefined) h = "338";
    var videoSearchForm = document.videoSearchForm;
    var kw = videoSearchForm.query.value;
    var sel = videoSearchForm['target'].selectedIndex;
    var searchType = videoSearchForm['target'].options[sel].value;
    if (kw != "") {
        if (searchType == 'ctv') {
            document.getElementById('vidSearch').style.height = h + "px";
            document.getElementById('vidSearch').style.width = w + "px";
            document.getElementById('vidSearchId').style.height = h + "px";
            document.getElementById('vidSearchId').style.width = w + "px";
            thisMovie("vidSearchId").showSearchClips(kw)
        } else 
        {
        
            videoSearchForm.action = searchType;
            videoSearchForm.submit()
        }
    } 
            
          }
}



