var opt= {
	scrolling     : 'no',
	transitionIn	: 'elastic',
	transitionOut	: 'elastic',
//	easingIn     : 'backout',
//	easingOut     : 'backin',
//	speedOut: 300,
//	speedIn: 300,
	titlePosition	: 'inside',
	overlayColor	: 'black',
	padding	:0,
	margin	:0,
	autoScale:false,
	onComplete: function(el){

	},
	onStart:function(selectedArray, selectedIndex, selectedOpts){
		var boxH = $(window).height();
		var boxW = $(window).width();
		boxH = Math.round(boxH*0.9);
		boxW = Math.round(boxW*0.9);
		boxW = boxW > 860 ? 860 : boxW;
		selectedOpts.width = boxW;
		selectedOpts.height = boxH;
		if(document.body.id=='videos'){
			selectedOpts.height = boxH > 480 ? 480 : boxH;
			selectedOpts.width = selectedOpts.height*1.7;
		}
	},
	type:'iframe',
	autoDimensions: false
};
$(document).ready(function (){
	if($.browser.msie){
		$('#content').wrap('<div/>');
	}
	init();
});
function setPlay(){
	if(window.top.sound.playing){
		$('a#jp-play').hide();
		$('a#jp-pause').show();
	}
	else {
		$('a#jp-play').show();
		$('a#jp-pause').hide();
	}
}
function init() {
	if(window.top != window.self){
//		console.log(window.top.sound.playing);
		if(typeof player_command != 'undefined' && player_command=='play'){
			$('a#jp-play').hide();
			$('a#jp-pause').show();
		}
		else {
			$('a#jp-play').show();
			$('a#jp-pause').hide();
		}
	}
	$('#jp_container_1').click(function(){
		if(window.top != window.self){
			/*frameset*/
			if(window.top.sound.playing){
				window.top.sound.pause();
			}
			else {
				window.top.sound.play();
			}
			setPlay();
		}
		else {
			$.get(baseUrl+'/sound/play',function(){
				window.location.href = window.location.href + '?s=on';
			});

			$('a#jp-play').show();
			$('a#jp-pause').hide();
		}
		return false;
	});
	$('.fancybox').fancybox(opt);

	var ajaxbox = $('.fancybox-ajax');
	if(ajaxbox.length > 0){
		ajaxbox.fancybox(getAjaxOptions());
	}


	if(typeof message != 'undefined'){
		var o = opt;
		delete o.type;
//		o.width=620;
//		o.height='auto';
		o.autoDimensions = true;
		o.padding=40;
//		o.margin=40;
		$.fancybox(message,opt);
	}

	$('.fancybox').fancybox(opt);

	$(window).resize(function() {
	   layout();
	});

	var maxH = 0;
	var contentH = $('#content').height();

	var ratio = $('#content').width()/contentH;

	$.each($('#flowGallery img') ,function(){
		maxH = Math.max(maxH,this.height);
	});

	if(typeof ImageFlow == 'function'){
		gallery = new ImageFlow();
		gallery.init({
			ImageFlowID: 'flowGallery',
			onClick: function() {
				if( $(this).attr('longdesc')){
					opt.href =$(this).attr('longdesc');
					$.fancybox(getAjaxOptions());
				}
				return false;
			},
			reflections: false,
			reflectionP: 0.0,
			circular: true,
			captions:false,
			startID: (typeof startID != 'undefined'? startID : 0),
			percentLandscape:170,
			aspectRatio: ratio,
			imagesHeight: 0.92,
			xStep: 100,
			percentOther:65
		});
	}
	if(typeof $.PikaChoose == 'function'){
		$("#pikame").PikaChoose({

					carousel:true,
					autoPlay:false,
					text: {previous: '', next:'' },
					carouselOptions:{visible: typeof countImages != 'undefined' ? (countImages > 20 ? 20 : countImages) : 10},
					thumbOpacity:0.8,
					startOn: typeof startID != 'undefined' ? startID : 0
				}
		);
		setSliderSizes();
	}

	$(".lavaLamp").lavaLamp({ fx: "backout", speed: 700 });
	$('li.back, #login-link a').click(function(){
		login();
		return false;
	});

	$('ul.checkbox li').click(function(){
		$(this).parent().find('span').html('');
		$(this).find('span').text('v');
		$('form#job').find('input#checkgroup').val($(this).find('label').text());
	});
	$('#scroller').jScrollPane({});

}
function getAjaxOptions(){
	var aopt = opt;
	aopt.type = 'ajax';
	aopt.onComplete = function(el){
		$('#frame-scroller').css('height',$('#fancybox-content').height()-80).fadeIn(600);
		$('#frame-scroller').jScrollPane({});
	};
	return aopt;
}
function login(){
	var o = opt;
	o.type='ajax';
	o.autoDimensions = true;
	o.overlayShow=false;
	o.onStart=function(){};
	o.href=baseUrl+'/member';
	$.fancybox(opt);
}
function layout(){
	var windowH = $(window).height();
	var naviH = 200;
	var posL =  Math.round(($(document.body).width()-560)/4 - 60);
	$('#logo').css('left',posL);
	$('#jp_container_1').css('left',posL);
	$('#social').css('right',posL);
	$('#login-link').css('right',posL);
	$('div.header,div.footer').css('width',$(window.document.body).width());
	var h = document.body.id!='frame' ? windowH - naviH - 40 : windowH - 70;
	$('#content').css('height',h);
//	if(document.body.id=='admin'){
//		$('#content').css('min-height',windowH - naviH - 30);
//		return;
//	}
	$('#content #scroller').css('height',h-40);
	$('#scroller').jScrollPane({
			showArrows: false,
			verticalArrowPositions: 'before',
			horizontalArrowPositions: 'before'
		}
	);
//	if($('#logoHome').length > 0){
//		var h = windowH-naviH + 30;
//		$('#logoHome').attr('height',h).css('margin-top',((windowH - h + 60)/2)+'px');
//	}
	/*
	 * slideshow
	 */
	setSliderSizes();
}
function setSliderSizes(){
	if($('div.pika-stage').length == 0)return;
	var height = $('#content').height() - $('.jcarousel-container').height()-8;
	$('div.pika-stage').css({
		height:height,
		width:height*1.5
	});

}






