/**
 * Base class, extended by specialised JS objects that may or may not be included
 * 
 * Namespace "Base"
 * @class Base
 * @desc Base class of this project
 */
var Base = function($){
	// VARIABLES DEFINED HERE ARE PRIVATE
	var arr_init = []; // Array containing all registered init-functions of subclasses
	
	// FUNCTIONS DEFINED HERE ARE PRIVATE
	
	/**
	 * Check and execute registered subclass functions
	 */
	function check_register() {
		for (var i=0; i<arr_init.length; i++) {
			arr_init[i]();
		}
	}
	
  
  /**
   * Checks IE version. This requires a line of JS in the <head> tags within
   * IE conditional statements similar to the one below. If not given,
   * Base.ieVersion stays null.
   * 
   * document.getElementsByTagName("html")[0].className += (" ie6");
   */
	function check_ie(){
		if( $ ){
			if(! window.XMLHttpRequest ) {
				Base.ieVersion = 6;
			}
			if( $('html.ie7').length > 0 ) {
				Base.ieVersion = 7;
			}
			if( $('html.ie8').length > 0 ) {
				Base.ieVersion = 8;
			}
			if (Base.ieVersion == 7 || Base.ieVersion == 8) {
				adjustStyle($(this).width());
				$(window).resize(function() {          
					adjustStyle($(this).width());      
				});				
			}
		}
	}
	
	function adjustStyle(width) {
		width = parseInt(width); 
		if (width < 320) {         
			$("#size-stylesheet").attr("href", "/info2011/static/css/layout320.css");      
		} else {
			if ((width >= 320) && (width < 640)) {          
				$("#size-stylesheet").attr("href", "/info2011/static/css/layout600.css");      
			} else {         
				if ((width >= 640) && (width < 1024)) {    
					$("#size-stylesheet").attr("href", "/info2011/static/css/layout960.css");      
				} else {         
					//$("#size-stylesheet").attr("href", "/info2011/static/css/layout.css");  
				}       
			} 
		}
	}  

	return { // Public area
		/**
		* Register (initialization) calls from subclasses
		* @param (obj_function) Function to initialize subclass
		*/
		register: function(obj_function) {
			arr_init.push(obj_function);
		},
		
		log: function(){
			if( typeof console == 'object' )
				console.log(arguments);
		},
		
		/**
		* Initialize this class
		*/
		init: function() {
			check_ie();
			check_register();
			
			if ($('body').hasClass('address')) {
				Base.GmapsContact.init();
			}
		}
	}
}(jQuery);

jQuery(document).ready(function(){
	Base.init();
});
