/**
 * Namespace Base
 * 
 * @class Base
 * @desc Base class
 * @constructor
 * @return {init}
 * 
 * @author Mathijs de Jong (Onbeperkt Media)
 * @version
 * 
 */
var Base = function(){
	/*
	 * PRIVATE
	 */
	
	// properties
	var	arr_init,
		is,
		Config,
		Forms,
		Browser,
		Flash,
		Maps,
		Menu,
		Font,
		Util;
		
	// set properties	
	arr_init = [];		// Array containing all registered init-functions of subclasses
	
	/**
	 * Config 
	 * global configurable values 
	 */
	Config = {
		debug			:	true,					// if debug mode is needed then true
		author			:	'Onbeperkt Media',		// author		
		easing			:	'easeInOutQuad',		// default easing method
		jsEnabledClass	:	'js',					// default class on body if Javascript is enabled
		ieClass			:	'ie',					// default class on body if IE6 is detected
		prefixBehaviour	:	'bh-'					// default html className prefix to add JS behaviour (default is 'bh-')
	};
	
	/**
	 * Forms
	 */
	Forms = {
		setDefaultValue: function(){
			$('input:text').each(function(){
				$(this).addClass("no-focus");
				
				if ($(this).hasClass('label-value')) {
					var labelElem = $(this).parent().find('label');
					var labelValue = $(labelElem).html();
					
					$(this).val(labelValue);
				}
				
				if (!$(this).hasClass('hold-value')) { // exceptions
					var initValue = $(this).val();
					$(this).focus(function(){
						$(this).removeClass("no-focus");
						if($(this).val() == initValue) $(this).val('');
					});
					$(this).blur(function(){
						if ($(this).val() == "") $(this).addClass("no-focus");	// set class no-focus only if value is cleared
						if($(this).val() == '') $(this).val(initValue);
					});
				}
			});
			$('textarea').each(function(){
				$(this).addClass("no-focus");
				if (!$(this).hasClass('hold-value')) { // exceptions
					var initValue = $(this).val();
					$(this).focus(function(){
						$(this).removeClass("no-focus");
						if($(this).val() == initValue) $(this).val('');
					});
					$(this).blur(function(){
						if ($(this).val() == "") $(this).addClass("no-focus");	// set class no-focus only if value is cleared
						if($(this).val() == '') $(this).val(initValue);
					});
				}			
			});
			
			$('select').each(function(){
				$(this).addClass("no-focus");
				$(this).focus(function(){
					$(this).removeClass("no-focus");
				});
				$(this).blur(function(){
					$(this).addClass("no-focus");
				});
			});
		},
		validateField: function(field){
			
			
		}
	};
	
	/**
	 * Browser shows browser specific information
	 * @param {Object} browserName
	 */
	Browser = {
		name:	null,
		is: function(browserName){
			var isBrowser = false;
			
			return isBrowser;
		},
		ie8: function(){
			//$('div.article.teaser').corner("20px cc:#c7e3c7");
		},
		init: function(){
			
			if (jQuery.browser.msie && jQuery.browser.version.substr(0,1) == 8) {
				Browser.ie8();
			};
			
			if (jQuery.browser.msie) {
				$('body').addClass(Config.ieClass);
			};
		}
	};
	
	Util = {
		createTabs: function(elem){
			elem.each(function(){
				
				var tabLinkList = $('<ul class="link-list tabs" />');
				
				$(this).find('div.section.tab').each(function(){
					var tabID, tabName;
					tabID = $(this).attr('id');
					tabName = $(this).find('h2').text();
					tabLinkList.append($('<li><a href="#'+tabID+'">'+tabName+'</a></li>'));
				});
				$(this).find('div.section.tab').not(':first').hide();
				tabLinkList.find('li:first').addClass('active');
				tabLinkList.insertBefore(elem);
				
				tabLinkList.find('a').click(function(e){
					e.preventDefault();
					if ($(this).hasClass('active')) return false;
					var targetTab = $(this).attr('href');
					$(targetTab).show();
					$(targetTab).parent('div').find('.tab').not(targetTab).hide();
					$(this).parents('ul').find('.active').removeClass('active');
					$(this).parent('li').addClass('active');
				});
			});
			
		}
	};
		
	// methods
	/**
	 * Initializes Base class
	 */
	init = function(){
		$('html').addClass('js');
		Forms.setDefaultValue();
		Browser.init();
		Util.createTabs($('div.article.tabs'));
		// initialize registered subClasses
		check_register();
	};
	
	/**
	 * Check and execute registered subclass functions
	 */
	function check_register() {
		for (var i=0; i<arr_init.length; i++) {
			arr_init[i]();
		};
	}
	
	/*
	 * PUBLIC
	 */
	return {
		
		/**
		 * registers subclasses
		 */
		register: function(obj_function) {
			arr_init.push(obj_function);
		},
		
		/**
		 * initializes Base class
		 */
		init: function(){
			init();
		}
	};
}();

$(document).ready(function(){
	Base.init();
});

