////////////////////////////////////////////
//////////////////////////////////////
//////////////////////////////
///////////////// 2010.07.07
//// Programed by Nori(http://3oclock.com/)
//// Twitter : @nori_togoru
/////////////////////////////
//////////////////////////////
/// Original By below: Thank you!
/***
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)

***/
// history //
////////////
// set finish page "/gallery.html"
//
//2010.07.29 support IE5,6,7 with no animation
//2010.08.06 bug fix(#flash)  for IE
//


function slideSwitch(whichNum) {
var nextpage
var $next
var $active


if (whichNum == "" || whichNum == "/"){
//for IE && top page without anchor
whichNum = "s1"
var nextpage = 'div#slideshow div#'+whichNum
var $next = $(nextpage)
$next.css({visibility:"visible"})
$next.addClass("active")
}else if (whichNum.slice(1) > maxNum){
//lastpage

location.href = returnpage;

}else{
var $active = $('div#slideshow div.active');
var nextpage = 'div#slideshow div#'+whichNum
var $next = $(nextpage)


if (jQuery.support.opacity || jQuery.browser.version >= "8.0" ){

$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
if (whichNum == "t1"){
$("div#slideshow div.slide").css({opacity:0.0})
}
});
}else{
// for do not support opacity property 
// example of  IE6 , IE7 
// no use last-active class   

$active.css({visibility:"hidden"})
$active.removeClass('active');
$next.css({visibility:"visible"})
        $next.addClass('active')
if (whichNum == "t1"){
$("#slideshow div.slide").css({visibility:"hidden"})
}

}
}
}

$(document).ready(function(){
//rollover image button
$('.navi a img').rollover();

SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);
function handleChange(event) {
var tid = SWFAddress.getValue()

var startpos = tid.indexOf("/")
if ( startpos >= 0){
tid = tid.substring(startpos+1)
}
slideSwitch(tid)

if(tid== "t1"){
SWFAddress.setTitle(_photo_subject_+ " thumbnails | bitGallery" );
}else if (tid==""){
tid = "1"
SWFAddress.setTitle(_photo_subject_+ " " +tid+"/"+maxNum +" | bitGallery" );
}else{
tid = tid.slice(1)
SWFAddress.setTitle(_photo_subject_+ " " +tid+"/"+maxNum +" | bitGallery" );
}


}

});

function tweet() {
    var login  = 'togoru'; // bitly username
    var apiKey = 'R_41bc178a6c09f4bf4a2098843a7dbd00'; // bitly API Key
    bitly = 'http://api.bit.ly/shorten' 
        + '?version=2.0.1&format=json&callback=callback'
        + '&login=' + login
        + '&apiKey=' + apiKey + '&longUrl=';
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = bitly + encodeURIComponent(location.href) ;
    document.body.appendChild(script);

  }

  function callback(bitlyResponse) {
    var title = '[ ' + document.title + ' ]';
    var url = 'http://twitter.com/home/?status=' 
        + encodeURIComponent(
             title + ' ' 
               + bitlyResponse.results[location.href]['shortUrl'] + ' ' + '#bitgallery #photo '
  );
location.href = url;  
  }
  
/**
 * jQuery.rollover
 *
 * @version  1.0.2
 * @author   rew <rewish.org@gmail.com>
 * @link     http://rewish.org/javascript/jquery_rollover_plugin
 * @license  http://rewish.org/license/mit The MIT License
 *
 * Inspired by:
 * Telepath Labs (http://dev.telepath.co.jp/labs/article.php?id=15)
 *
 * Usage:
 * jQuery(document).ready(function($) {
 *   // <img>
 *   $('#nav a img').rollover();
 *
 *   // <input type="image">
 *   $('form input:image').rollover();
 *
 *   // set suffix
 *   $('#nav a img').rollover('_over');
 * });
 */
jQuery.fn.rollover = function(suffix) {
suffix = suffix || '_on';
return this.not('[src*="'+ suffix +'."]').each(function() {
var img = jQuery(this);
var src = img.attr('src');
var _on = [
src.substr(0, src.lastIndexOf('.')),
src.substring(src.lastIndexOf('.'))
].join(suffix);
jQuery('<img>').attr('src', _on);
img.hover(
function() { img.attr('src', _on); },
function() { img.attr('src', src); }
);
});
};

