/**
@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.11b"; :created "2010-09-02"];
  :author [:name "Keisuke Mori"] .
*/


$(document).ready(function(){

var s4d2010 = {
	over: 'hover',
	smart: $.support.boxModel,
	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,
		_lag: 0,
		bglag: 0,
		fade: 60,
		spd: 480,
		ease: 'easeInOutCubic',
		changed: false,
		html: $('html').width()
	},
	gallery: {
		spd: 240
	},
	paging: {
		place: ''
	},
	form: {
		spd: 240,
		ease: 'easeInOutQuad'
	},
	scrll: {
		spd: 960,
		ease: 'easeOutQuart'
	}
}

if (!s4d2010.smart) {
	try { document.execCommand("BackgroundImageCache",false,true); }catch(e){}
}

/*
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;
});

if ( $('#noscript').length != 0 ) {
	$('#noscript').hide();
	function hideModal(e) {
		$(this).blur();
		$('#galleryModal:visible').fadeOut('slow', function(){
			$('#galleryModal').remove();
		} );
		return false;
	}
	var gallery = $('#galleryModalThumbs').galleriffic({
		delay:                     2500,
		imageContainerSel:         '#slideshow',
		controlsContainerSel:      '#controls',
		captionContainerSel:       '#caption',
		loadingContainerSel:       '#loading',
		renderSSControls:          false,
		renderNavControls:         true,
		playLinkText:              'Play',
		pauseLinkText:             'Pause',
		prevLinkText:              'Prev',
		nextLinkText:              'Next',
		defaultTransitionDuration: 600
	});
	
	$('#slideshow').attr('aria-live', 'polite');
	$('#galleryModalClose').attr('role', 'button');
	$('#galleryModalControl').show();
	$('#galleryModalClose').live('click', function() {
		$(this).blur();
		hideModal();
		return false;
	});
	$('#galleryModal:hidden').fadeIn('slow');
}


$('#gallery-thumb a').css('outline', 'none').click(function(){
	var loadFile = $(this).attr('href');
	$(this).blur();
	if ( $('#galleryModal').length == 0 ) {
		$('body').append('<div id="galleryModal" class="galleryModal" />');
	}
	$('#galleryModal').load(loadFile + ' #galleryModalInner', function() {
		$('#galleryModalThumbs').galleriffic({
			delay:                     2500,
			enableBottomPager:         false,
			imageContainerSel:         '#slideshow',
			controlsContainerSel:      '#controls',
			captionContainerSel:       '#caption',
			loadingContainerSel:       '#loading',
			renderSSControls:          false,
			renderNavControls:         true,
			playLinkText:              'Play',
			pauseLinkText:             'Pause',
			prevLinkText:              'Prev',
			nextLinkText:              'Next',
			defaultTransitionDuration: 600
		});
	});
	$('#slideshow').attr('aria-live', 'polite');
	$('#galleryModalClose').attr('role', 'button');
	$('#galleryModal').fadeIn(s4d2010.gallery.spd);
	$('#toTop').css('z-index', 0);
	
	$(this).blur();
	return false;
});

function hideModal(e) {
	$('#galleryModal:visible').fadeOut(s4d2010.gallery.spd, function(){
		$('#galleryModal').remove();
	} );
	$('#toTop').css('z-index', 1000);
	return false;
}


$('html').keyup(function(e){
	if (e.keyCode == '27' ) {
		hideModal();
	}
});
$('#galleryModalClose').live('click', function() {
	$(this).blur();
	hideModal();
	return false;
});

if (!$.support.leadingWhitespace) {
	$('#galleryModalControl a').live('hover', function() {
		$(this).css({ 'top': '12px' });
	}).live('mousedown', function() {
		$(this).css({ 'top': '13px' });
	}).live('mouseup', function() {
		$(this).css({ 'top': '12px' });
	});
}

$('#galleryModalClose').live('click', function() {
	hideModal();
	return false;
});



$('<img />').attr('src','/_assets/img/gallery/bgi-loader.gif');
$('<img />').attr('src','/_assets/img/bgi-gnav_over.png');
$('<img />').attr('src','/_assets/img/bgi-hna_over.png');
$('<img />').attr('src','/_assets/img/bgi-linklist_over.png');
$('<img />').attr('src','/_assets/img/bgi-submitBtn_over.png');
$('<img />').attr('src','/_assets/img/ico-external_over.png');
$('<img />').attr('src','/_assets/img/ico-dot_over.png');
if (!s4d2010.smart) {
	$('<img />').attr('src','/_assets/img/basic/txt-billboard_over.png');
	$('<img />').attr('src','/_assets/img/basic/ico-external_over.png');
	$('<img />').attr('src','/_assets/img/basic/bgi-hna_over.png');
	$('<img />').attr('src','/_assets/img/basic/bgi_hna_left_over.png');
	$('<img />').attr('src','/_assets/img/basic/bgi-submitBtn_over.png');
}


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

if ( $('#securityInner').length != 0 ) {
	$('#securityInner').append('<div id="securityInnerContent" aria-live="polite" />');
	$('#securityInnerContent').load('/privacy/ #main-inner div');
}
$('#tglSecurity').click(function() {
	$('#securityInnerContent').slideToggle(s4d2010.form.spd, s4d2010.form.ease);
	return false;
});


if (!s4d2010.smart) {
	$('#contactBtn, #btnFix').hover(
		function() { $(this).addClass('hover'); },
		function() { $(this).removeClass('hover'); }
	).focus(function()  { $(this).addClass('hover'); })
	.blur(function()  { $(this).removeClass('hover'); });
}


});