var Base = function() {
};
Base.extend = function(_instance, _static) {
	var extend = Base.prototype.extend;
	Base._prototyping = true;
	var proto = new this;
	extend.call(proto, _instance);
	delete Base._prototyping;
	var constructor = proto.constructor;
	var klass = proto.constructor = function() {
		if (!Base._prototyping) {
			if (this._constructing || this.constructor == klass) {
				this._constructing = true;
				constructor.apply(this, arguments);
				delete this._constructing;
			} else if (arguments[0] != null) {
				return (arguments[0].extend || extend)
						.call(arguments[0], proto);
			}
		}
	};
	klass.ancestor = this;
	klass.extend = this.extend;
	klass.forEach = this.forEach;
	klass.implement = this.implement;
	klass.prototype = proto;
	klass.toString = this.toString;
	klass.valueOf = function(type) {
		return (type == "object") ? klass : constructor.valueOf();
	};
	extend.call(klass, _static);
	if (typeof klass.init == "function")
		klass.init();
	return klass;
};
Base.prototype = {
	extend : function(source, value) {
		if (arguments.length > 1) {
			var ancestor = this[source];
			if (ancestor
					&& (typeof value == "function")
					&& (!ancestor.valueOf || ancestor.valueOf() != value
							.valueOf()) && /\bbase\b/.test(value)) {
				var method = value.valueOf();
				value = function() {
					var previous = this.base || Base.prototype.base;
					this.base = ancestor;
					var returnValue = method.apply(this, arguments);
					this.base = previous;
					return returnValue;
				};
				value.valueOf = function(type) {
					return (type == "object") ? value : method;
				};
				value.toString = Base.toString;
			}
			this[source] = value;
		} else if (source) {
			var extend = Base.prototype.extend;
			if (!Base._prototyping && typeof this != "function") {
				extend = this.extend || extend;
			}
			var proto = {
				toSource : null
			};
			var hidden = [ "constructor", "toString", "valueOf" ];
			var i = Base._prototyping ? 0 : 1;
			while (key = hidden[i++]) {
				if (source[key] != proto[key]) {
					extend.call(this, key, source[key]);
				}
			}
			for ( var key in source) {
				if (!proto[key])
					extend.call(this, key, source[key]);
			}
		}
		return this;
	},
	base : function() {
	}
};
Base = Base.extend( {
	constructor : function() {
		this.extend(arguments[0]);
	}
}, {
	ancestor : Object,
	version : "1.1",
	forEach : function(object, block, context) {
		for ( var key in object) {
			if (this.prototype[key] === undefined) {
				block.call(context, object[key], key, object);
			}
		}
	},
	implement : function() {
		for ( var i = 0; i < arguments.length; i++) {
			if (typeof arguments[i] == "function") {
				arguments[i](this.prototype);
			} else {
				this.prototype.extend(arguments[i]);
			}
		}
		return this;
	},
	toString : function() {
		return String(this.valueOf());
	}
});

var Common_Global = Base
		.extend(
				{},
				{
					get_object_position : function(obj) {
						var oPosition = {
							x : 0,
							y : 0
						};
						if (obj == null)
							return oPosition;
						if (obj.offsetParent) {
							while (obj.offsetParent) {
								oPosition.x += obj.offsetLeft;
								oPosition.y += obj.offsetTop;
								obj = obj.offsetParent;
							}
						} else if (obj.x) {
							oPosition.x += obj.x;
							oPosition.y += obj.y;
						}
						return oPosition;
					},
					get_event_position : function(e) {
						var oPosition = {
							x : 0,
							y : 0
						};
						if (typeof (e) == 'undefined')
							e = window.event;
						if (typeof (e.pageX) != 'undefined') {
							oPosition.x = e.pageX;
							oPosition.y = e.pageY;
						} else {
							oPosition.x = e.clientX
									+ document.documentElement.scrollLeft
									+ document.body.scrollLeft;
							oPosition.y = e.clientY
									+ document.documentElement.scrollTop
									+ document.body.scrollTop;
						}
						return oPosition;
					},
					set_popup_position : function(oPopup, tour) {
						var left = $(window).scrollLeft();
						var top = $(window).scrollTop();
						if (!tour) {
							left += ($(window).width() - $(oPopup).outerWidth()) / 2;
							top += 171;
						} else {
							left += document.body.clientWidth / 2 - 420;
							top += 140;
						}
						oPopup.style.top = top + 'px';
						oPopup.style.left = left + 'px';
					},
					set_center_position : function(obj, top) {
						var x, y;
						if (self.pageYOffset) {
							x = self.pageXOffset;
							y = self.pageYOffset;
						} else if (document.documentElement
								&& document.documentElement.scrollTop) {
							x = document.documentElement.scrollLeft;
							y = document.documentElement.scrollTop;
						} else if (document.body) {
							x = document.body.scrollLeft;
							y = document.body.scrollTop;
						}
						if ('undefined' == typeof (top))
							var top = 240;
						obj.style.top = y + top + 'px';
						obj.style.left = document.body.clientWidth / 2
								- (obj.offsetWidth / 2) + 'px';
					},
					get_document_size : function() {
						var x, y;
						if (self.innerHeight) {
							x = self.innerWidth;
							y = self.innerHeight;
						} else if (document.documentElement
								&& document.documentElement.clientHeight) {
							x = document.documentElement.clientWidth;
							y = document.documentElement.clientHeight;
						} else if (document.body) {
							x = document.body.clientWidth;
							y = document.body.clientHeight;
						}
						var xx, yy;
						var test1 = document.body.scrollHeight;
						var test2 = document.body.offsetHeight
						if (test1 > test2) {
							xx = document.body.scrollWidth;
							yy = document.body.scrollHeight;
						} else {
							xx = document.body.offsetWidth;
							yy = document.body.offsetHeight;
						}
						if ($('wrp'))
							yy = $('wrp').offsetHeight;
						var oSize = {
							width : 0,
							height : 0
						};
						oSize.height = ((y > yy) ? y : yy);
						oSize.width = xx;
						return oSize;
					},
					is_image_file : function(file_name) {
						if (file_name) {
							var dot = file_name.lastIndexOf('.');
							if (dot != -1) {
								var ext = file_name.substr(dot).toLowerCase();
								var allowed = {
									'.jpg' : 1,
									'.jpeg' : 1,
									'.png' : 1,
									'.bmp' : 1,
									'.gif' : 1
								};
								return (allowed[ext]);
							}
						}
						return false;
					},
					new_win : function(link, params) {
						var params = params || {};
						var width = params['width'] || 400;
						var height = params['height'] || 400;
						var left = params['left'] || 200;
						var top = params['top'] || 200;
						window
								.open(
										link,
										'_blank',
										"height="
												+ height
												+ ", width="
												+ width
												+ ", left="
												+ left
												+ ", top="
												+ top
												+ ", status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no");
						return false;
					},
					new_win_info : function(link, width, height) {
						this.new_win(link, {
							width : width,
							height : height
						});
						return false;
					},
					getCookie : function(name) {
						var prefix = name + '=';
						var cookieStartIndex = document.cookie.indexOf(prefix);
						if (cookieStartIndex == -1)
							return null;
						var cookieEndIndex = document.cookie.indexOf(';',
								cookieStartIndex + prefix.length);
						if (cookieEndIndex == -1)
							cookieEndIndex = document.cookie.length;
						return decodeURIComponent(document.cookie.substring(
								cookieStartIndex + prefix.length,
								cookieEndIndex));
					},
					deleteCookie : function(name) {
						var domain = hostname ? hostname : null;
						if (domain) {
							if (domain.indexOf('.box.net') >= 0) {
								domain = 'box.net';
							}
						}
						Common_Global.setCookie(name, '', (new Date())
								.getTime()
								- (1000 * 3600 * 24), '/', domain);
					},
					setCookie : function(name, value, expires, path, domain,
							secure) {
						var expires_date = new Date();
						if (typeof expires == 'undefined' || expires == null) {
							expires = expires_date.getTime()
									+ (1000 * 3600 * 24 * 60);
						}
						expires_date.setTime(expires);
						var cookie = name + '=' + encodeURIComponent(value);
						cookie += '; expires=' + expires_date.toGMTString();
						if (path)
							cookie += '; path=' + path;
						if (domain)
							cookie += '; domain=' + domain;
						if (secure)
							cookie += '; secure';
						document.cookie = cookie;
					}
				});
$(function() {
	if (!Common_Global.getCookie('referrer')) {
		Common_Global.setCookie('referrer', document.referrer, null, '/',
				document.domain, 0);
	}
});
