document.write('<script type="text/javascript" src="/js/coco_newcomer.js"></script>');
document.write('<script type="text/javascript" src="/js/AjaxPages.js"></script>');
var is_data_loaded = false;
var is_ajax_pages_loaded = false;

setTimeout( "init();", 100 );

function init() {
    try{
	   var script = document.getElementsByTagName( 'script' );
    	for ( var i = 0; i < script.length; i++ ) {
	       if ( script[i].src.search( /AjaxPages/i ) > 0 ) {
                is_ajax_pages_loaded = true;
    		} else if ( script[i].src.search( /coco_newcomer/i ) > 0 ) {
    			is_data_loaded = true;
    		}
        }
        document.getElementById( 'SubNewcomer' ).innerHTML = '';
    } catch(e){
        setTimeout( "init();", 100 );
        return;
    }
    if ( is_data_loaded && is_ajax_pages_loaded ) {
        set_prototype();
        main();
    } else {
        setTimeout( "init();", 100 );
    }
}

function main()  {
    var ajp;
    try {
	   ajp = new AjaxPages();
           ajp.load( '/js/tt/new_comer.ajp' );
    }catch(e){
        setTimeout( "init();", 100 );
        return;
    }
    var processor = ajp.getProcessor();
    output( processor( {data:new_comer_data} ) );
}

function output( outputHTML ) {
    document.getElementById('SubNewcomer').innerHTML = outputHTML;
}

function set_prototype() {
    Array.prototype.nextRand = function() {
        var now = new Date();
        var num = Math.floor( ( Math.random() * 1000 ) + now.getSeconds() ) % this.length;
        if ( this.num_list === void 0 ) {
            this.num_list = new Array();
        }
         if ( this.counter === void 0 ) {
            this.counter = 0;
        }
    
        if ( this.num_list[ num.toString() ] ) {
            return this.nextRand();
        }
        this.num_list[ num.toString() ] = true;
        this.counter ++;
        return this[num];
    }

    Array.prototype.hasNext = function() {
      if ( this.counter === void 0 ) {
         this.counter = 0;
       }
        if ( this.counter < this.length ) {
            return true;
        } else {
            return false;
        }
    }
}

function publish_type( type ) {
    if ( type == 0 ) {
        return '<img src="http://www.podcastjuice.jp/material/image/ico_sound.gif" width="62" height="18" alt="Sound" />';
    } else if ( type == 1 ) {
        return '<img src="http://www.podcastjuice.jp/material/image/ico_video.gif" width="62" height="18" alt="Video" />';
    } else {
        return '';
    }
}

function trunc( str, num ) {
    if ( str.length > num ) {
        return str.substring( 0, num ) + '…';
    } else {
        return str;
    }
}
