$(document).ready(function (){
	$("[stype=slider]").each(function (){
		newSlider($(this));
	});

	$("[stype=tabMenu]").mouseover(function (){
		var _name = $(this).attr("name");
		var _idx = $("[name="+_name+"]").index(this);
		$("[name="+_name+"]").each(function (index){
			if(_idx == index){
				$(this).attr("src", $(this).attr("src").replace("_n", "_o"));
				$("[view="+_name+"]").eq(index).show();
				$("#"+_name).attr("href", $(this).attr("href"));
			}
			else{
				$(this).attr("src", $(this).attr("src").replace("_o", "_n"));
				$("[view="+_name+"]").eq(index).hide();
			}
		});
	}).click(function (){
		document.location.href = $(this).attr("href");
	}).css("cursor", "pointer");

	$("[stype=popup]").click(function (){
		var intWidth = "400";
		var intHeight = "600";
		var url = "";
		var target = "_blank";

		if($(this).attr("intWidth")){
			intWidth = $(this).attr("intWidth");
		}
		if($(this).attr("intHeight")){
			intHeight = $(this).attr("intHeight");
		}
		if($(this).attr("url")){
			url = $(this).attr("url");
		}
		if($(this).attr("target")){
			target = $(this).attr("target");
		}
		var z =  window.open(url, target, "width="+intWidth+",height="+intHeight+",resizable=1,scrollbars=0") ;
		if($(this).attr("focus") =="1"){
			z.focus();
		}

	}).css("cursor", "pointer");

	$("[stype=linkSelect]").change(function (){
		var obj = $(this).find(":selected");
		var target = $(obj).attr("target");
		eval(target+".location='"+$(this).val()+"'");
		if($(obj).attr("restore") == "1"){
			$(this).find("option").eq(0).attr("selected", true);
		}
	});


	$("[stype=layer]").each(function(){
		var x = 0;
		var y = 0;
		var width = $(this).width();
		var height = $(this).height();
		var id = $(this).attr("id");

		if($(this).attr(x)){
			x = $(this).attr(x);
		}
		if($(this).attr(y)){
			y = $(this).attr(y);
		}

		if($(this).attr("rec") == "1"){
			x = 0;
			y = 0;
		}
		else if ($(this).attr("rec") == "2"){
			x = 0;		
			y = $(window).height() - height;
		}
		else if ($(this).attr("rec") == "3"){
			x = $(window).width() - width;
			y = 0;
		}
		else if($(this).attr("rec") == "4"){
			x = $(window).width() - width;
			y = $(window).height() - height;
		}

		$(this).css("position", "absolute").css("left", x).css("top", y);

		var view= $(this).find("[view="+id+"]");
		var btn= $(this).find("[btn="+id+"]");
		$(btn).click(function (){
			var type = $(this).attr("type");
			$(btn).each(function (){
				if($(this).attr("type") == type){
					$(this).hide();
					$(view).show();
					$("#"+id).css("width", $("#"+id).css("bWidth"));
				}
				else{
					$(this).show();
					$("#"+id).attr("bWidth", $("#"+id).css("width"));
					$("#"+id).css("width", $(this).width());
					$(view).hide();
				}
			});
			$("#"+id).css("left", $(window).width()- $("#"+id).width());

		}).css("cursor", "pointer");
	});

	$(window).resize(function (){
		$("[stype=layer]").each( function (){
				if($(this).attr("resize") == "1"){
				var width = $(this).width();
				var height = $(this).height();

				if($(this).attr("rec") == "1"){
					x = 0;
					y = 0;
				}
				else if ($(this).attr("rec") == "2"){
					x = 0;		
					y = $(window).height() - height;
				}
				else if ($(this).attr("rec") == "3"){
					x = $(window).width() - width;
					y = 0;
				}
				else if($(this).attr("rec") == "4"){
					x = $(window).width() - width;
					y = $(window).height() - height;
				}

				$(this).css("position", "absolute").css("left", x).css("top", y);
			}
		});
	});
});

function viewLayer(id, type){
	if(type == 1){
		document.getElementById(id).style.display = "inline";
	}
	else{
		document.getElementById(id).style.display = "none";
	}
}



/*png transparent*/
function setPng24(obj) {
	if ($.browser.msie && $.browser.version != 6) {
		return false;
	}


	obj.width=obj.height=1;
	obj.className=obj.className.replace(/\bpng24\b/i,'');
	obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
	obj.src=''; 
	return '';
}

//롤오버 생성
function rollOver(obj){
	var s = "";
	var r = "";
	var str = "";
	if($(obj).attr("src")){
		str = $(obj).attr("src");
	}
	else{
		str = $(obj).css("filter");		
	}
	
	if(str.indexOf("_n") != -1){
		s = "_n";
		r = "_o";
		$(obj).css("cursor", "pointer");
	}
	else{
		s = "_o";
		r = "_n";
	}
	
	if($(obj).attr("src")){
		$(obj).attr("src", str.replace(s, r));
	}
	else{
		$(obj).css("filter", str.replace(s, r));
	}
}


//슬라이더 생성
var moving = false;
var _idx = 0;
function newSlider(obj){
	var slider = obj;
	slider.each(function (index){
		$(this).attr("status", 0);
		var maxsize = ($(this).attr("maxsize"))? parseInt($(this).attr("maxsize")) : 960;
		$(this).attr("maxsize", maxsize);
		
		var imgsize = ($(this).attr("imgsize"))? parseInt($(this).attr("imgsize")) : 600;
		$(this).attr("imgsize", imgsize);
		
		var size =  maxsize - imgsize;
		var left  = imgsize;
		
		var cutwidth  = ($(this).attr("cutwidth"))? parseInt($(this).attr("cutwidth")): 180;
		$(this).attr("cutwidth", cutwidth);
		
		var space  = ($(this).attr("space"))? parseInt($(this).attr("space")) : 0;
		$(this).attr("space", space);
		
		var lastsize  = ($(this).attr("lastsize"))? parseInt($(this).attr("lastsize")) : 360;
		$(this).attr("lastsize", lastsize);
		
		var acc = ($(this).attr("acc"))? parseInt($(this).attr("acc")) : 30;
		$(this).attr("acc", acc);
		
		var total = $(this).find("[class=slider]").size()-1;

		for(var i = 1; i < $(this).find("[class=slider]").size(); i++){
			var width = (i-1)*cutwidth;
			if(total == i){
				$(this).find("[class=slider]").eq(i).css("width", lastsize);
			}
			setSize($(this).find("[class=slider]").eq(i), left+width, i, 10);
		}
		slider.eq(index).find("[class=slider]").mouseover(function (){
			var idx = slider.eq(index).find("[class=slider]").index(this);
			var obj = slider.eq(index);

			if(moving && idx != _idx){
				if(idx > parseInt(obj.attr("status"))){
					for(i  = 0; i <= idx; i++){
						setImgMove(slider.eq(index), (cutwidth+space)*i, i, 1, acc, cutwidth, imgsize);
					}
				}
				else{
					setImgMove(slider.eq(index), idx+1, idx, 2, acc, cutwidth, imgsize);
				}
				_idx = idx;
				slider.eq(index).attr("status", idx);
			}
		}).css("cursor", "pointer");
	});
}

var bId = "";
//레이어 메뉴 보기
function showMenuLayer(id, subId, clazz){
	if(bId != "") {
		$("#"+bId).hide();
	}
	if($("#"+subId).css("display") == "none"){
		bId = subId;
		$("#"+subId).unbind("mouseover").bind("mouseover", function (){
			return false;
		}).show().find("."+clazz).unbind("mouseover").bind("mouseover", function (){
			return false;
		});
	}
	else{
		$("#"+subId).hide();
	}

	$("#"+id).unbind("mouseover").bind("mouseover", function (){
		if(bId != "" && bId == id) {
			$("#"+bId).hide();
		}
		return false;
	});
	
	$(document.body).unbind("mouseover").bind("mouseover", function (e){
		if($("#"+subId).css("display") != "none"){
			$("#"+subId).hide();
		}
	});
}


function famliySiteAction(){
	var fsf = document.getElementById("familySite");
	var fsl = document.getElementById("fsiteList");
	if(!fsl.value || fsl.value.value == "") {
		alert("이동하실 사이트를 선택해 주세요.");
		fsl.focus();
		return false;
	}
	fsf.action = fsl.value;
	return true;
}




//새창띄우기
function OpenWindow(url, intWidth, intHeight){
	var z = window.open(url, "VrJido", "width="+intWidth+",height="+intHeight+",resizable=0,scrollbars=0");
	z.focus();
	
}

function OpenMassage(msg){
	alert(msg);
}
