// JavaScript Document

_$ = jQuery.noConflict(false);

/* -- kogumahome original -- */



var dd_arr = new Array();
var cButton = new Array();
var now_show;
var orgSRC;
var newSRC;
var imgHTML;
var imgHREF = new Array();
var newSRC_arr = new Array();
var newIndex = 100;
var overRayImg;
var curOverRay = '';
var oldShowObj = '';
var openedID = 0;


_$('body').ready(
		function() {
			pageLoading();
			_$('#linkNavi a')
			.bind('mouseover', function(e){contiBtnRollOver(this);})
			.bind('mouseout', function(e){contiBtnRollOut(this);})
			.bind('mouseup', function(e){contiBtnClick(this);});
			if(_$.cookie('openedID')) {
				openedID = _$.cookie('openedID')
			}
			setAccordion();
			naviPopSettings('#linkNavi ul');
			_$('#linkNavi > ul > li')
			.bind('mouseover',function(e){showPopUp(this);})
			.bind('mouseout',function(e){hidePopUp(this);});
			var jireiImgObj = _$('#jireibox dt a img');
			jireiImgObj
			.bind('mouseover',function(e){imgZoomIn(this)});
			for(var n=0;n<_$('#listmenu dt').length;n++) {
				cButton = _$('#listmenu dt');
				cButton[n].n = n;
				_$(cButton[n])
				.bind('click',function(e){showAccordion(this.n)})
				.css({'cursor':'pointer'});
			}
			
			_$('#bannerMenu a img')
			.bind('mouseover',function(e) { _$(this).css({'opacity':'0.6'});})
			.bind('mouseout',function(e) { _$(this).css({'opacity':'1.0','filter':'none'});});
			
			mainImgChg();
			setZoomIn(_$('#jireibox dt img'));
			
			blogBoxSettings(_$('#blogBox'));

		}
	);
	
 _$(window)
 .resize(
		 function() {
			blogBoxMoving(_$('#blogBox'));
		 });

//Cases photo change

function mainImgChg () {
	thumb_arr = _$('#thumbImg li');
	var imgObj_arr = new Array();
	for(var n = 0; n < thumb_arr.length; n++){
		imgHREF[n] = _$(thumb_arr[n]).children('a').attr('href');
		imgObj_arr[n] = new Image();
		imgObj_arr[n].src = imgHREF[n];
		_$(thumb_arr[n]).children('a').removeAttr('href').css({'cursor':'pointer'})
		.bind('mouseover',function(e) { _$(this).css({'opacity':'0.6'});})
			.bind('mouseout',function(e) { _$(this).css({'opacity':'1.0','filter':'none'});});
		targ = _$(thumb_arr[n]).children('a').children('img');
		_$(targ).attr('id',n);
		_$(targ)
		.bind('click',
			  function() {
				 doChg(imgObj_arr[_$(this).attr('id')].src);
			  });
		
	}
}


function doChg(t) {
 	var tar = t;
	_$('#mainImg > img')
	.animate({'opacity':0},500,
			 function() {
				_$(this).attr('src',tar);
				_$(this).animate({'opacity':1.0},500,
								 function() {
									_$(this).css({'opacity':1.0,'filter':'none'}); 
								 });
			 }); 
 }

	
//mouseover img zoom

function setZoomIn(t) {
  var imgObj_arr = new Array();
  var targObj = _$(t);
  for(var i=0;i<targObj.length;i++) {
	imgObj_arr[i] = new Image();
	imgObj_arr[i].src = targObj.attr('title');
  }
}

function imgZoomIn(z) {
 var targObj = _$(z);
 var offset = targObj.offset();
 orgSRC = targObj.attr('src');
 newSRC = targObj.attr('title');
 var imgObj = new Image();
 imgObj.src = newSRC;
 imgHTML = '<p class="bigImg"><img src="' + newSRC + '" class="newIMG" /></p>';
 overRayImg = targObj.parent().append(imgHTML);
   if(curOverRay != overRayImg) {
   _$(curOverRay).children('p.bigImg').remove();
   curOverRay = overRayImg;
 } else {
	 curOverRay = overRayImg; 
 }
 curOverRay
 .children('.bigImg')
 .css({'position':'absolute','top':offset.top + 'px','left':(offset.left - 5) + 'px','cursor':'pointer','zIndex':newIndex})
 .bind('mouseout',function(e) { imgZoomOut(this) })
 .children('img.newIMG').css({'width':'131px','height':'84px','position':'absolute'})
 .animate({'height':'192px','width':'300px','top':'-30px','left':'-80px'},300);
  newIndex++;
}

function imgZoomOut(z) {
 var targ = _$(z);
 targ.remove();
 curOverRay = '';
}

// linkNavi popup

function naviPopSettings(tar) {
	var TargObj = _$(tar);
	TargObj
	.css({'position':'relative','zIndex':'200'})
	.children('li')
	.children('ul')
	.css({'position':'absolute','display':'none','zIndex':'300','top':'32px','left':'0px'});
 	
}

function showPopUp(targ) {
  var targObj = _$(targ);
  var offsetArr = targObj.offset();
  var parOfst = targObj.parent().offset();
  var showObj = targObj.children('ul');
  if(oldShowObj != '') {
	  oldShowObj.css({'display':'none'});
  }
  if(showObj) {
	 showObj.css({'display':'block','left':(offsetArr.left - parOfst.left) + 'px'});
	 oldShowObj = showObj;
  }
}

function hidePopUp(targ) {
  var targObj = _$(targ);
  var showObj = targObj.children('ul');
  if(showObj) {
	 id = setTimeout(function() {fadeDom(showObj);},100);
	  showObj.parent().bind('mouseover',
	   function() {
		  clearTimeout(id); 
	   });
  }
}

function fadeDom (sObj) {
 sObj.css({'display':'none'});
}

// accordion menu

function setAccordion() {
  for(var i=0;i<_$('#listmenu dd').length;i++) {
	dd_arr[i] =  _$('#listmenu dd')[i];
	if(i != openedID ) {
	  _$(dd_arr[i])
	  .css({'height':'0px'})
      .children().css({'display':'none'});
	} else {
	  now_show = dd_arr[i];	
	}
  }
  
 
	
}

function showAccordion(t) {
 var hi = _$(dd_arr[t]).children().height()+18;
 _$.cookie(
		   'openedID',
			t,{expires:1,path:'/',domain:'www.kogumahome.com'}
		   );
 if(now_show != dd_arr[t]) {
  _$(now_show)
  .animate({'height':'0px'},600)
  .children().css({'display':'none'});
 _$(dd_arr[t])
 .animate({'height':hi+'px'},300,
		  function() {
			_$(dd_arr[t]).children().css({'display':'block'});  
		  });
  now_show = dd_arr[t];
 }
}

// Roll Over Script
function contiBtnRollOver(t){
	if(_$(t).children().attr('src')) {
	orgImgSrc = _$(t).children().attr('src');
	if(orgImgSrc.indexOf('_roll') == -1) {
	    overImgSrc = orgImgSrc.replace(/(\.gif|\.jpg|\.png)/,"_roll$1");
	    _$(t).children().attr('src',overImgSrc);
	    }
	}
};
	
function contiBtnRollOut(t){
	if(orgImgSrc) {
	_$(t).children().attr('src',orgImgSrc);
	}
};

function contiBtnClick(t) {
	_$(t).children().attr('src',orgImgSrc);
};
	
function preLoadImg(val){
	var imgObj = new Object();
	for(var i = 0; i < val.length; i++){
		imgObj["img"+ i] = new Image();
		imgObj["img"+ i] .src = val[i];
	}
}

function blogBoxSettings (t) {
  	var tObj = t;
	var trgsw = false;
	_$('#blg_nw_post p').css({'position':'absolute','top':'-145px','right':'-120px'});
	var brOffset = _$('#threePoints').offset();
	if(brOffset != null) {
	    var boxLeft = (brOffset.left) + 'px';
	}
	tObj.css({'position':'absolute','top':'500px','left':boxLeft,'zIndex':'200','width':'293px','height':'280px','display':'none','background':'url(/images/common/blogBox_bg.png) no-repeat','padding':'12px 86px 0 22px'})
	.prepend('<p id="cBtn"><img src="/images/common/closeBx_btn.gif" width="16" height="16" alt="close" /></p>')
	.children('dl')
	.css({'width':'290px','height':'128px','overflow':'auto'});
	_$('#cBtn')
	.css({'position':'absolute','top':'10px','right':'45px','cursor':'pointer'});
	_$('#blg_nw_post')
	.bind('click',
		  function() {
			  if(trgsw == false) {
				  tObj
				  .css({'display':'block','opacity':'0.0'})
				  .animate({'opacity':'1.0'},600,function() {_$(this).css({'filter':'none'});});
				  _$(this).children('p').children('a').html("CLOSE!");
				  _$('#cBtn')
				  .bind('click',
						function() {
							tObj
							.css({'display':'none'});
							_$(this)
							.unbind('click');
							trgsw = false;
							_$('#blg_nw_post p a').html('OPEN!');
						});
				  trgsw = true;
				  return false;
			  } else {
				 tObj
				 .css({'display':'none'});
				 trgsw = false;
				 _$(this).children('p').children('a').html("OPEN!");
				 _$('#cBtn')
				 .unbind('click');
				 return false;
			  }
		  });
	
}

function blogBoxMoving (t) {
	var tObj = t;
	var trgsw = false;
	_$('#blg_nw_post p').css({'position':'absolute','top':'-145px','right':'-120px'});
	var brOffset = _$('#threePoints').offset();
	var boxLeft = (brOffset.left) + 'px';
	tObj.css({'position':'absolute','top':'500px','left':boxLeft});
}

function pageLoading () {
 var _x = _$('#wrapper').width();
 var _y = _$('#wrapper').height();
 _$('body').append('<div id="loadingMV"><img src="/images/common/nowLoading.png" alt="Now Loading..." /></div>')
 .children('#loadingMV')
 .css({'position':'absolute','font-size':'2.8em','color':'#998800','top':'0px','left':'0px','text-align':'center','width':'100%','height':'100%','background':'#fff','zIndex':'1000','opacity':'0.0','padding':'150px 0 0 0'});
 _$(window).load(
			 function () {
				 _$('#loadingMV').animate({'opacity':'1.0'},1250,
										  function() {
											fadeDOM();  
										  });
				 
			 });
}


function loadFlash() {
 
var flashvars = {};

var params = {
	wmode :"transparent"
 };

 var attributes = {
	 id:"flashbox",
	 name:"flashbox"
 };
 
swfobject.embedSWF("/images/flash/mainfla.swf","flashbox","558","392","9.0.0","/images/flash/expressInstall.swf",flashvars,params,attributes);


}












