/* このJSは各ブログで共有されています。 */
/* 加えた変更は各ブログすべてに影響します。 */

document.observe("dom:loaded", function() { ContentInit(); });	// prototype.js(1.6.0 RC1)
// ↓ 二つ以上の指定には問題なし、ただしブラウザにより実際の実行順が異なる
//document.observe("dom:loaded", function() { alert('二つ目のdocument.observe("dom:loaded"が実行されました'); });

function ContentInit(){	// ページロード時に実行する処理を列挙する
Shadowbox.init();initLightbox();FormOpenDefine();
}

// ========== フォームのポップアップ定義 ==========

/* フォームへのリンクには、rel属性で
contactlink（フォームリンクの区別のための文字列：固定）,
ブログのパス（トップページの場合は「top」を指定）,
フォームファイル名（.htmlはつけない）
を指定する（カンマ区切りの配列にする） 
【指定例】<a href="/plate/printed_order.html" rel="contactlink,plate,printed_order"> */

function FormOpenDefine() {	// ページロード時にrel属性のあるリンクにonclickイベントを定義
  if (!document.getElementsByTagName) return false;

  var links = document.getElementsByTagName("a");
  for (var i=0; i<links.length; i++) {
       if (links[i].getAttribute("rel")){	// rel属性があるときのみ
           var RelAttr = links[i].getAttribute("rel");	// alert(RelAttr);
           if (RelAttr.indexOf('contactlink,',0) != -1 && RelAttr.indexOf('lightbox',0) == -1 && RelAttr.indexOf('shadowbox',0) == -1) 
              // rel属性に'contactlink,'があり、なおかつlightboxもshadowboxも含まれていないとき
              {
               links[i].onclick = function() { return FormOpen(this); };
               //alert(links[i].getAttribute("href") + 'へのリンクのrel属性にはlightboxもshadowboxも見つかりません');
           }
       }	// if(links[i]) end
  }	// for end
}	// function FormOpenDefine() end


function FormOpen(AnchorObj) {	// onclickで実行するフォームポップアップファンクション
  var RelAttrValue = AnchorObj.getAttribute("rel");	// alert(RelAttrValue);
  var RelAttrArray = RelAttrValue.split(',');	// alert(RelAttrArray);
  var FormFileName = RelAttrArray[2];	// alert(FormFileName);
  var FormBlogPath = RelAttrArray[1];
  FormBlogPath     = (FormBlogPath == 'top') ? '/' : '/' + FormBlogPath + '/';	// alert(FormBlogPath);

  var AnchorURL    = AnchorObj.getAttribute("href");	// alert(AnchorURL);
  //if (AnchorURL.indexOf('?') != -1) {alert('?が見つかりました')} else {alert('?は見つかりません')};
  var QueryStr     = (AnchorURL.indexOf('?') != -1) ? '&' + AnchorURL.split('?').pop() : '' ;	// alert(QueryStr);

  var MoveTo       = FormBlogPath + 'agree.html?' + FormFileName + QueryStr;	// alert(MoveTo);
  window.open(MoveTo,'subwin','toolbar=0,scrollbars=1,status=1,width=680,height=700');

  return false;	// リンクジャンプ抑止
}	// function Formopen() end




// ========== flash呼び出し ==========

function flashload(url, width, height, title, quality){	// 汎用

document.write( '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab=version=6,0,29,0" width="' + width + '" height="' + height + '" title="' + title + '">' );
document.write( '<param name="movie" value="' + url + '" />' );
document.write( '<param name="quality" value="' + quality + '" />' );
document.write( '<embed src="' + url + '" quality="' + quality + '" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>' );
document.write( '</object>' );

}	// function flashload() end


function youtubemovieload(id,width,height,rel){	// TouTUBE動画呼び出し
	// 埋め込み動画プレーヤーで関連動画表示オプションをオフにする場合、引数relに'no'を指定

var YouTube = 'http://www.youtube.com/v/';
if (rel == 'no'){var norelate = '&amp;rel=0'}else{var norelate = ''};

document.write('<object data="' + YouTube + id + norelate + '" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '">');
document.write('<param name="movie" value="' + YouTube + id + norelate + '" />');
document.write('<param name="wmode" value="transparent" />');
document.write('<embed src="' + YouTube + id + norelate + '" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" wmode="transparent">');
document.write('</embed></object>');

}	// function youtubemovieload() end


function youtubeplaylistload(id,width,height){	// TouTUBE動画再生リスト呼び出し

var YouTube = 'http://jp.youtube.com/p/';

document.write('<object data="' + YouTube + id + '" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '">');
document.write('<param name="movie" value="' + YouTube + id + '" />');
document.write('<param name="wmode" value="transparent" />');
document.write('<embed src="' + YouTube + id + '" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" wmode="transparent">');
document.write('</embed></object>');

}	// function youtubeplaylistload() end


