$(function(){
initDivSelector();
var objDivSelValue1 = $('.family_site .dyn_value');
var objDivSelValue2 = $('.kepco_home .dyn_value');
var objUlSelect1 = $('.family_site .dyn_selSelect');
var objUlSelect2 = $('.kepco_home .dyn_selSelect');
var objSns = $('.footer .twitter')
objSns.bind('blur', function(){
objDivSelValue1.focus();
});
objDivSelValue1.click(function(){
objUlSelect2.hide();
});
objDivSelValue2.bind('focus click', function(){
objUlSelect1.hide();
});
$('.box_select').bind('mouseleave', function(){
objUlSelect1.hide();
objUlSelect2.hide();
});
$('.dyn_selSelect li:last-child a').bind('focusout', function(){
objUlSelect1.hide();
objUlSelect2.hide();
});
//검색메뉴 focusin event
$('.utill_search > a').on('focusin', function (event) {
suggestToggle();
});
$('#utill_search').on('focusout', function (event) {
suggestToggle();
});
});
var initDivSelector = function() {
//objDivSelector = $("#selectBox");
objDivSelector2 = $("#selectBox2");
objDivSelector2.each(function() {
// Setting
var objOrigin = $(this);
var strNameSpace = objOrigin.attr("id");
var objOriginData = objOrigin.find('option');
var objCreateTitle = $("
").attr({"id":"div_" + strNameSpace}).addClass("dyn_value").html("" + 'KEPCO 홈' + "");
var objCreateUl = $("").attr({"id":"dyn_" + strNameSpace}).addClass("scroll dyn_selSelect").css({"overflow": "hidden", "display": "none", "height": "115px"});
// Data Binding
objOriginData.each(function () {
var objCreateLi = $("");
objCreateLi.find("span").html("" + $(this).text() + "");
objCreateUl.append(objCreateLi);
});
objCreateTitle.click(function() {
if (objCreateUl.css("display") == "none") {
setDivSelectorRePosition();
objCreateUl.show();
}
else {
objCreateUl.hide();
}
});
objCreateUl.mouseleave(function() {
objCreateUl.hide();
});
objCreateUl.find("li>span>a").click(function(index) {
var intIndex = $(this).parents('li').index();
objCreateTitle.html("" + $(this).html() + "");
objOrigin.find("option").attr("selected",false);
objOrigin.find("option").eq(intIndex).attr("selected",true);
objOrigin.trigger("change");
objCreateUl.hide();
});
// Create
objOrigin.hide();
objOrigin.after(objCreateTitle);
objCreateTitle.after(objCreateUl);
});
//Window Resize Change Position
$(window).resize(setDivSelectorRePosition);
}
var setDivSelectorRePosition = function() {
objDivSelector2.each(function() {
var objOrigin = $(this);
var strNameSpace = objOrigin.attr("id");
var objCreateTitle = $("#div_" + strNameSpace);
var objCreateUl = $("#dyn_" + strNameSpace);
var intWindowHeight = $(window).height();
var intCreateTop = objCreateTitle.offset().top + objCreateTitle.outerHeight() + 2;
var intCreateUlTop = parseInt(objCreateTitle.css("margin-top").replace("px","")) + objCreateTitle.outerHeight() + 2;
if (navigator.userAgent.indexOf("MSIE 7") != -1) {
intCreateTop -= 4;
intCreateUlTop -= 4;
}
if (intWindowHeight < intCreateTop + 148) {
intCreateTop = objCreateTitle.offset().top - 148;
intCreateUlTop = parseInt(objCreateTitle.css("margin-top").replace("px","")) - 148;
if (navigator.userAgent.indexOf("MSIE 7") != -1) {
intCreateTop -= 4;
intCreateUlTop -= 4;
}
}
//objCreateUl.css({"position": "absolute", "top": intCreateTop, "left": objCreateTitle.offset().left});
objCreateUl.css({"position": "absolute", "top": intCreateUlTop, "left": 0});
});
}