// JavaScript Document

$(function(){
var _footerPrint = $("#print-inner");
var _printContents = "/print/womb.html"; // print 読み込み先
$(_footerPrint).load(_printContents);

_tweetFunc();

function _tweetFunc(){// twitter api sample より改変
                                               function tweet() {
                                                   permalink  = $(this).attr("href");
                                                   tweettitle = $(this).attr("title");
                                                   var login  = 'womb';
                                                   var apiKey = 'R_b36a1180be08526b341b36e3a600f1f9';
                                                   bitly = 'http://api.bit.ly/shorten?version=2.0.1&format=json&callback=twitterCallback'+ '&login=' + login+ '&apiKey=' + apiKey + '&longUrl=';
                                                   var script = document.createElement('script');
                                                   script.type = 'text/javascript';
                                                   script.src = bitly + encodeURIComponent(permalink) ;
                                                   document.body.appendChild(script);
                                                   
                                                   return false;
                                               }
                                               (function (){
                                                    $('#contents a.forTwitterLink').each(function(){
                                                                                             var twitterImg = $('<img width="16" height="16" alt="Share on Twitter" src="/_common/img/icon/foot_btn_twitter.gif">');
                                                                                             var permalink  = $(this).attr("href");
                                                                                             tweettitle = $(this).text();
                                                                                             var login  = 'womb';
                                                                                             var apiKey = 'R_b36a1180be08526b341b36e3a600f1f9';
                                                                                             var bitly = 'http://api.bit.ly/shorten?version=2.0.1&format=json&callback=twitterCallback'+ '&login=' + login+ '&apiKey=' + apiKey + '&longUrl=';
                                                                                             var script = $('<script type="text/javascript"></script>');
                                                                                             script.attr("src", bitly + encodeURIComponent(permalink));
                                                                                             $("body").append(script);
                                                                                             
                                                                                             $(this).attr("target", "_blank");
                                                                                             $(this).html(twitterImg);
                                                                                             //$(this).click(tweet);
                                                                                             $(this).show();
                                                                                         });
                                                })();
       }
	 
	 
	$('a[href^="http://"]').attr("target", "_blank"); 
	
	$('[href^="http://youtube.com"]','#contents').css({'display':'none'});
});

function twitterCallback(bitlyResponse) {
    for (var i in bitlyResponse.results) {
        var orignUrl = i;
        var shortUrl = bitlyResponse.results[i]['shortUrl'];
        break; // 一個目を強制的に取り出す。
    }
    var url = 'http://twitter.com/home/?status='+ encodeURIComponent(tweettitle + ' ' + shortUrl); 

    $('#contents a.forTwitterLink').each(function(){
                                             var href = $(this).attr("href");
                                             if(href == orignUrl){
                                                 $(this).attr("href", url);
                                             }
                                         });

    return false;
}

// JavaScript Document
// For Tweet Event Schedule






//history.forward();

