//	Frameworks 전체에 사용함으로, 수정하지 말 것!.

Array.prototype.remove = function(from, to) {
	var rest = this.slice((to || from) + 1 || this.length);
	this.length = from < 0 ? this.length + from : from;
	return this.push.apply(this, rest);
};
 
Array.prototype.inArray = function(strVal, from) {
	for(var i = from + 1; i <= this.length; i++) if(strVal == this[i - 1]) return i;
	return -1;
};
 
var SERVICE_LIST = new Array();
SERVICE_LIST[0] = 'directreader';
SERVICE_LIST[1] = 'mobilekeeper';
SERVICE_LIST[2] = 'officekeeper';

function frame_OnLoad(){
//	alert('frame_OnLoad start');

	$("ul#MenuFirst").each(function(index) {
		$(this).mouseover(function(){
			$("ul#Menu_Area").show();
		});
	});

	$("ul#MenuFirst").each(function(index) {
		$(this).mouseout(function(){
			$("ul#Menu_Area").hide();
		});
	});

	$("ul#Menu_Area").each(function(index) {
		$(this).mouseover(function(){
			$("ul#Menu_Area").show();
		});
	});

	$("ul#Menu_Area").each(function(index) {
		$(this).mouseout(function(){
			$("ul#Menu_Area").hide();
		});
	});
//	alert('host_OnLoad call');
	try{host_OnLoad();}catch(e){ alert('/frame/common.js - 46');}
	
	autoLink();
}

var str = Array();
var Localization = Array();

$(document).ready(function(){
	setTimeout(function(){
		window.scrollTo(0, 0);

		var LocalizationURL = 'Localization.php' + location.search + '&For=javascript&Language=ko';
	
		var param = location.search.substring(1, location.search.length).split("&");
		for(var i = 0; i < param.length; i++) if(param[i].indexOf("m=") != -1) xmlURL_str = location.pathname + 'str/' + param[i].replace("m=", "") + '.xml';
	
		if(xmlURL_str != null){
			$.ajax({
				url: LocalizationURL,
				type: "GET",
				dataType: 'json',
				success: function(response, status, obj){
					try{
						for(Record in response){
							switch(Record) {
								case 'remove':
								case 'inArray':
									break;
								default:
									eval("str['" + Record + "'] = '" + eval("response." + Record) + "'");
									eval("Localization['" + Record + "'] = '" + eval("response." + Record) + "'");
							}
						}
					} catch(e){
//						alert('Localization data parsing error :: /frame/common.js');
					}
	
					try{frame_OnLoad();} catch(e){
//						alert('Call error :: /frame/common.js :: frame_OnLoad()');
					}
				},
				error: function(response, status, obj){
					try{frame_OnLoad();} catch(e){
//						alert('Call error :: /frame/common.js :: frame_OnLoad()');
					}
				}
			});
		}
	}, 10);
});

function autoLink(){
	$(".autoLink").each(function(index) {
		$(this).unbind().click(function(){
			tmp = $(this).attr('url').replace("?", "").split("&");

			var arrParamKey = Array();
			var arrParamVal = Array();

			for(var i = 0; i < tmp.length; i++) {
				p = tmp[i].split('=');
				if(arrParamKey.inArray(p[0], 0) == -1){
					arrParamKey[arrParamKey.length] = p[0];
					arrParamVal[arrParamVal.length] = p[1];
				}
			}

			tmp = $(location)[0].search.replace("?", "").split("&");

			for(var i = 0; i < tmp.length; i++) {
				p = tmp[i].split('=');
				if(p[0].indexOf('temp_') == -1)
					if(arrParamKey.inArray(p[0], 0) == -1){
						arrParamKey[arrParamKey.length] = p[0];
						arrParamVal[arrParamVal.length] = p[1];
					}
			}
			
			var param = '';
			for(var i = 0; i < arrParamKey.length; i++)
				if(i == 0)
					param += '?' + arrParamKey[i] + '=' + arrParamVal[i];
				else
					param += '&' + arrParamKey[i] + '=' + arrParamVal[i];
//			alert($(location)[0].protocol + '//' + $(location)[0].hostname + $(location)[0].pathname + param);
			location = param;
		});
	});
}
