/*================================================
	page scroll 
================================================*/
var is_top = true; // top flag

Event.observe(window, 'load', function(){
//wResizeHandler();
//window.onresize = wResizeHandler;
shuffle_pictures();

// for narrow width pc
if (screen.height < 768) {
applyCSS(document, '/mt-static/themes/josuikan/css/layout-m.css');
}

// for apple
if (navigator.userAgent.indexOf('iPad') != -1) {
	clearMovie();
}else if(navigator.userAgent.indexOf('iPhone') != -1){
	clearMovie();
	applyCSS(document, '/mt-static/themes/josuikan/css/index-i.css');
    applyCSS(document, '/mt-static/themes/josuikan/css/layout-m.css');
}else{
}
});



function setVerticalMiddle(targetObj){
		var contentsHeight = Element.getHeight(targetObj); 
		var mainHeight = Element.getHeight($('wrapper')); 
		if(targetObj == $('contents')){
			var naviHeight = 80;
			mainHeight = mainHeight-naviHeight;
		}
		targetObj.style.top = (mainHeight-contentsHeight)/2 + 'px';
}
function wResizeHandler(){
	setVerticalMiddle($('contents'));
	setVerticalMiddle($('menu'));
	setVerticalMiddle($('mark'));
	
	
	//$('mask').style.width = (Element.getWidth($('main'))  ) + 'px';

}

function shuffle_pictures()
{
    var shuffle = [];
    var photos = $('photolist').getElementsByTagName('IMG');
    var arr = [];
    var pair = [];
    for (var i=0,j=photos.length; i<j; i++){ arr.push(i); }
    
    for (var i=0,j=photos.length; i<j; i++){
        photos[i].id = "top_photo_"+i;
        var num = arr.length;
        var x = Math.floor(Math.random()*num);
        pair.push(arr[x]);
        if (i%2 == 1){
            shuffle.push(pair);
            pair = [];
        }
        arr = arr.without(arr[x]);
    }
    
    for (i=0,j=shuffle.length; i<j; i++){
//        $('photolist').replaceChild($('top_photo_'+shuffle[i][0]), $('top_photo_'+shuffle[i][1]));
        var src1 = $('top_photo_'+shuffle[i][0]).src;
        var src2 = $('top_photo_'+shuffle[i][1]).src;
        $('top_photo_'+shuffle[i][0]).src = src2;
        $('top_photo_'+shuffle[i][1]).src = src1;
        
        var href1 = $('top_photo_'+shuffle[i][0]).parentNode.href;
        var href2 = $('top_photo_'+shuffle[i][1]).parentNode.href;
        $('top_photo_'+shuffle[i][0]).parentNode.href = href2;
        $('top_photo_'+shuffle[i][1]).parentNode.href = href1;
        
        var alt1 = $('top_photo_'+shuffle[i][0]).alt;
        var alt2 = $('top_photo_'+shuffle[i][1]).alt;
        $('top_photo_'+shuffle[i][0]).alt = alt2;
        $('top_photo_'+shuffle[i][1]).alt = alt1;
        $('top_photo_'+shuffle[i][0]).parentNode.title = alt2;
        $('top_photo_'+shuffle[i][1]).parentNode.title = alt1;
    }
}

try { 
    document.execCommand('BackgroundImageCache', false, true); 
} catch(e) {} 

