
searchBox = {
	inputBox:null,
	cueBox:null,
	value:null,
	init:function(obj,cueText){
		this.inputBox = $(obj);
		this.inputBox.wrap('<div class="searchBox" />')
		this.cueBox = this.inputBox.clone()
		this.cueBox.removeAttr('name')
		this.cueBox.addClass('cue')
		this.cueBox.attr('value',cueText)
		this.inputBox.after(this.cueBox)
		this.inputBox.removeAttr('value');
		if(!Boolean(this.inputBox.attr('value'))){
			this.inputBox.hide();
		}else{
			this.cueBox.hide();
		}
		var myDummy = this;
		this.cueBox.focus(function(){
			myDummy.focus($(this));
		})
		this.inputBox.focusout(function(){
			myDummy.focusout($(this));
		})
	},
	focus:function(target){
		this.inputBox.show();
		this.cueBox.hide();
		this.inputBox.focus()
	},
	focusout:function(target){
		if (target.attr('value') == '') {
			this.inputBox.hide();
			this.cueBox.show();
		}
	}
}

dynamicRecord = {
	init:function(selectedFunction,unselectedFunction){
		var allRecord = $(".dynamicRecord");
		allRecord.each(function(){
			this.selected = selectedFunction?selectedFunction:function(){};
			this.unselected = unselectedFunction?unselectedFunction:function(){};
			var myDummy = $(this); 
			myDummy.find('.recordHead').click(function(e){
				if(!myDummy.hasClass('selected')){
					allRecord.removeClass('selected').find('.recordBody').slideUp({duration: 300, easing: 'easeInQuad'});
					allRecord.each(function(){this.unselected();});
					myDummy.addClass('selected').children('.recordBody').slideDown({duration: 500, easing: 'easeOutQuad', complete: function (){
						
						$('html, body').animate({scrollTop: ($(this).position().top - myDummy.find('.recordHead').height()) +"px"}, 1000);
						}});
					myDummy[0].selected();
				}else{
					myDummy.removeClass('selected').children('.recordBody').slideUp({duration: 300, easing: 'easeOutQuad'});
					myDummy[0].unselected();
				}
			});
		});
		
		/*$(".msg_head").click(function(){
			if(!$(this).parent().hasClass('selected')){
				$('.msg_list.selected').removeClass('selected').children('.msg_body').slideUp({duration: 300, easing: 'easeInQuad'});
				$(this).parent().addClass('selected').children('.msg_body').slideDown({duration: 500, easing: 'easeOutQuad'});
			}else{
				$(this).siblings('.msg_body').slideUp({duration: 300, easing: 'easeInQuad'});
				$(this).parent().removeClass('selected');
			}
		});*/
	}
};

fontSize = {
	defaultSize:12,
	currentSize:null,
	maxSize:14,
	minSize:12,
	init:function(obj){
		for(i in obj){
			this[i] = obj[i];
		}
		this.currentSize = parseInt($.cookie('fontSize'));
		if(!Boolean(this.currentSize)){
			this.currentSize = this.defaultSize;
		}
		var style='<style>'
		for(var i=this.minSize;i<this.maxSize;i++){
			style+='.font_size_'+(i+1)+'{font-size:'+(i+1)+'px;}'
		}
		style+='</style>'
		$('body').append(style);
		this.set(this.currentSize);
	},
	removeClass:function(){
		if(/font_size_/.test($('body').attr('class'))){
			var classArray = $('body').attr('class').split(' ');
			for(i in classArray){
				if(/font_size_/.test(classArray[i])){
					classArray.splice(i,1);
				}
			}
			$('body').attr('class', classArray.join(' '));
		}
	},
	set:function(size){
		//if(size != null){	
			if(size > this.maxSize){
				size = this.maxSize;
			}else if(size < this.minSize){
				size = this.minSize;
			}
			
			this.currentSize = size;
			
			this.removeClass();
		
			if(this.currentSize != this.defaultSize){
				$('body').addClass('font_size_'+this.currentSize);
			}
		
			$.cookie('fontSize', this.currentSize, { expires: 30 });
		//}else{
		//	return this.currentSize;
		//}
	},
	get:function(){
		return this.currentSize;
	}
};

fontContrast = {
	defaultContrast:false,
	currentContrast:null,
	init:function(){
		this.currentContrast = $.cookie('contrast');
		if(this.currentContrast == null){
			this.currentContrast = this.defaultContrast;
		}
		$('body').append('<style>.contrast *{color:#000 !important;}</style>');
		this.set(this.currentContrast);
	},
	set:function(contrast){
			$('body').removeClass('contrast');
			this.currentContrast = contrast;
			if(this.currentContrast.toString() == 'true'){
				$('body').addClass('contrast');
			}
			$.cookie('contrast', this.currentContrast, { expires: 30 });
	},
	get:function(){
		return this.currentContrast.toString() == 'true';
	}
};

latestNewsMenu = {
	init:function(){
		
	},
	open:function(callback){
		$('.news-container').show().find('.content').css('left',function(){return -$(this).width();}).animate({
			left: '0'
		}, {
			duration: 1000, 
			specialEasing: {
				left: 'easeOutExpo'
			}, 
			complete: function() {
				if(typeof(callback)=='function'){
					callback();
				}
				// Animation complete.
			}
		});
	},
	close:function(callback){
		var positionX = $('.news-container .content').width()
		$('.news-container .content').animate({
			left: -positionX
		}, {
			duration: 200, 
			specialEasing: {
				left: 'easeInQuad'
			},
			complete: function() {
				$('.news-container').hide();
				if(typeof(callback)=='function'){
					callback();
				}
				// Animation complete.
			}
		});
	}
}
