/*---------------------------------+

すきなばしょ
design by Isao Watanabe 
up date:2010/01/07
Copyright (c) 2010 Sukina Basho. All Rights Reserved.

+----------------------------------*/
var setMap;
var obj;
var path = '/wp-content/themes/sukinabasho';

//set up sukinabashoUI
function sukinabasho(){
	jQuery('body').css('overflow','hidden');
	jQuery('a.blank').attr('target','_blank');
	jQuery('a.popup').popupwindow(profiles);
	
	var brCk = this.getUserAgent();
	var layoutType = jQuery('body').attr('id');
	
	if(brCk == 'ie6'){
		jQuery('div#guidance').css('display','block');
	}
	
	jQuery('a.blank,a.popup').bind('click', function(){
		jQuery('div#guidance').css('display','block').html('<p class="btnBdMsg"><img src="' + path + '/images/common/btn_stopIconWin.gif" alt="クリックすると再開します。" width="200" height="53" class="badm10" /></p>');
		jQuery('p.btnBdMsg').bind('click', function(){jQuery(this).parent().css('display','none')});
	
	});

	/*thickbox*/
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
	
	if(layoutType == 'layoutThree'){
		this.init();
		this.layoutControl();
		setContentScroll();
		//check box
		jQuery('input#agree').bind('click', function(){
			var ck = jQuery(this).attr('checked');
			if(ck == true){jQuery('div#btnAgree').after('<div id="btn"><a href="/wp-login.php?action=register">登録する</a></div>');
			}else if(ck == false){jQuery('div#btn').remove();}
		});
	}
	if(layoutType == 'layoutTwo'){
		setMap = new setGmap();
		setMap.init();
		this.init();
		this.layoutControl();
		setContentScroll();
		startSlideShow();
		jQuery('div#innerWrapper a').attr('target', '_blank').addClass('blank');
		jQuery('div#innerWrapper a.blank').bind('click', function(){
			jQuery('div#guidance').css('display','block').html('<p class="btnBdMsg"><img src="' + path + '/images/common/btn_stopIconWin.gif" alt="クリックすると再開します。" width="200" height="53" class="badm10" /></p>');
			jQuery('p.btnBdMsg').bind('click', function(){jQuery(this).parent().css('display','none')});
		});
	}
	if(layoutType == 'top'){
		setMap = new setGmap();
		setMap.init();
		var x = $('div#contentsList div.eLayout').length;
		this.init();
		this.infniteScroll();
		setContentScroll();
	}
	
}

sukinabasho.prototype = {
	init : function(){
		this.setBtnFooter();
		this.setCloseBtn();
		this.setContentListAction();
		this.setPageTop();
		jQuery(window).bind('resize', this.layoutControl);
	},
	layoutControl : function(){
		var size = jQuery(window).height();
		jQuery('div#contentsWrapper').css('height', size);
		var scrollArea = jQuery('div#contents');
		var cw = jQuery('div#contentsWrapper').css('top');
		var wh = size - cw.match(/\w/);
		jQuery('div#scrollBar').css('top','0');
		scrollArea.css({'overflow' : 'hidden'});
		var elmHeight = scrollArea.height();
		if(size < elmHeight){
			scrollArea.css({'height' : wh + 'px'});
			scrollArea.scrollTop(0);
			jQuery('div#scrollBar').css('display','block');
		}else if(size > elmHeight){
			scrollArea.css({'height' : wh + 'px'});
			jQuery('div#scrollBar').css('display','none');
		}
	},
	setBtnFooter : function (){
		jQuery('li#btnCntrlPn a').bind('click',function(){
			if(jQuery(this).attr('class') == 'on'){
				jQuery(this).removeClass('on');
				jQuery('div#footerWrapper').css('display','none');
			}else{
				jQuery(this).addClass('on');
				jQuery('div#footerWrapper').css('display','block');
		}
		
		});
	},
	setCloseBtn : function (){
		jQuery('div#btnClose').bind('click', function(){
			if(jQuery(this).attr('class') == 'on'){
				jQuery('div#contentsWrapper').animate({left: '-700px'},250);
				jQuery(this).removeClass('on');
			}else{
				jQuery('div#contentsWrapper').animate({left: '0px'},250);
				jQuery(this).addClass('on');
			}
		});	
	},
	setPageTop : function (){
		jQuery('div.pageTop').bind('click',function(){
			jQuery('div#contents').scrollTop(0);
			jQuery('div#scrollBar').css('top','0px');
		});
	},
	setContentListAction : function (){
		var num = 0;
		jQuery('div#contentsList div.eLayout').each(function(){
			num++;
			jQuery(this).attr('id', 'map' + num);
			jQuery('#map' + num).bind('mouseover', function(){
				jQuery(this).addClass('choiceList');
				setMap.ChengeMap(this);
			});
			
			jQuery('#map' + num).bind('mouseout', function(){
				jQuery(this).removeClass('choiceList');
			});
			
		});
	},
	scrollBtnControl : function(){
		scrollBtnControlLogic();
		jQuery(window).bind('resize', function(){scrollBtnControlLogic();});
	},
	getUserAgent : function(){
		var ua = $.browser;
		var re;
		if(ua.msie && ua.version < 7){
			re = 'ie6';
		}else{
			re = 'ok';
		}
			return re;
	},
	infniteScroll : function(){
	}
}

function scrollBtnControlLogic(){
		var size = jQuery(window).height();
		var elmHeight = jQuery('div#contents').height();
		if(size < elmHeight){
			jQuery('div#btnScrollUp, div#btnScrollDown').css('display', 'block');
		}else if(size > elmHeight){
			jQuery('div#btnScrollUp, div#btnScrollDown').css('display', 'none');
		}
}

//function setWindowEvent(){jQuery(window).bind('unload', GUnload);}

var profiles ={
	window800:{
		height:800,
		width:800,
		status:1
	},
	window200:{
		height:200,
		width:200,
		status:1,
		resizable:0
	},
	windowCenter:{
		height:300,
		width:400,
		center:1
	},
	windowNotNew:{
		height:300,
		width:400,
		center:1,
		createnew:0
	}
};

jQuery(document).ready(function(){
	obj = new sukinabasho();
});
