    var selStory = 'default';
    var selFaq = '';

    function openWin(url,name, wid, hgt) {
        if (wid && hgt)
            var newwin = window.open(url, name, 'width=' + wid + ',height=' + hgt + ',location=no,scrollbars=no,menubar=no,status=no,titlebar=no,toolbar=no');
        else
            var newwin = window.open(url, name, '');
        if (newwin) newwin.focus();
    }
    function openWinFB(url, name, wid, hgt) {
        if (wid && hgt)
            var newwin = window.open(url, name, 'width=' + wid + ',height=' + hgt + ',location=no,menubar=no,status=no,titlebar=no,toolbar=no');
        else
            var newwin = window.open(url, name, '');
        if (newwin) newwin.focus();
    }
    function logout(pathToRoot) {
        var cooks = null;
        $.get(pathToRoot + 'public/logoutajax.aspx', function(data) {
            var doms = data.split(":");
            cooks = doms[1].split(",");
            for (var cook in cooks) {
                if (doms[0] == "")
                    $.cookie(cooks[cook * 1], null, { path: '/' });
                else
                    $.cookie(cooks[cook * 1], null, { path: '/', domain: doms[0] });
            }

            var curpage = document.location.href;
            if (curpage.indexOf('public/artist.aspx') > -1)//page that needs full refresh
            {
                window.location.reload()
                return;
            }
            
            if ((location + "").indexOf("/secure/") >= 0) {//user was in secure area
                location=PathToRoot;
            }
            if (document.getElementById('helpframe'))
                document.getElementById('helpframe').contentWindow.location.reload();

        });
        if ((location+"").indexOf("/secure/") < 0) {//user was not in secure area
            $('#login').show('slow');
            $('#logout').hide();
        }

    }
    function login(username, status, artistURL) {
        var curpage = document.location.href;
        if (curpage.indexOf('public/artist.aspx') > -1)//page that needs full refresh
        {
            window.location.reload()
            return;
        }
        else //don't refresh page, fake out top part of the page
        {
            $('#username').text(username);
            $('#logout').show('slow');
            $('#login').hide();
            $('.artist').remove();
            if (status == "active") {
                if (artistURL != null) {
                    $('dd').addClass("big");
                    $('#lisettings').after("<li class=\"artist\"><a href=\"" + PathToRoot + "secure/user/sellmix.aspx\">Create Legitmix</a></li>" +
                "<li class=\"artist\"><a href=\"" + artistURL + "\">My Legitmixes</a></li>");
                }
                $('#lisettings').show();
            }
            var fr = document.getElementById('helpframe');
            if (fr)
                fr.src = fr.src
            // fr.contentWindow.location = fr.contentWindow.location;
        }
    }
    function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null)
            return "";
        else
            return decodeURIComponent(results[1].replace(/\+/g, " "));
    }
    function showBio(selector,pos) {
        if (pos != selStory) {
            
            if (pos == 'default') {
                $('#faqs-expanded-story .btn-close-alt').css('display','none');
            } else {
                $('#faqs-expanded-story .btn-close-alt').css('display','block');
                $(selector).addClass('sel');
            }
            
            if (selStory != 'default') {
                oldLink = $('#faqs-expanded-story .col-r a').get(selStory);
                $(oldLink).removeClass('sel');
            }
            
            $('#story-'+selStory).stop(true).fadeOut('fast', function() {
                $('#story-'+pos).stop(true).fadeIn('fast');
                selStory = pos;
            });
            
        }
    }
    
    function resetBio() {
        $('#faqs-expanded-story .btn-close-alt').css('display','none');
        if (selStory != 'default') {
            $('#story-'+selStory).hide();
            oldLink = $('#faqs-expanded-story .col-r a').get(selStory);
            $(oldLink).removeClass('sel');
        }
        $('#story-default').show();
        selStory = 'default';
    }
    
    function prevFaq() {
        // figure out new element to be shown, move into position
        newIndex = (selFaq - 1);
        if (newIndex < 0) {
            newIndex = 3;
        }
        newEle = $('.faqs-expanded').get(newIndex);
        $(newEle).css('left', '-944px');
        $(newEle).show();
        // slide both elements
        curEle = $('.faqs-expanded').get(selFaq);
        $(curEle).stop(true).animate({left: '936px'}, 200, function() {
            // reset the element that was hidden
            $(curEle).hide();
            $(curEle).css('left','-4px');
        })
        $(newEle).stop(true).animate({left: '-4px'}, 200);
        selFaq = newIndex;
    }
    
    function nextFaq() {
        // figure out new element to be shown, move into position
        newIndex = (selFaq + 1);
        if (newIndex > 3) {
            newIndex = 0;
        }
        newEle = $('.faqs-expanded').get(newIndex);
        $(newEle).css('left', '936px');
        $(newEle).show();
        // slide both elements
        curEle = $('.faqs-expanded').get(selFaq);
        $(curEle).stop(true).animate({left: '-944px'}, 200, function() {
            // reset the element that was hidden
            $(curEle).hide();
            $(curEle).css('left','-4px');
        })
        $(newEle).stop(true).animate({left: '-4px'}, 200);
        selFaq = newIndex;
    }

    function prevArtistPanel() {

        var curpanelid = $(".artist-win:visible").attr("id")
        var curpanel = curpanelid.substring(10) * 1;

        var newIndex = (curpanel - 1);
        if (newIndex < 0) {
            newIndex = panels-1;
        }
        newEle = $('#artist-win'+newIndex);
        $(newEle).css('left', '-670px');
        $(newEle).show();
        // slide both elements
        curEle = $('#'+ curpanelid );
        $(curEle).stop(true).animate({ left: '670px' }, 400, function() {
            // reset the element that was hidden
            $(curEle).hide();
            $(curEle).css('left', '0px');
        })
        $(newEle).stop(true).animate({ left: '0px' }, 400);
     }

     function nextArtistPanel() {

         var curpanelid = $(".artist-win:visible").attr("id")
         var curpanel = curpanelid.substring(10) * 1;

         var newIndex = (curpanel + 1);
         if (newIndex >= panels) {
             newIndex = 0;
         }
         newEle = $('#artist-win' + newIndex);
         $(newEle).css('left', '670px');
         $(newEle).show();
         // slide both elements
         curEle = $('#' + curpanelid);
         $(curEle).stop(true).animate({ left: '-670px' }, 400, function() {
             // reset the element that was hidden
             $(curEle).hide();
             $(curEle).css('left', '0px');
         })
         $(newEle).stop(true).animate({ left: '0px' }, 400);
    }


    $(document).ready(function() {

        $(".dropdown dt a").click(function() {

            // Change the behaviour of onclick states for links within the menu.
            var toggleId = "#" + this.id.replace(/^link/, "ul");

            // Hides all other menus depending on JQuery id assigned to them
            $(".dropdown dd ul").not(toggleId).hide();

            //Only toggles the menu we want since the menu could be showing and we want to hide it.
            $(toggleId).toggle();

            //Change the css class on the menu header to show the selected class.
            if ($(toggleId).css("display") == "none") {
                $(this).removeClass("selected");
            } else {
                $(this).addClass("selected");
            }

        });

        $(".dropdown dd ul li a").click(function() {

            // This is the default behaviour for all links within the menus
            var text = $(this).html();
            $(".dropdown dt a span").html(text);
            $(".dropdown dd ul").hide();
        });

        $(document).bind('click', function(e) {

            // Lets hide the menu when the page is clicked anywhere but the menu.
            var $clicked = $(e.target);
            if (!$clicked.parents().hasClass("dropdown")) {
                $(".dropdown dd ul").hide();
                $(".dropdown dt a").removeClass("selected");
            }

        });


        // hide expanded faqs
        $('.faqs-expanded-plate').hide();
        $('.faqs-expanded').hide();

        // collapsed faqs
        $('.box-faqs .faqs-item').each(
            function() {
                $(this).bind({
                    'mouseenter': function() {
                        $(this).css('background-position', '0px 0px');
                    },
                    'mouseleave': function() {
                        $(this).css('background-position', '0px -145px');
                    },
                    click: function(e) {
                        e.preventDefault();
                        curIndex = $('.box-faqs .faqs-item').index(this);
                        if (curIndex == 1) {
                            // exception for team bios
                            resetBio();
                        }
                        shownEle = $('.faqs-expanded').get(curIndex);
                        $('.faqs-expanded-plate').stop(true).slideDown('fast', function() {
                            $('.faqs-expanded-close').css('display', 'block');
                            $('.faqs-expanded-hide-l').css('display', 'block');
                            $('.faqs-expanded-hide-r').css('display', 'block');
                            $(shownEle).stop(true).fadeIn('fast');
                            selFaq = curIndex;
                        })
                    }
                })
            }
        );

        // close button for expanded faqs
        $('.faqs-expanded-close').bind({
            click: function(e) {
                e.preventDefault();
                shownEle = $('.faqs-expanded').get(selFaq);
                $(shownEle).stop(true).fadeOut('fast', function() {
                    $('.faqs-expanded-close').css('display', 'none');
                    $('.faqs-expanded-hide-l').css('display', 'none');
                    $('.faqs-expanded-hide-r').css('display', 'none');
                    $('.faqs-expanded-plate').stop(true).slideUp('fast', function() {
                        selFaq = '';
                    })
                })
            }
        });

        // previous button for expanded faqs
        $('.btn-prev-faq').each(
            function() {
                $(this).bind({
                    click: function(e) {
                        e.preventDefault();
                        prevFaq();
                    }
                })
            }
        );

        // next button for expanded faqs
        $('.btn-next-faq').each(
            function() {
                $(this).bind({
                    click: function(e) {
                        e.preventDefault();
                        nextFaq();
                    }
                })
            }
        );


            // previous button for expanded faqs
            $('.btn-prev-artist').each(
            function() {
                $(this).bind({
                    click: function(e) {
                        e.preventDefault();
                        prevArtistPanel();
                    }
                })
            }
        );

            // next button for expanded faqs
            $('.btn-next-artist').each(
            function() {
                $(this).bind({
                    click: function(e) {
                        e.preventDefault();
                        nextArtistPanel();
                    }
                })
            }
        );


        // expanded team member bios
        $('#faqs-expanded-story .col-r a').each(
            function(index) {
                $(this).bind({
                    'click': function(e) {
                        e.preventDefault();
                        showBio(this, index);
                    }
                })
            }
        );

        // expanded team member bios close
        $('#faqs-expanded-story .btn-close-alt').bind({
            click: function(e) {
                e.preventDefault();
                showBio(this, 'default');
            }
        });

        // mini thumbs, artist & label page
        $('.sml-thumbs img').tipsy({ gravity: 's', html: true });

        // hidden faqs video, artist & label page
        $('.box-faqs-video').hide();
        $('.box-faqs-teaser .btn-learn-more').bind({
            click: function(e) {
                e.preventDefault();
                //    		    $('.box-faqs-teaser').fadeOut('fast', function() {
                //    		        $('.box-faqs-video').fadeIn('slow');
                //    		        $('html, body').animate({scrollTop: $('#content').height()}, 200);
                //    		    });
                $('.box-faqs-teaser').hide();
                $('.box-faqs-video').fadeIn('fast');
                $('html, body').animate({ scrollTop: $('#content').height() }, 200);

            }
        });
        $('.box-faqs-video .btn-faqs-hide').bind({
            click: function(e) {
                e.preventDefault();
//                $('.box-faqs-video').slideUp('fast', function() {
//                    $('.box-faqs-teaser').fadeIn('fast');
                //                });

                $('.box-faqs-video').fadeOut('fast', function() {
                    $('.box-faqs-teaser').fadeIn('fast');
                });


            }
        });

        // hidden subtracks, mix page
        $('.sub-tracks').hide();

        // expand/collapse arrows for subtracks, mix page
        $('.subtrack-arr').each(
            function(index) {
                $(this).toggle(function(e) {
                    e.preventDefault();
                    $(this).parent().parent().children('.sub-tracks').slideDown('slow');
                    $(this).toggleClass('arr-sel');
                }, function(e) {
                    e.preventDefault();
                    $(this).parent().parent().children('.sub-tracks').slideUp('fast');
                    $(this).toggleClass('arr-sel');
                });
            }
        );

        // hint, mix page
        $('.box-mix-info .mix-hint').tipsy({ gravity: 's', opacity: 1, html: true });
        $('.mix-hint').tipsy({ gravity: 's', opacity: 1, html: true });
        
        // Settings page - affiliate hint
        $('.affiliate .hint').tipsy({ gravity: 's', opacity: 1, html: true });
        
    });

    var playing = null;
    var paused = null;
    var files = null;
    var elems = null;
    var mixCuePoints = [1]; // Default. Set each time by server.
    var defaultCuePoints = [1, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000, 21000, 22000, 23000, 24000, 25000, 26000, 27000, 28000, 29000, 30000];
    var cuePoints = null;
    var flowPlayerReady = false; // Set to true once flowplayer is loaded and ready.
    var fptId = null;
    var flashSupported = false;    

// Flowplayer CuePoints
//    var CuePointFunc = function(clip, cuepoint) {
//        console.log("first cuepoint: done waiting");
//        if (playing.waiting) {
//            console.log("first cuepoint: done waiting");
//            playing.aelem.className = "pause";
//            playing.waiting = false;
//        }
//        else if (playing.index == 0) {
//            //console.log("progress " + cuepoint / 1000 + " seconds");
//            $('#mix-progress').width($('#mix-progress').width() + 1);
//        }
    //    };

    function flowplayerSetup() {

        if (flashembed.isSupported([6, 65])) {
            flashSupported = true;
        }
        else {
            $('#player1').hide();
            $('#notice-bar').show().animate({ top: '0px' }, 800);
            return;
        }    
    
        $f("player1", PathToRoot + "flowplayer/flowplayer-3.2.7.swf", {
            plugins: {
                controls: null,
                audio: {
                    url: PathToRoot + 'flowplayer/flowplayer.audio-3.2.2.swf'
                },
                rtmp: {
                    url: PathToRoot + 'flowplayer/flowplayer.rtmp-3.2.3.swf'
                }
            }
                ,
            onLoad: function() {
                this.onCuepoint(mixCuePoints, function(clip, cuepoint) {
                    if (playing.waiting || playing.aelem.className == "wait") {
                        playing.aelem.className = "pause";
                        playing.waiting = false;
                    }
                    else if (playing.index == 0) {
                        $('#mix-progress').width($('#mix-progress').width() + 1);
                    }
                });
                flowPlayerReady = true;
            }
        });
    }

 function resetPreview(fileIndex, elem) {
     elem.className = "preview";

     elem.onclick = function() {
         playPreview(fileIndex, elem);
     };

     // Reset progress on mix preview
     if (fileIndex == 0) {
         $('#mix-progress').width(0);
         $('#mixPreview').hide();         
     }

     if (playing!=null && playing.next!=null && playing.next > totalSrcCount) {
        // Reset Preview All button
        var pa = document.getElementById('previewAll');
        pa.className = "btn-preview-all";
        pa.onclick = function() { playPreview(1, document.getElementById('play_button_1'), 2); };
    }     
          
     playing = null;
 }

 function playPreview(fileIndex, elem, nextFile) {

     if (!flashSupported) return;
     
     // Do nothing if the file path is empty
     if (files[fileIndex] == "") return;

     elem.className = "wait";

     // Wait for flowplayer to be ready.
     if (!flowPlayerReady) {
        if (fptId!=null) clearTimeout(fptId);
        fptId = setTimeout("playPreview(" + fileIndex + ",document.getElementById('play_button_" + fileIndex + "')" + (nextFile != null ? "," + nextFile : "") + ")", 1000);
        return;
     }
 
     if (playing != null) {
         if (playing.aelem != elem) {
             resetPreview(playing.index, playing.aelem)
         }
         else {
             pausePreview(fileIndex, elem);
             return;
         }
     }
     else if (paused != null && paused.aelem != elem) { // Really only needed for main mix preview because play button is hidden on sources when paused.        
        resetPreview(paused.index, paused.aelem)
    }
    
    playing = { aelem: elem, file: files[fileIndex], index: fileIndex, next: nextFile, waiting: true };
    paused = null;

     $f().stop();
     var item = {};
     if (nextFile != null) {
         if (elem.parentNode.parentNode.previousSibling == null && elem.parentNode.parentNode.parentNode.className.indexOf("sub-tracks") >= 0 && elem.parentNode.parentNode.parentNode.style.display=="none") {             
             var arr = elem.parentNode.parentNode.parentNode;             
             $(arr).prev().children(':first-child').next().click();
         }
         if (nextFile <= totalSrcCount) {
             item.onBeforeFinish = function() { resetPreview(fileIndex, elem); playPreview(nextFile, document.getElementById('play_button_' + nextFile), nextFile + 1); }
         }
     }
     if (item.onBeforeFinish == undefined) item.onFinish = function() { resetPreview(fileIndex, elem); }
     
     if (fileIndex == 0) {
         // Do something         
     }
     else {
         item.duration = 30 // Limit source preview to 30 seconds         
     }
     //item.duration = 3; // For testing
     if (files[fileIndex].match(/\.m4a$/))//iTunes preview
     {
         item.url = files[fileIndex];
     }
     else {
         if (files[fileIndex].indexOf("|") >= 0) {
             var fparts = files[fileIndex].split("|");
             if (fparts.length > 1) {
                 item.netConnectionUrl = fparts[0];
                 item.url = fparts[1];
                 item.provider = 'rtmp';
             }
             else {
                 item.url = files[fileIndex];
                 item.provider = "audio";
             }
         }
         else {
             item.url = files[fileIndex];
             item.provider = "audio";
         }
     }
     $f().setClip(item);
     var ref = $f().play().getClip();     
     
     if (item.onFinish != undefined) { ref.onFinish(item.onFinish); }
     if (item.onBeforeFinish != undefined) { ref.onBeforeFinish(item.onBeforeFinish); }
     var pa = document.getElementById('previewAll');
     if (pa) {
         if (nextFile > 0) {
             pa.className = "btn-pause-all";
             pa.onclick = function() { pausePreview(fileIndex, elem); };
         }
         else { // Not controlling "Preview All". Reset Preview All button.         
             pa.className = "btn-preview-all";
             pa.onclick = function() { playPreview(1, document.getElementById('play_button_1'), 2); };
         }
     }     
     elem.className = "wait";
     elem.onclick = function() { pausePreview(fileIndex, elem); };     
 }

 function pausePreview(fileIndex, elem) {
     $f().pause();
     $(elem).unbind('click');

     if (elem.className != "preview") {
         elem.className = "preview";
         elem.onclick = function() {
             resumePreview(fileIndex, elem);
         };
     }

     if (playing.next > 0) {
         // Sync preview-all button
         var pa = document.getElementById('previewAll');
         if (pa.className == "btn-pause-all") {
             pa.className = "btn-preview-all";
             pa.onclick = function() { resumePreview(fileIndex, elem); };
         }
     }

     paused = { aelem: elem, file: files[fileIndex], index: fileIndex, next: playing.next };
     playing = null;
 }

 function resumePreview(fileIndex, elem) {
     if (paused && paused.aelem == elem) {     
         $f().resume();

         // Check preview all and sync
         if (paused.next > 0) {
             var pa = document.getElementById('previewAll');
             if (pa.className == "btn-preview-all") {                 
                 pa.className = "btn-pause-all";
                 pa.onclick = function() { pausePreview(fileIndex, elem); };
             }
         }
         
         elem.className = "pause";
         $(elem).unbind('click');
         elem.onclick = function() {
             pausePreview(fileIndex, elem);
         };

         playing = { aelem: elem, file: files[fileIndex], index: fileIndex, next: paused.next };
         paused = null;
     }
     else playPreview(fileIndex, elem);
 }

 function showMessage(subj, txt, width, height, type) {
     $('applet').css({ "width": 0, "height": 0 });

     $('#screen').css({ "background-color": "#000", "display": "block", opacity: 0.7, "width": $(document).width(), "height": $(document).height() });
     $('#box').css({ opacity: 0.9, "width": width, "height": height, "margin-left": (-0.5 * width), "margin-top": (-1 * height / 2 - 40) });
     $('#box').fadeIn('slow');

     $("#boxcontent").text('');
     $(txt).appendTo("#boxcontent");
     $("#messagetitle").text(subj);

     if (type == 1) {
         $("#closemessage").hide();
     } else $("#closemessage").show();

     $(window).resize(function() {
         if ($('#box').css("display") != 'none') resize(subj, txt, width, height, type);
     });
     $(window).scroll(function() {
         if ($('#box').css("display") != 'none') resize(subj, txt, width, height, type);
     });
 }

 function hideMessage() {
     return;
     $('#box').fadeOut('fast');
     $('#message').fadeOut('fast');
     $('#screen').fadeOut('fast'); //$('applet').css({ "width": appletwidth*1, "height": appletheight*1 });
     if (hasApplet) {

         //           var app=document.getElementById("divApplet").childNodes[4];
         //           app.style.width=(appletwidth*1+1)+"px";
         //           app.style.height=(appletheight*1+1)+"px";
         $('applet').css({ "width": appletwidth * 1, "height": appletheight * 1 + 1 });
         //appletwidth+=1;
         appletheight += 1;

         // $('applet').width(appletwidth*1+0);
         //  $('applet').height(appletheight*1+0);
     }
     $(window).unbind('scroll');
     $(window).unbind('resize');
     // noresize = true;
 }

 function getParameterByName(name) {
     name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
     var regexS = "[\\?&]" + name + "=([^&#]*)";
     var regex = new RegExp(regexS);
     var results = regex.exec(window.location.href);
     if (results == null)
         return "";
     else
         return decodeURIComponent(results[1].replace(/\+/g, " "));
 }

 function SubmitControl(id, buttonplch, action, successplch, errorplch) {
     $("#" + buttonplch).append('<a id="' + id + '" class="submit">Submit</a>');
     $("#" + id).click(function() {
         $("#" + buttonplch).append('<img style="margin:15px 0px 0px 10px; position:absolute" id="waitgif" src="' + PathToRoot + 'images/lmanimationtiny.gif"/>');
         var res = action();
         $("#waitgif").remove();
         if (res === true) { $("#" + successplch).append("Your changes have been saved successfully."); setTimeout('$("#' + successplch+'").html("")', 5000); }
         else $("#" + errorplch).append(res);
     });
     this.getlinks = function(xmlDoc) { }
 }

 function flipSlides(step, pstep,width) {
     if (pstep == null) {
         pstep = step - 1;
     }
     $('#slide' + step).css('left', width+'px');
     $('#slide' + step).show();

     $('#slide' + pstep).stop(true).animate({ left: '-'+width+'px' }, 200, function() {
         // reset the element that was hidden
         $('#slide' + pstep).hide();
         $('#slide' + pstep).css('left', '0px');
     })
     $('#slide' + step).stop(true).animate({ left: '0px' }, 200);
 }

 function arrayClone(arr) {
     var newObj = (arr instanceof Array) ? [] : {};
     for (i in arr) {
         if (i == 'clone') continue;
         if (arr[i] && typeof this[i] == "object") {
             newObj[i] = arrayClone(arr[i]);
         } else newObj[i] = arr[i]
     } return newObj;
 };

 function ValidURL(url) {
     var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
     return regexp.test(url);
 }
 function GetLength(seconds) {
     var time = "";
     var mins = Math.floor(seconds / 60);
     var secs = seconds - 60 * mins;
     secs = secs.toFixed(0);
     var hours = Math.floor(mins / 60);
     mins = mins - 60 * hours;
     //    time += hours > 9 ? hours + ":" : 0 + "" + hours + ":";
     //    time += mins > 9 ? mins + ":" : 0 + "" + mins + ":";
     //    time += secs > 9 ? secs : 0 + "" + secs ;


     //     time = hours + "h" + mins + "m" + secs + "s";

     return time;

 }

 function GetMaxLength(seconds) {
     var time = "";
     var mins = Math.ceil(seconds / 60);
     var secs = seconds - 60 * Math.floor(seconds / 60);
     secs = secs.toFixed(0);
     var hours = Math.ceil(mins / 60);
     if (mins > 50 && mins <= 60) return "1 hour";
     else if (hours > 2) return hours + " hours";
     else return mins + " minute" + (mins > 1 ? "s" : "");
     //    else return "1 minute";
     //  else if (secs > 0) return secs + " second" + (secs > 1 ? "s" : "");
 }

 String.prototype.trunc =
     function(n, useWordBoundary) {
         var toLong = this.length > n;
         var s_ = "";
         s_ = toLong ? this.substr(0, n / 2 - 1) : this + "";
         s_last = toLong ? this.substr(this.length - n / 2, this.length - 1) : "";

         s_ = useWordBoundary && toLong ? s_.substr(0, s_.lastIndexOf(' ')) : s_;
         return toLong ? s_ + '...' + s_last : s_;
     };
