var ui = {
	languageBox: {
		onFocus: function() {
			jQuery('#css_lang_dropdownBox').removeClass('closed').addClass('opened');
		},
		onBlur: function() {
			jQuery('#css_lang_dropdownBox').removeClass('opened').addClass('closed');
		}
	},

	form: {
		onFileSelected: function(source, uiEl) {
		var path = source.value;
		try{
        	var fakePathString = "fakepath";
            if (path.indexOf(fakePathString) > -1)
            { 
               path = path.substring(path.indexOf(fakePathString)+fakePathString.length+1);
            }
		//alert(path);
		//jQuery('#' + uiEl).text(source.value);
		jQuery('#' + uiEl).text(path);
        }catch(ex){
        	alert(ex);
        }
        
		},
		
		onSelectSelected: function(value, uiEl)  {
			jQuery('#' + uiEl).text(value);
		},
		
		onRadioSelected: function(source, uiEl) {
			jQuery("#" + uiEl).find('.view').each(function(idx, el) {
				jQuery(el).removeClass('active');
			});
			
			jQuery(source).addClass('active').blur();
		},
		
		onCheckboxSelected: function(source) {
			var obj = jQuery(source);
			if (obj.hasClass("active")) {
				obj.removeClass("active");
			} else {
				obj.addClass("active");
			}
			
			obj.blur();
		},
		
		
		
		onChange: function(objId, value) {
			jQuery('#' + objId).text(value);
		},
		
		onRadioCheck: function(objId, source) {
			jQuery('#' + objId).find('.checkBox-fake').each(function(idx, el){
				jQuery(el).removeClass('active');
			});
			
			jQuery(source).addClass('active');
		},
		
		onCheckboxCheck: function(source) {
			var obj = jQuery(source);
			
			if (obj.hasClass('active')) {
				obj.removeClass('active');
			} else {
				obj.addClass('active');
			}
		}
	},
	
	popupWindow: {
		show: function(objId) {
			var obj = jQuery('#' + objId);
			var middleX = jQuery(window).width() / 2;
			var popupWidth = obj.width();
			obj.css('left', (middleX - popupWidth / 2) + 'px');
			obj.fadeIn();
		},
		
		hide: function(objId) {
			jQuery('#' + objId).fadeOut();
		}
	},
	
	location: {
		worker: null,
		_isClosed: true,
		_curtain: null,
		_coords: {
			xl: null,
			xr: null,
			yt: null,
			yb: null
		},
		
		init: function() {
			this._curtain = jQuery('.base-header .curtain');
			
			this._coords.xl = this._curtain.offset().left;
			this._coords.xr = this._coords.xl + 306;
			
			this._coords.yt = this._curtain.offset().top;
			this._coords.yb = this._coords.yt + 80;
			
			//jQuery(document).mousemove(function(e) {
			//	ui.location.work(e);
			//});
			//jQuery("#location_box").mouseover( this.show() );
			//jQuery("#location_box").mouseout(this.hide());
			//this.show();
		},
		work: function(e) {
			if (e.pageX > this._coords.xl && 
					e.pageX < this._coords.xr &&
					e.pageY > this._coords.yt &&
					e.pageY < this._coords.yb) {
				
				this.show();
				this._isClosed = false;
			} else {
				this.hide();
				this._isClosed = true;
			}
		},
		
		show: function() {
			//if (!this._isClosed) {
			//	return;
			//}
			
			var cobj = jQuery('.base-header .location > .center');
			var lobj = jQuery('.base-header .location');
			
			ui.location.clearWorker();
			
			var height = 10;
			ui.location.worker =  setInterval(function() {
				if (height >= 80) {
					ui.location.clearWorker();
				}
				
				cobj.height(height + 'px');
				lobj.css('margin-top', -height + 'px');
				height += 10;
			}, 20);
		},
		
		hide: function() {
		//	if (this._isClosed) {
		//		return;
		//	}
			
			var cobj = jQuery('.base-header .location > .center');
			var lobj = jQuery('.base-header .location');
			
			ui.location.clearWorker();
			
			var height = 70;
			ui.location.worker =  setInterval(function() {
				if (height <= 0) {
					ui.location.clearWorker();
				}
				
				cobj.height(height + 'px');
				lobj.css('margin-top', -height + 'px');
				height -= 10;
			}, 20);
		},
		
		clearWorker: function() {
			clearInterval(ui.location.worker);
			worker = null;
		}
	},
	
	searchBox: {
		onfocus: function(source, schLang) {
			if (source.value == schLang) {
				source.value = "";
				jQuery(source).css('font-size', '14px').css('color','#B6325E').css('font-weight', 'bold').css('font-style', 'normal');
				
			}
		},
		
		onblur: function(source, schLang) {
			if (source.value == "") {
				jQuery(source).css('font-size', '12px').css('color','#939393').css('font-weight', 'normal').css('font-style', 'italic');
				source.value = schLang;
			}
		}
	}
};

