﻿var refreshOnSBClose = false;

//add the dynamic scrolling effect for the video and quick find lists
window.addEvent('domready', function() {

    var videoTab = aspElm('tabDiv2');
    var videoScroller = new Scroller(videoTab.id, { area: 80, fps: 100000000 });
    videoScroller.start();
    videoTab.addEvent('click', videoScroller.stop.bind(videoScroller));

// uncomment when ready for quick find
//    var quickFindTab = elm('QuickFindList');
//    var quickFindScroller = new Scroller(quickFindTab.id, { area: 60, fps: 100000000 });
//    quickFindScroller.start();
//    quickFindTab.addEvent('click', quickFindScroller.stop.bind(quickFindScroller));
});

// switch between lesson, video and quick find tabs
function setVisibleTab(selectedTabIndex) {
//  loop to 3 when ready to add quick find tab, for now just loop the 2 tabs
//    for (var i = 1; i <= 3; i++) {
    for (var i = 1; i <= 2; i++) {
        if (i == selectedTabIndex) {
            aspElm('tab' + i).className = 'tabHeading2';
            aspElm('tabDiv' + i).style.display = '';
        }
        else {
            aspElm('tab' + i).className = 'tabHeading2inactive';
            aspElm('tabDiv' + i).style.display = 'none';
        }
    }
}

// update average score and review count for video just closed
function ShadowboxOnClose(x) {
    var contentID = x.content.substring(x.content.indexOf("id=") + 3, x.content.length);
    UpdateAverage(contentID, 1);
	if (typeof onSbClose == 'function') {
		onSbClose();
	}
}

// update average score and review count for content chunk just closed
function ChunkOnClose(contentID) {
    UpdateAverage(contentID, 2);
}

// call the method on the server to get the updated average score
function UpdateAverage(contentID, contentTypeID) {
    if(typeof PageMethods != 'undefined') PageMethods.UpdateAverageScore(contentID, contentTypeID, OnUpdateAverageSuccess, OnUpdateAverageFailure);
}

// update the display with the new average score and review count
function OnUpdateAverageSuccess(result, userContext, methodName) {

    var tabId, contentType;
    var params = result.split("|");
    //params[0] -> contentId
    //params[1] -> contentTypeId
    //params[2] -> average score
    //params[3] -> reviews count

    switch (params[1]) {
        case "1": // video
            tabId = "tabDiv2";
            contentType = "Video";
            break;
        case "2": // chunk
            tabId = "tabDiv3";
            contentType = "ContentChunk";
            break;
        default:
            break;
    }
    var inputs = aspElm(tabId).getElementsByTagName("input");
    for (var i = 0; i < inputs.length; i++) {
        if ((inputs[i].attributes["updateTag"]) && (inputs[i].attributes["updateTag"].value == "star_" + contentType + "_" + params[0])) {
            updateStarsAvg(inputs[i].id, params[2], params[3]);
            break;
        }
    }
}

function OnUpdateAverageFailure(error, userContext, methodName) {
    //alert(error.get_message());
}

function ThumbMouseover(imgId) {
    if (!(window.navigator.userAgent.indexOf("MSIE") > -1))
        elm(imgId).src = "../graphics/site/play_over.png";
}

function ThumbMouseout(imgId) {
    if (!(window.navigator.userAgent.indexOf("MSIE") > -1))
        elm(imgId).src = "../graphics/site/play.png";
        
    //    var zxce = window.event || arguments.callee.caller.arguments[0];
    //    if((window.navigator.userAgent.indexOf("MSIE") > -1) && (!zxcCkEventObj(zxce, imgId))) return false;
    //    elm(imgId).src = "../graphics/site/play.png";
}
//function zxcCkEventObj(zxce, imgId){
//    if (!zxce) var zxce=window.event;
//    zxce.cancelBubble=true;
//    if (zxce.stopPropagation) zxce.stopPropagation();
//    var zxceobj=(zxce.relatedTarget)?zxce.relatedTarget:(zxce.type=='mouseout')?zxce.toElement:zxce.fromElement;
//    while (zxceobj.parentNode){
//        if (zxceobj.id && (zxceobj.id.indexOf('videoLinkDiv') > -1)) { return false; }
//        zxceobj = zxceobj.parentNode;
//    }
//    return true;
//}
