/**
@prefix : <http://purl.org/net/ns/doas#> .
<> a :JavaScript;
  :title "SiTE4D 2010 javascript";
  :shortdesc "Common javascript for XHTML pages of this site";
  :created "2010-05-11";
  :release [:revision "0.1"; :created "2010-05-11"];
  :author [:name "Keisuke Mori"] .
*/


if ($.browser.msie && $.browser.version < 7) {
	var ie6Loc = document.location.href.replace('site4d.co.jp', 'site4d.co.jp/2009');
	location.href = ie6Loc;
}

$(document).ready(function(){

var s4d2010 = {
	layout: {
		btn: {
			left: '<div id="layoutChangeLeft" class="layoutChange" role="button" title="レイアウトを変更する" />',
			right: '<div id="layoutChangeRight" class="layoutChange" role="button" title="レイアウトを変更する" />'
		},
		base: $('#wrapper').offset().left,
		lag: 0,
		bglag: 0,
		fade: 60,
		spd: 480,
		ease: 'easeInOutCubic',
		changed: false,
		html: $('html').width()
	},
	gallery: {
		spd: 240
	},
	paging: {
		place: ''
	},
	scrll: {
		spd: 960,
		ease: 'easeOutQuart'
	}
}


function changed() {
	if ( s4d2010.layout.changed == false ) {
		s4d2010.layout.changed = true;
	}
	else {
		s4d2010.layout.changed = false;
		$('html').css('overflow-x', 'auto');
	}
}

function changing() {
	$('#layoutChangeLeft, #layoutChangeRight').fadeOut(10);
	setTimeout(function () {
		$('#layoutChangeLeft, #layoutChangeRight').fadeIn(10);
	}, s4d2010.layout.spd);
}

$('#header').append(s4d2010.layout.btn.left, s4d2010.layout.btn.right);
$('.layoutChange').fadeIn(s4d2010.layout.fade);


$('#layoutChangeLeft').click(function(){
	s4d2010.layout.base = new $('#wrapper').offset().left;
	s4d2010.layout.base = s4d2010.layout.base - s4d2010.layout.lag;
	if ( s4d2010.layout.base <= 0 ) s4d2010.layout.base = s4d2010.layout.base * -1;
	var _lag = String(s4d2010.layout.base);
	_lag = _lag + 'px';
	changing();
	if ( s4d2010.layout.changed == false ) {
		if ( $('#flower-container').find('.first-child').css('display') != 'none' ) {
			$('#flower-container').find('.first-child').fadeOut(s4d2010.layout.spd);
		}
		if ( $('#flower-container').find('.last-child').css('display') == 'none' ) {
			$('#flower-container').find('.last-child').fadeIn(s4d2010.layout.spd);
		}
		$('html').css('overflow-x', 'hidden');
		$('#page')
			.animate({ left: '-=' + _lag }, s4d2010.layout.spd, s4d2010.layout.ease, changed);
		$('.tweet-container')
			.fadeOut(s4d2010.layout.spd);
	} else {
		$('#flower-container').find('.first-child').fadeIn(s4d2010.layout.spd);
		$('#flower-container').find('.last-child').fadeIn(s4d2010.layout.spd);
		$('#page')
			.animate({ left: 0 }, s4d2010.layout.spd, s4d2010.layout.ease, changed);
		$('.tweet-container')
			.fadeIn(s4d2010.layout.spd);
	}
});

$('#layoutChangeRight').click(function(){
	s4d2010.layout.base = new $('#wrapper').offset().left;
	s4d2010.layout.base = s4d2010.layout.base - s4d2010.layout.lag;
	if ( s4d2010.layout.base <= 0 ) s4d2010.layout.base = s4d2010.layout.base * -1;
	var _lag = String(s4d2010.layout.base);
	changing();
	if ( s4d2010.layout.changed == false ) {
		if ( $('#flower-container').find('.first-child').css('display') == 'none' ) {
			$('#flower-container').find('.first-child').fadeIn(s4d2010.layout.spd);
		}
		if ( $('#flower-container').find('.last-child').css('display') != 'none' ) {
			$('#flower-container').find('.last-child').fadeOut(s4d2010.layout.spd);
		}
		$('html').css('overflow-x', 'hidden');
		$('#page')
			.animate({ left: _lag }, s4d2010.layout.spd, s4d2010.layout.ease, changed);
		$('.tweet-container')
			.fadeOut(s4d2010.layout.spd);
	} else {
		$('#flower-container').find('.first-child').fadeIn(s4d2010.layout.spd);
		$('#flower-container').find('.last-child').fadeIn(s4d2010.layout.spd);
		$('#page')
			.animate({ left: 0 }, s4d2010.layout.spd, s4d2010.layout.ease, changed);
		$('.tweet-container')
			.fadeIn(s4d2010.layout.spd);
	}
});


function paging(context) {
	s4d2010.paging.place = $('#progress').css('width');
	s4d2010.paging.place = s4d2010.paging.place.replace('px', '');
	s4d2010.paging.place = Number(s4d2010.paging.place);
	if ( context == 'prev' ) {
		if ( s4d2010.paging.place > 0 ) s4d2010.paging.place = s4d2010.paging.place - 5;
	} else if ( context == 'next' ) {
		if ( s4d2010.paging.place < 49 ) s4d2010.paging.place = s4d2010.paging.place + 5;
	}
	s4d2010.paging.place = String(s4d2010.paging.place);
	s4d2010.paging.place = s4d2010.paging.place + 'px';
	$('#progress').animate({ 'width': s4d2010.paging.place }, 'fast');
}

$('#pgPrev').click(function(){ $(this).blur(); paging('prev'); });
$('#pgNext').click(function(){ $(this).blur(); paging('next'); });


$('#toTop').click(function () {
	$(this).blur();
	var target = $('#header').offset().top;
	if($.browser.opera) $('html').animate({ scrollTop: target }, s4d2010.scrll.spd, s4d2010.scrll.ease );
	else $('html,body').animate({ scrollTop: target }, s4d2010.scrll.spd, s4d2010.scrll.ease );
	return false;
});




$('#gallery-thumb a').css('outline', 'none').click(function(){
	var loadFile = $(this).attr('href');
	$(this).blur();
	if ( $('#galleryModal').length == 0 ) {
		$('body').append('<div id="galleryModal" />');
	}
	$('#galleryModal').load(loadFile);
	$('#galleryModal').fadeIn(s4d2010.gallery.spd, function(){
		$('#galleryModalClose')
			.addClass('active')
			.focus();
	} );
	
	$(this).blur();
	return false;
});

function hideModal(e) {
	$('#galleryModal:visible').fadeOut(s4d2010.gallery.spd, function(){
		$('#galleryModal').remove();
	} );
	return false;
}
$('html').keyup(function(e){
	if (e.keyCode == '27' ) {
		hideModal();
	}
});
$('#galleryModal').blur(function(){
	$(this)
		.removeClass('active');
});


$('#galleryModalClose').live('click', function() {
	hideModal();
	return false;
});
$('<img />').attr('src','/_assets/tmp/_assets/img/gallery/loader.gif');
$('<img />').attr('src','/_assets/tmp/_assets/img/bg_g-nav-hover.png');
$('<img />').attr('src','/_assets/tmp/_assets/img/bg_hn-a-hover.png');
$('<img />').attr('src','/_assets/tmp/_assets/img/bg_linklist-hover.png');


if ( $('#lastname').length != 0 ) { $('#lastname').focus(); }


$.s4dTweet({
	id: 'arashi',
	tweet: 'iPadでのサイトの見え方が確認できるiPadのシュミレーター　http://ipadpeek.com'
});
$.s4dTweet({
	id: 'hakase',
	tweet: 'いよいよ始まったようじゃの。'
});
$.s4dTweet({
	id: 'gordon',
	tweet: 'こーるどふゅーじょん。わくわく。'
});
$.s4dTweet({
	id: 'humbolt',
	tweet: 'ヽ(｀Д´)ﾉソレ、ワタシノ！アト、ソレ コン平！！RT @tycho_s4d: ≡≡≡ﾍ(*ﾟ∇ﾟ)ﾉ はいはいはーいっ！ちゃら〜んっ！RT @eriots: やまだくんにざぶとん3枚っ☞RT @humboldt_s4d: (✌ﾟ∀ﾟ)☞ズーーーム インッ！！'
});
$.s4dTweet({
	id: 'tycho',
	tweet: '≡≡≡ﾍ(*ﾟ∇ﾟ)ﾉ はいはいはーいっ！ちゃら〜んっ！RT @eriots: やまだくんにざぶとん3枚っ☞RT @humboldt_s4d: (✌ﾟ∀ﾟ)☞ズーーーム インッ！！'
});

});


/**
@prefix : <http://purl.org/net/ns/doas#> .
<> a :JavaScript;
  :title "SiTE4D 2010 Tweet javascript";
  :shortdesc "tiny jQuery plugin for XHTML pages of this site. ";
  :created "2010-05-14";
  :release [:revision "0.1"; :created "2010-05-14"];
  :author [:name "Keisuke Mori"] .
*/

(function ($) {

	jQuery.s4dTweet = function (c) {
		c = $.extend({
			spd: 120
		}, c);
		if (c) {
			if (c.id) {
				c.container = $('<div id="tweet-' + c.id + '" class="tweet-container" />');
				c.container.append($('<div class="tweet-chara" />'));
			}
			if (c.tweet) {
				c.box = $('<div class="tweet-box" />');
				c.box.append($('<div class="tweet-box-top"></div>'));
				c.box.append($('<div class="tweet-box-mdl" />').text(c.tweet));
				c.box.append($('<div class="tweet-box-btm"></div>'));
			}
			c.container.append(c.box);
		}
		$('body').append(c.container);
		
		c._container = $('#tweet-' + c.id);
		c.chara = $(c._container).find('.tweet-chara');
		c._box = $(c._container).find('.tweet-box');

		$(c._box).hide();
		
		$(c.chara).hover(
			function() {
				if (!$.browser.msie) $(c._box).fadeIn(c.spd);
				else $(c._box).show();
			},
			function() {
				if (!$.browser.msie) $(c._box).fadeOut(c.spd);
				else $(c._box).hide();
			}
		).click(function(){
			$(c._box).hide();
			location.href = 'http://www.site4d.co.jp/twitter/';
		});
		
	};

})(jQuery);



