// JavaScript Document
$(document).ready(function(){
	$("img[src*='_off.']").rollOver();
	$("button").rollOver("img");
	$("a.pn[href^='#']").smScroll();
	$(".ar").alphaRo({from:1, to:0.8, group:false});
	$("a[rel='jump']").anotherWin({width:750});

	var strUA = navigator.userAgent.toLowerCase();
	if(navigator.userAgent.indexOf("MSIE 6")>=0){
		$(".tel img").fixPng();
	}
});

function mainImage() {
	var baseDir = 'img/index/';
	var imgFileList = ['back.jpg', 'back02.jpg', 'back03.jpg'];
	var rnd = Math.floor(Math.random()*imgFileList.length);
	var height = getContentsHeight();
	$("#backImage").css("height", height);
	if( rnd>0 ) {
		$("#backImage img").attr('src', baseDir+imgFileList[rnd]).load( function() {
			$("#backImage img").fadeIn(8000);
		} );
	} else {
		$(window).load( function() {
			$("#backImage img").fadeIn(8000);
		} );
	}
	$(window).resize( function() {
		var width = getBrowserWidth();
		var height = getContentsHeight();
		$("#backImage").css("height", height);
		if( width < 1100 ) {
			if( width<960 ) {
				$("#backImage").css("width", 960);
				width = 960;
			} else {
				$("#backImage").css("width", "100%");
			}
			var mag = (1100-width)/2;
			$("#backImage img").css({ "width":1100, "margin-left": -mag});
		} else {
			$("#backImage").css("width", "100%");
			$("#backImage img").css({ "width":"100%", "margin-left":0 });
		}
	} );
}

// getBrowserWidth() by Cameron Adams
// http://www.themaninblue.com/experiment/ResolutionLayout/
function getBrowserWidth () {
    if ( window.innerWidth ) { return window.innerWidth; }
    else if ( document.documentElement && document.documentElement.clientWidth != 0 ) { return document.documentElement.clientWidth; }
    else if ( document.body ) { return document.body.clientWidth; }
    return 0;
}

function getBrowserHeight() {
	if ( window.innerHeight ) { return window.innerHeight; }  
	else if ( document.documentElement && document.documentElement.clientHeight != 0 ) { return document.documentElement.clientHeight; }  
	else if ( document.body ) { return document.body.clientHeight; }  
	return 0;  
}

function getContentsHeight() {
	var h = Math.max( document.body.clientHeight , document.body.scrollHeight );
	h = Math.max( h , document.documentElement.scrollHeight );
	h = Math.max( h , document.documentElement.clientHeight );
	return h;
}
