// JavaScript Document
$(document).ready(function(){
	// HEAD FLASH CENTERING
	flashOffset();
	$(window).resize(function(){flashOffset();});
	
	// ROLL OVER BUTTON
	var ovStr = '.ov';
	$('a img[src*=".nr."],button img[src*=".nr."]').each(function(){
		var ovImg = $(this);
		var orgSrc= ovImg.attr('src');
		var newSrc= orgSrc.replace(/^(.+).nr(\.[png|gif|jpg])/i,"$1.ov$2");
		// PRELOAD
		$('<img>').attr('src',newSrc);
		// HOVER EVENT
		ovImg.hover(
			function(){
				ovImg.attr('src',newSrc);
			},
			function(){
				ovImg.attr('src',orgSrc);
			}
		);
	});
	
	// ATTACH
	$('#galleryListBox li:last').css('margin-right','0px');
	// Matsuic Attach
	$('#matindexBox div:odd').addClass('index1');
	$('#matindexBox div:even').addClass('index2');
	// Column Attach
	$('#colum_index tr:even>td').addClass('bg');
	$('.halfimg').fadeTo(0,0.5);
	// LOUNGE SCRIPT
	if($('#sendmess').length){
		// PENDING
	}
	// LOUNGE ENTRY SORT
	if($('#sortSw').length){
		// URL
		var url = $(location).attr('href').split('/');
		var fil = url[url.length-1];
		var xxx = fil.match(/^(lounge_room\d+_)\d+(r?)\.html$/);
		var jump= RegExp.$1;
		var swc = RegExp.$2;
		if(swc){
			$('#sortSw').val('asc');
		}else{
			$('#sortSw').val('desc');
		}
		// 
		$('#sortSw').change(function(){
			var key = $(this).val();
			if(key=='desc'){
				jump+= '1.html';
			}else if(key=='asc'){
				jump+= '1r.html';
			}
			location.href = jump;
		});
	}
	// LOUNGE THEME JUMP
	if($('#roomSelect').length){
		$('#roomSelect').change(function(){
			var url = $(this).val();
			location.href = url;
		});
	}
	// BACK
	if($('#backwd').length){
		$('#backwd').click(function(){
			history.back();
		});
	}
});

//HEAD FLASH CENTERING
function flashOffset(){
	var swfWidth	= 1440;
	var boxWidth	= $('#flashBox').width();
	var swfOffset	= (boxWidth-swfWidth)/2;
	$('#flashBox').children('div').css('margin-left',swfOffset);
}

// FLASH VIEW
function flashView(){
	var swfName		= 'iiie_top.swf';
	var swfWidth	= 1440;
	var swfHeight	= 400;
	var swfVars		= '';
	var swfDummyImg	= 'img/flashDummy.jpg';
	if(isFlashInstalled()){
		var prm = '';
		prm+= '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+swfWidth+'" height="'+swfHeight+'" id="topflash" align="middle">';
		prm+= '<param name="allowScriptAccess" value="sameDomain" />';
		prm+= '<param name="allowFullScreen" value="false" />';
		prm+= '<param name="movie" value="'+swfName+'" />';
		prm+= '<param name="loop" value="false" />';
		prm+= '<param name="menu" value="false" />';
		prm+= '<param name="quality" value="high" />';
		prm+= '<param name="wmode" value="transparent" />';
		prm+= '<param name="scale" value="exactfit" />';
		prm+= '<param name="bgcolor" value="#ffffff" />';
		prm+= '<param name="FlashVars" value="flg='+swfVars+'" />'
		prm+= '<embed src="'+swfName+'" loop="false" menu="false" quality="high" wmode="transparent" scale="exactfit" bgcolor="#ffffff" width="'+swfWidth+'" height="'+swfHeight+'" name="topflash" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="flg='+swfVars+'" />';
		prm+= '</object>';
		document.write(prm);
	}else{
		document.write('<img src="'+swfDummyImg+'" width="'+swfWidth+'" height="'+swfHeight+'" alt="topimage" />');
	}
}
// NO FLASH PLUGIN
function isFlashInstalled(){
  if(navigator.plugins['Shockwave Flash']){
    return true;
  }
  try{
    new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
    return true;
  }catch(e){
    return false;
  }
}
