﻿Event.observe(window, 'load', function(){
	var menu = ['top', 'radio','kanko','event','other'];
	menu.each(function(e){
		new RollOverImage(e,'/images/new_top/menu/'+e+'_over.gif');
	});
});


var Player = Class.create();
Player.prototype = {
	initialize: function(num,mw,mh) {
		this.num = num;
		this.playmode = 'false';
		this.mw = (mw==undefined) ? 405 : mw;
		this.mh = (mh==undefined) ? 382 : mh;
	},
	showFlv: function(){
		if(location.href.match(/medias\/show\/\d+/)) this.playmode = 'true';
		var temp = ['<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" id="FLVPlayer" height="%s" width="%s">'.sprintf(this.mh, this.mw),
		'<param name="movie" value="/swfs/flv_player.swf">',
		'<param name="salign" value="lt">',
		'<param name="quality" value="high">',
		'<param name="wmode" value="transparent" />',
		'<param name="scale" value="noscale">',
		'<param name="FlashVars" value="streamName=%s&amp;autoPlay=%s">'.sprintf(this.num, this.playmode),
		'<embed src="/swfs/flv_player.swf" flashvars="streamName=%s&amp;autoPlay=%s" quality="high" scale="noscale" name="FLVPlayer" salign="LT"  wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" height="%s" width="%s">'.sprintf(this.num, this.playmode, this.mh, this.mw),
		'</object>'].join('');;
		$('media_player').innerHTML = temp;
	},
	showMp3: function(){
		return false;
	}
}

function showBlog(){
	var s = document.createElement('script');
	s.src = 'http://radiocafe.jp/cgi-bin/news/hightubesubaruism.cgi';
	s.charset = 'UTF-8';
	s.type = 'text/javascript';

	document.body.appendChild(s);
}
function showBlogList(json){
	if(!json['rdf:RDF'].item) return;
	var items = json['rdf:RDF'].item;
	var temp =  document.createElement('div');
	var e  = items;
	items.each(function(e){
		var content = e['content:encoded'];
		var entry = document.createElement('div');
		if(content.match(/skinNo=1/)){
			content = content.replace(/width="296"/g,'width="240"');
			content = content.replace(/height="42"/g,'height="35"');
		}
		if(!content.match(/img/) && !content.match(/\.swf/))
		content = content.substr(0,50) + '･･･';
		entry.innerHTML = '<h4><a href="%s" target="_blank">%s</a></h4>'.sprintf(e.link,e.title) + content;
		entry.className = 'entry';
		temp.appendChild(entry)
	});
	$('blog_info').appendChild(temp);
	//$('blog_navi').innerHTML = '<p>どなたでも投稿いただけます。　　 <a href="mailto:post-hightube_yokohama@blog.seesaa.jp">投稿はこちら</a>(添付ファイルは25MBまで)　<a href="http://whatismedia.seesaa.net">投稿一覧</a></p>';
}

String.prototype.sprintf = function(){
	var temp = this.split('%s');
	var arg = arguments;
	
	var text = temp.map(function(e,index){
		var rep = (index<arg.length)?arg[index]:'';
		return e + rep;
	});

	return text.join('');
}


function get_response_text ( text ) {
	if ( navigator.appVersion.indexOf( "KHTML" ) > -1 ) {
		var esc = escape( text );
		if ( esc.indexOf("%u") < 0 && esc.indexOf("%") > -1 ) {
			text = decodeURIComponent( esc );
		}
	}
	return text;
}

Ajax.Updater = Class.create();

Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
  initialize: function(container, url, options) {
    this.containers = {
      success: container.success ? $(container.success) : $(container),
      failure: container.failure ? $(container.failure) :
        (container.success ? null : $(container))
    }

    this.transport = Ajax.getTransport();
    this.setOptions(options);

    var onComplete = this.options.onComplete || Prototype.emptyFunction;
    this.options.onComplete = (function(transport, object) {
      this.updateContent();
      onComplete(transport, object);
    }).bind(this);

    this.request(url);
  },

  updateContent: function() {
    var receiver = this.responseIsSuccess() ?
      this.containers.success : this.containers.failure;
    var response = get_response_text(this.transport.responseText);

    if (!this.options.evalScripts)
      response = response.stripScripts();

    if (receiver) {
      if (this.options.insertion) {
        new this.options.insertion(receiver, response);
      } else {
        Element.update(receiver, response);
      }
    }

    if (this.responseIsSuccess()) {
      if (this.onComplete)
        setTimeout(this.onComplete.bind(this), 10);
    }
  }
});