/* allVideoSorter.js 
 * copyright Juicyorange, LLC 2009
 * all rights reserved
 */

// sorting indecies
var allVideoIndexes_obj = {};
allVideoIndexes_obj.byName_arr = new Array(1891,1897,1899,1905,1893,1901,1885,1895,1903,1889,1907,1887,1855,2581,1757,1449,1572,1640,23597,16398,1682,1837,10968,15079,5882,6521,12649,6986,13020,15672,16888,14498,17539,16210,1875,7489,1570,1690,16400,11366,17196,7761,5522,23893,1602,1365,1686,24451,1373,1554,20110,17361,10966,3977,1397,1666,543,24220,1714,1375,1441,1540,1458,1421,6646,5528,5530,1439,1530,1558,1680,1678,1550,1827,1377,9911,1839,1821,1508,1618,1624,1612,1610,1620,1604,1616,1614,1622,1608,1626,1606,6260,5111,8964,4750,15495,1574,1560,1741,1696,2276,24093,1433,8198,24591,8292,523,6516,1516,14779,1775,9372,1534,1395,1853,349,1476,1351,1405,1849,6263,22777,1727,1472,23377,9370,20374,10095,1829,1369,353,1803,1789,1813,13963,5114,9249,24523,1592,1379,1586,24286,1600,1722,1578,249,1841,1769,1650,1809,5153,1783,10756,8819,5137,1712,1745,1662,5159,1644,7076,9144,5162,23750,620,1652,1544,1835,569,5184,1735,1706,1781,1692,24348,2300,6741,6747,6743,6731,6745,6737,6733,6739,6735,6752,7074,13341,13961,1646,1861,23717,1863,1859,2271,1504,627,1913,645,310,1450,6518,1688,10751,1482,8287,350,16639,14941,1881,351,3971,22124,1427,9909,3558,1462,1480,1496,5156,1799,1815,5154,1708,1642,5186,1747,12346,1702,5158,1787,1797,1765,5138,5109,20229,568,6081,2107,1700,2274,20687,1580,1710,1704,1743,1751,2297,1793,12496,1761,5139,16470,18276,22718,1694,18605,21823,21037,17781,17014,14774,14777,5533,1819,24369,8289,21461,1883,1920,1817,1576,1598,5157,1698,24351,24339,24312,20531,14046,1636,1520,11729,22463,1470,1468,1676,611,1879,544,5151,1500,23050,1779,1873,1871,1869,1867,1865,9247,9374,7986,1399,1596,1749,1445,4455,1845,8195,1466,1532,1425,1847,19889,1771,1474,23128,14289,15821,1588,3975,7989,1359,1486,1484,1367,1391,1389,1454,19207,13725,1447,14287,1452,19203,1419,19201,1791,17131,23286,16720,18502,5526,1387,23139,1413,1843,1857,1407,1638,1720,18093,11725,9028,1753,23439,10473,619,6650,3561,7260,1739,1562,1417,1361,1393,1460,1552,1584,23190,10302,11593,1464,1546,355,1718,14643,5620,1916,1918,1490,5152,1656,5187,1737,1807,5185,1811,14240,1654,1823,22982,21304,1437,1536,1755,1582,1725,1564,17699,1498,9244,14781,1431,3741,1478,1660,8885,5524,1672,1763,1518,1357,9596,1371,1512,4452,1542,1538,23048,1668,1733,1731,1729,1409,1429,1674,1566,1456,1556,1851,23052,11310,8737,1914,1488,10243,1443,23790,1494,8241,8082,1805,10754,11727,24371,1664,10758,1670,24450,1492,15077,6716,6750,15443,15497,22669,6346,1423,10097,1385,352,1831,1403,23126,1911,659,10533,1773,6388,19179,1514,4602,1411,1568,1716,1590,1658,1648,1548,16016,14156,1877,11916,21306,19205,15493,354,24525,15280,1355,1777,16402,10530,17878,19346,4173,5422,24708,22918,1415,1383,22204,1381,1353,1502,7079,1833,1510,1401,1594,1435,23701,24752,24302,1684,1825);
allVideoIndexes_obj.byCategory_arr = new Array(1907,1905,1903,1901,1899,1897,1895,1893,1891,1889,1887,1885,23893,11366,7761,5522,20110,17361,24286,249,20531,20374,19179,8241,5151,5154,5152,5139,5137,5153,5185,5138,5156,5184,5158,5157,5187,5159,5186,1600,1722,1636,1592,1578,1558,1530,23717,14240,8195,7074,5111,2276,659,620,611,523,1914,1911,1883,1879,1875,1857,1853,1851,1849,1845,1847,1843,1841,1839,1837,1835,1833,1831,1829,1827,1817,1819,11310,8964,8737,4750,1741,1696,1574,1560,1863,1861,1859,23377,13963,1813,1803,1789,13961,13725,13341,8819,1809,1783,9144,5162,1745,1712,1662,1650,1644,1684,1682,1686,1688,1680,1678,1676,1674,1672,1670,1668,1666,1664,1869,1867,1865,1873,1871,8885,1749,1739,1596,1584,1562,1554,1550,1532,1351,1720,1604,1606,1608,1610,1612,1614,1616,1618,1620,1622,1624,1626,23286,18502,17131,16720,11593,10302,23597,14643,5620,2581,1811,1807,1757,1737,1718,1570,1656,1556,1725,1582,1564,23750,23439,7989,3975,1486,1484,1763,1359,1805,15821,8082,7489,6263,4452,6750,6747,6745,6743,6741,6739,6737,6735,6733,6731,6752,16016,14156,1716,1658,1648,1590,1568,1548,1546,17196,24708,22918,19346,17878,10530,5422,4173,22204,24752,24302,23701,1918,1916,1735,1706,1692,1425,1423,1427,1602,24451,24450,10968,10966,24351,24348,23052,23050,23048,15443,14289,10473,10243,7260,3561,619,17699,14941,1458,1460,1714,1462,1464,24339,24312,24220,24093,23790,21461,6346,4602,543,544,1572,1544,16639,14287,9596,3741,6716,1855,3558,1920,1913,1881,1877,10533,1588,1586,22124,17539,15672,645,310,16888,16210,14498,13020,12649,11916,6986,5882,1496,1791,6521,6518,6516,12346,1797,1787,1765,1747,1708,1702,1642,1799,1815,22982,2274,2271,15497,15495,15493,1652,1654,1437,1435,1369,1540,1821,1542,1538,1534,1536,1823,1825,20229,6081,5109,2107,568,9374,9372,9370,1456,6260,5533,5530,5528,5526,5524,7986,10095,10097,15079,15077,1502,1504,627,1494,1779,1781,1490,1775,1777,1773,1769,1771,1443,1445,1449,1447,14046,1433,1646,1638,1640,1431,7079,7076,1733,1731,1466,1729,22718,20687,18276,16470,12496,2297,1793,1761,1751,1743,1710,1704,1694,1594,1580,1353,1429,18093,1488,1498,1500,1371,1552,353,352,354,355,22669,23128,23126,23139,569,1520,1516,1518,24525,24523,1454,1700,8198,1377,21823,21037,18605,17781,17014,14774,19889,1755,1482,22777,21306,21304,1492,19207,19205,19203,19201,1367,1361,1365,1357,1421,1439,1441,1660,24371,24369,11729,11727,11725,23190,8292,8289,8287,2300,1508,1510,1514,1512,1419,1417,1415,1413,14781,14779,14777,9028,1474,1476,1379,1381,1383,1385,1387,15280,9911,9909,6650,6646,1698,1598,1576,1566,1389,1391,1478,1480,1753,1450,1452,1690,16402,16400,16398,3977,3971,22463,6388,24591,5114,1375,1373,4455,1355,349,350,351,1399,1401,1403,1405,1409,1411,1407,1395,1397,1393,9249,9247,9244,1468,1472,1727,1470,10751,10754,10756,10758);
allVideoIndexes_obj.byDate_arr = new Array(24752,24708,24591,24525,24523,24451,24450,24371,24369,24351,24348,24339,24286,24312,24302,24220,24093,23893,249,23790,23750,23717,23701,23597,23439,23377,23286,23190,23128,23126,23139,23052,23050,23048,22982,22918,22777,22718,21306,22669,22463,22204,22124,1799,21823,21461,21304,21037,20687,20531,20374,20229,20110,19889,19346,19207,19205,19203,19201,19179,18605,18502,18276,18093,17878,17781,17699,1805,17539,17361,17196,17131,17014,16888,16720,16639,16470,16402,16400,16398,16210,16016,15821,15672,15497,15495,15493,15443,15280,15079,15077,14941,14781,14779,14777,14774,14643,14498,14289,14287,14240,14156,14046,13961,13963,13725,13341,13020,12649,12496,12346,11916,11729,11727,11725,11593,11366,11310,10968,10966,10751,10754,10756,10758,10530,10533,10473,10302,10243,10095,10097,9911,9909,9596,9028,9374,9372,9370,9249,9247,9244,9144,8964,8885,8819,8737,8292,8289,8287,8241,8195,8198,8082,7989,7986,7761,7489,1379,1381,1383,1385,1387,7260,7074,7079,7076,6986,6750,6747,6745,6743,6741,6739,6737,6735,6733,6731,6752,3741,6716,6650,6646,6521,6518,6516,6388,6346,6260,6263,6081,5882,5620,5522,5533,5530,5528,5526,5524,5422,5162,4602,5111,5114,5109,4750,4455,4452,1855,4173,3971,3975,3977,3558,3561,2581,2300,2297,2274,2276,2271,2107,645,619,627,568,659,543,620,5151,544,611,569,310,349,523,350,351,353,352,354,355,5154,1815,1813,1520,1516,1518,5152,1811,5139,5137,1508,1510,1512,1514,1809,1920,5153,1807,1916,1918,5185,1502,1504,5138,1913,1914,1803,1498,1500,1911,5156,1600,1797,1907,1905,1903,1901,1899,1793,1897,1895,1893,1891,1889,1887,1496,1791,1885,1789,1588,1586,1787,1492,1494,1783,1883,1490,1775,1777,1779,1781,1881,1769,1771,1773,1765,1484,1486,1761,1488,1763,1482,1755,1757,1879,1478,1480,1751,1753,1474,1476,1749,1747,1745,1743,1741,1739,1737,1735,5184,1733,1731,1466,1468,1470,1472,1727,1729,1875,1877,1725,1722,1720,1718,1716,1458,1460,1462,1464,1714,1865,1867,1869,1871,1873,1570,1712,1710,1863,1861,1859,1708,1706,1456,1857,1704,1702,5158,1454,1700,1698,5157,1696,1692,1694,1450,1452,1690,1853,1664,1666,1668,1670,1672,1674,1676,1678,1680,1682,1684,1686,1688,1443,1445,1447,1449,1851,1662,1439,1441,1660,1849,1658,1656,5187,1435,1437,1652,1654,1845,1847,1650,1843,1433,1646,1648,1644,5159,1431,1638,1640,1642,1841,5186,1429,1636,1839,1423,1425,1427,1604,1837,1606,1608,1610,1612,1614,1616,1618,1620,1622,1624,1626,1602,1421,1596,1598,1594,1590,1592,1419,1417,1413,1415,1582,1584,1835,1399,1401,1403,1405,1407,1409,1411,1393,1395,1397,1578,1580,1389,1391,1574,1576,1572,1833,1566,1568,1562,1564,1377,1558,1560,1831,1373,1375,1554,1556,1829,1371,1546,1548,1550,1827,1552,1353,1369,1534,1536,1538,1540,1542,1544,1821,1823,1825,1359,1532,1351,1530,1355,1817,1819,1357,1361,1365,1367);
// testing sort indicies
// var allVideoIndexes_obj = {};
// allVideoIndexes_obj.byName_arr = new Array(1296,1298,1300,1302);
// allVideoIndexes_obj.byCategory_arr = new Array(1296,1298,1302,1300);
// allVideoIndexes_obj.byDate_arr = new Array(1300,1302,1296,1298);

// ---- set up sorter ----
allVideoIndexes_obj.setUpSorter = function(args_arr){
    // -- initiate variables --
    
    // variables local to this function
    var curRowId = null;
    var curRowHTMLID = null;
    
    
    // variables for object
    this.ref_arr = [];
    // reference to the last inserted object
    this.lastInserted_ref = null;
    this.headRow_ref = null;
    this.par_ref = null;
    this.activeSort = [];
    this.activeSort['name'] = null;
    this.activeSort['ascending'] = true;
     
    this.statusImageRefs_arr = [];
    this.statusImageRefs_arr['name'] = null;
    this.statusImageRefs_arr['category'] = null;
    this.statusImageRefs_arr['date'] = null;
    this.statusImageSrcs_arr = [];
    // use this to count because string keys don't always increment correctly
    // this supplimental array is used instead
    this.statusMap_arr = ['name','category','date'];
    this.statusImageSrcs_arr['desc'] = null;
    this.statusImageSrcs_arr['asc'] = null;
    this.statusImageSrcs_arr['blank'] = null;
    
    this.statusImageRefs_arr['name'] = document.getElementById('nameStatusImage');
    this.statusImageRefs_arr['category'] = document.getElementById('categoryStatusImage');
    this.statusImageRefs_arr['date'] = document.getElementById('dateStatusImage');
    
    this.rowHTMLIDPrefix = 'not set';
    
    this.rowHtmlClasses = [];
    this.rowHtmlClasses['odd'] = null;
    this.rowHtmlClasses['even'] = null;
     
    this.byNameDesc_arr = [];
    this.byCategoryDesc_arr = [];
    this.byDateDesc_arr = [];
    this.matches_arr = [];

    this.lastestWasOdd = false;
    
    if(args_arr['initialSortName']){
        this.activeSort['name'] = args_arr['initialSortName'];
    }
     
    // avoided setting prefix to null as null will match anything in 
    // a prefix because null.length has length of zero
    // or will fail because null is not a string
    if(args_arr['rowHtmlClasses']['odd']){
        this.rowHtmlClasses['odd'] = args_arr['rowHtmlClasses']['odd'];
    }
    
    if(args_arr['rowHtmlClasses']['even']){
        this.rowHtmlClasses['even'] = args_arr['rowHtmlClasses']['even'];
    }
     
    if(args_arr['rowHTMLIDPrefix']){
        this.rowHTMLIDPrefix = args_arr['rowHTMLIDPrefix'];
    }
     
    if(args_arr['statusDesc']){
        this.statusImageSrcs_arr['desc'] = args_arr['statusDesc'];
        // testing code
        // alert('desc:' + this.statusImageSrcs_arr['desc']);
    }
    
    if(args_arr['statusAsc']){
        this.statusImageSrcs_arr['asc'] = args_arr['statusAsc'];
        // testing code
        // alert('asc:' + this.statusImageSrcs_arr['asc']);
    }
    
    if(args_arr['statusBlank']){
        this.statusImageSrcs_arr['blank'] = args_arr['statusBlank'];
        // testing code
        // alert('blank:' + this.statusImageSrcs_arr['blank']);
    }
    
    // create reference to the parent node 
    if(args_arr['parHTMLID']){
        this.par_ref = document.getElementById(args_arr['parHTMLID']);
        // testing code
        // alert(this.par_ref.id);
    }
    
    if(args_arr['searchInput'] != null){
        this.searchInp_ref = document.getElementById(args_arr['searchInput']);
    }else{
        this.searchInp_ref = null;
    }
    
    this.statusImg = [];
    
    if(args_arr['statusHTMLID'] != null){
        this.statusImg['ref'] = document.getElementById(args_arr['statusHTMLID']);
    }else{
        this.statusImg['ref'] = null;
    }
    
    this.statusImg['normalSrc'] = args_arr['statusSrc'];
    this.statusImg['backSrc'] = args_arr['statusBackSrc'];
    this.statusImg['backOverSrc'] = args_arr['statusBackOverSrc'];


    // if parent node not set return false 
    if(!this.par_ref){
        return false;
    }
        
    // testing code
    // alert('par ref id: ' + this.par_ref.id);
     
    // create descending indexes for each
    // byName_arr
    bi = this.byName_arr.length - 1;
    for(i=0 ; i<this.byName_arr.length ; i++){
       this.byNameDesc_arr.push(this.byName_arr[bi]);
       bi--; 
    }
     
    // testing code
    // alert(this.byNameDesc_arr.length);
     
    // byCategory_arr
    bi = this.byCategory_arr.length - 1;
    for(i=0 ; i<this.byCategory_arr.length ; i++){
       this.byCategoryDesc_arr.push(this.byCategory_arr[bi]);
       bi--; 
    }

    // testing code
    // alert(this.byNameDesc_arr.length);
    
    // byDate_arr
    bi = this.byDate_arr.length - 1;
    for(i=0 ; i<this.byDate_arr.length ; i++){
       this.byDateDesc_arr.push(this.byDate_arr[bi]);
       bi--; 
    }

    // testing code
    // alert(this.byNameDesc_arr.length);

    // create array of references

    // loop through byName_index and create the array keys 
    for(i=0 ; i<this.byName_arr.length ; i++){
        this.ref_arr[this.byName_arr[i]] = null;
    }
     
    // -- loop through the childnodes checking for the video row prefix -- 
    
    // get all child nodes of the parent element to the rows
    rows_arr = this.par_ref.childNodes;
            
    for(i=0;i < rows_arr.length; i++){
        // handle further if "Element" nodeType
        if(rows_arr[i].nodeType == 1){
            // alert('row id:' + rows_arr[i].id)
            // make the header references if header 
            if(rows_arr[i].id == 'allVideoHeader'){
                // testing code
                // alert('header found') ;
                 
                // create reference to the header row
                this.headRow_ref = rows_arr[i];
            }
            
            // scan for elemts whose id begings with the prefix 
            srch = this.rowHTMLIDPrefix;
            srchLen = srch.length;
            curRowHTMLID = rows_arr[i].id;
            if(curRowHTMLID.substring(0,srchLen) == srch){
                // grab the video id from the prefix
                curRowId = curRowHTMLID.substring(srchLen,rows_arr[i].id.length);
                // testing code
                // alert('video found:' + curRowId);
                // add as reference to the array 
                this.ref_arr[curRowId] = rows_arr[i];
            }
        }
    }
    
    // set initial sort
    if(this.activeSort['name'] != null){
         this.setActiveSort(this.activeSort['name'],this.activeSort['ascending']);
    }
}    

// ---- sorter function accepts index name
allVideoIndexes_obj.sortAllVideos = function(indexName){
    // initiate variablse local to this function
    var curRowRef = null;
    var nextSibling =  null;

    var indexToUse = [];

    // check against current sort, switch asc or desc if same
    // else if different set as  ascending sort
    if(indexName != this.activeSort['name']){
            this.activeSort['ascending'] = true;
    }else{
        if(this.activeSort['ascending']){
            this.activeSort['ascending'] = false;
        }else{
            this.activeSort['ascending'] = true;
        }
    }
    
    // set index to use variable by indexName argument
    if(indexName == 'name'){
        // check ascending or not and designate respective index for sorting
        if(this.activeSort['ascending']){
            indexToUse = this.byName_arr;
        }else{
            indexToUse = this.byNameDesc_arr;
        }
    }else if(indexName == 'category'){
        if(this.activeSort['ascending']){
            indexToUse = this.byCategory_arr;
        }else{
            indexToUse = this.byCategoryDesc_arr;
        }
    }else if(indexName == 'date'){
        if(this.activeSort['ascending']){
            indexToUse = this.byDate_arr;
        }else{
            indexToUse = this.byDateDesc_arr;
        }
    }
    
    // set the last inserted element ref to the header row
    this.lastInserted_ref = this.headRow_ref;
    
    // loop through index array
    for(i=0 ; i< indexToUse.length ; i++){
        curRowRef =  this.ref_arr[indexToUse[i]];
        // alert('video ' + i + ' under sort method ' + indexName + ' is ' + curRowRef.id );
        // move the video row div by adding it as a child element of the parent after the last inserted element
        
        // set background to be even or odd conditionally
        if(curRowRef.style.display != 'none'){
            this.labelOdd(curRowRef);
        }

        nextSibling = this.lastInserted_ref.nextSibling;
        this.par_ref.insertBefore(curRowRef,nextSibling);
        // testing code
        //this.par_ref.insertBefore(txt,this.lastInserted_ref);

        // make just inserted element last inserted
        this.lastInserted_ref = curRowRef;
        // repeat
    } 
         
    // setActive sort by calling set active sort function 
    this.setActiveSort(indexName,this.activeSort['ascending']);
}

// -- set the row background image to alternate between even and odd row colors
allVideoIndexes_obj.labelOdd = function(curRowRef){
    if(this.latestWasOdd){
        curRowRef.className = this.rowHtmlClasses['even'];
        this.latestWasOdd = false;
    }else{
        curRowRef.className = this.rowHtmlClasses['odd'];
        this.latestWasOdd = true;
    }
}

// -- show which category is visually sorted ----
allVideoIndexes_obj.setActiveSort = function(column,ascending){

    // initiate variables local to this function
    var activeSrc = '';
    var blankSrc = '';
    var curColumn = '';

    // type check the input arguments
    if(!(column == 'name' || column == 'category' || column == 'date')){
        return false;
    }else{

        this.activeSort['ascending'] = ascending;
        this.activeSort['name'] = column;

        // set image src url strings variables
        if(ascending){
            activeSrc = this.statusImageSrcs_arr['asc'];
        }else{
            activeSrc = this.statusImageSrcs_arr['desc'];
        }
        blankSrc = this.statusImageSrcs_arr['blank'];

        for(i=0 ; i<this.statusMap_arr.length ; i++){
            curColumn = this.statusMap_arr[i];
            if(curColumn == column){
                this.statusImageRefs_arr[curColumn].src = activeSrc;
            }else{
                this.statusImageRefs_arr[curColumn].src = blankSrc;
            }
        }
    }
}

// ---- search handler ----------
allVideoIndexes_obj.setToSearch = function(matches_arr,nonmatches_arr){

    var matchedCount = matches_arr.length;
    var notMatchedCount = nonmatches_arr.length;

    // alert(matchedCount + ' matches ' + notMatchedCount + 'nonmatches'); 

    // set the matches array 
    this.matches_arr = matches_arr;
    
    // loop through and hide non-matches 
    for(var i=0 ; i < nonmatches_arr.length; i++){
        curRowRef = this.ref_arr[nonmatches_arr[i]];
        curRowRef.style.display = 'none';
    }
    
    // loop through and order matches - relabel even odd
    for(var i=0 ; i < matches_arr.length ; i++){
        // alert('labeling');
        curRowRef = this.ref_arr[matches_arr[i]];
        curRowRef.style.display = 'block';
        this.labelOdd(curRowRef);
    }
    
    // show the search button
    this.setSearchStatus(true);

}

// -- clear search --
allVideoIndexes_obj.clearSearch = function(){
    var indexToUse = null;
    var curRowRef = null;
    // alert('clear search');
    
    // get the current sort method
    if(this.activeSort['name'] == 'name'){
        // check ascending or not and designate respective index for sorting
        if(this.activeSort['ascending']){
            indexToUse = this.byName_arr;
        }else{
            indexToUse = this.byNameDesc_arr;
        }
    }else if(this.activeSort['name'] == 'category'){
        if(this.activeSort['ascending']){
            indexToUse = this.byCategory_arr;
        }else{
            indexToUse = this.byCategoryDesc_arr;
        }
    }else if(this.activeSort['name'] == 'date'){
        if(this.activeSort['ascending']){
            indexToUse = this.byDate_arr;
        }else{
            indexToUse = this.byDateDesc_arr;
        }
    }


    // scroll through and set each row to visible
    for(i=0 ; i< indexToUse.length ; i++){
        curRowRef = this.ref_arr[indexToUse[i]];
        // make sure the node is visible - may have been hidden if 
        // not a match in a search
        curRowRef.style.display = 'block';
        // testing code
        // if(i < 20){
        //    alert('labeling');
        // }
        this.labelOdd(curRowRef);
    }

    // clear the search bar
    this.searchInp_ref.value = '';

    // hide the back to button
    this.setSearchStatus(false);
}

// -- function to set the status of weather a search is in order or not
allVideoIndexes_obj.setSearchStatus = function(active){
    
    // set image and any other display items for active search status
    if(active){
        this.statusImg['ref'].src = this.statusImg['backSrc'];
        this.statusImg['ref'].onmouseover = function(){
            this.src = allVideoIndexes_obj.statusImg['backOverSrc'];
        }
        this.statusImg['ref'].onmouseout = function(){
            this.src = allVideoIndexes_obj.statusImg['backSrc'];
        }
        this.statusImg['ref'].onclick = function(){
            allVideoIndexes_obj.clearSearch();
        }

    // set image and any other display items for non-search status
    }else{
        this.statusImg['ref'].src = this.statusImg['normalSrc'];
        this.statusImg['ref'].onmouseover = null;            
        this.statusImg['ref'].onmouseout = null;            
        this.statusImg['ref'].onclick = null;
    }

}

// ---- function wrappers to make calls globally accessible ----
function sortAllVideo(name){
    allVideoIndexes_obj.sortAllVideos(name);
}

