var safeSimplePoll = new Class({ 
    Implements: Options,
	options: {
		wrapperId : 'esmasSafeAdminWrapper',
		mainContainersClassId: 'safe_main_containers', 
		mainHeaderId : 'safe_admin_header', 
		mainsubMenuId : 'subpropertiesMenu', 
		mainBodyId : 'safe_admin_body', 
		mainFooterId : 'safe_admin_footer', 
		headerHeight : 57, 
		submenuHeight : 73, 
		footerHeight : 25
	},
	windowHeight : 0, 
	windowWidth : 0, 
	workAreaHeight: 0, 
	workAreaWidth: 0, 
	initialize : function(options){ 
		this.setOptions(options); 
		this.setViewPort(); 
		this.refreshWindowSize();
		this.menuesAnimation(true); 
		this.centerObject('login_container');		
		this.centerObject('grid_container');
		
	},
	refreshWindowSize : function(){
		window.addEvent('resize', this.setViewPort.bind(this)); 
	}, 
	setViewPort : function (){
		var windowSize = window.getSize();
		this.windowHeight = windowSize.y;
		this.windowWidth = windowSize.x;
		
		this.resizeWrapper();
		this.resizeMenues();
		this.centerObject('login_container');		
		this.centerObject('grid_container');
	}, 
	resizeWrapper : function(){
		var myWrapper = $(this.options.wrapperId).set({
			'styles': {
				'width' : this.windowWidth + 'px',
				'height' : this.windowHeight + 'px', 
				'display' : 'block'
			}
		});
		var mainContainers = $$('.' + this.options.mainContainersClassId).set({
			'styles': {
				'width' : this.windowWidth + 'px'
			}
		});
		
		/*
		var myHeader = $(this.options.mainHeaderId).set({
			'styles': {
				'height' : this.options.headerHeight + 'px' 
			}
		});
		*/
		
		var myBody = $(this.options.mainBodyId).set({
			'styles': {
				'height' : eval(this.windowHeight - this.options.headerHeight - this.options.footerHeight) + 'px' 
			}
			
		});
		
		this.workAreaHeight = eval(this.windowHeight - this.options.headerHeight - this.options.footerHeight);
		this.workAreaWidth = this.windowWidth;
		
		
		/*
		var myFooter = $(this.options.mainFooterId).set({
			'styles': {
				'height' : this.options.footerHeight + 'px' 
			}
		});
		*/
	}, 
	
	resizeMenues : function(){ 
		if ($('accountMenu'))
			$('accountMenu').set({ 'styles': { 'width' : eval(this.windowWidth - 63) + 'px' } });
		
		if ( $('separatorMenu') )
			$('separatorMenu').set({ 'styles': { 'width' : eval(this.windowWidth - 63) + 'px' } });
		
		if ( $('propertiesMenu') )
			$('propertiesMenu').set({ 'styles': { 'width' : eval(this.windowWidth - 63) + 'px' } });
			
		if ($('subpropertiesMenu'))
			$('subpropertiesMenu').set({ 'styles': { 'width' : this.windowWidth + 'px' } });
	}, 
	
	
	
	
	
	
	
	centerObject : function(objectId){ 
		
		if ($(objectId)){
			
			var objectSize = $(objectId).getSize();
			$(objectId).style.position = 'absolute'; 
			
			var myElement = $(objectId).set({
				'styles': {
					'left': (Math.floor(eval(this.workAreaWidth/2)) - Math.floor(eval(objectSize.x/2))) + 'px',
					'top': (Math.floor(eval(this.workAreaHeight/2)) - Math.floor(eval(objectSize.y/2))) + 'px'
				}
			});
			
		} 
		
	}, 
	
	
	
	
	
	menuesAnimation : function(resetMenues){ 

			$$('#propertiesMenuContainer li').each(function(item,index){
				
															
					 item.addEvent('mouseover', function(){
						if (!item.hasClass('on')){
							item.removeClass('out');
							item.removeClass('on'); 
							item.addClass('hover');
						} else {
						}
							
					 });
					 item.addEvent('mouseout', function(){ 
						if (!item.hasClass('on')){
							item.removeClass('hover');
							item.removeClass('on'); 
							item.addClass('out'); 
						} else {
						}
							
					 });
					 item.addEvent('click', function(){ 
												 
						$$('#propertiesMenuContainer li').each(function(item2,index2){
								item2.removeClass('hover');
								item2.removeClass('out'); 
								item2.removeClass('on'); 
						});
						item.addClass('on');
						
						
						$$('#subpropertiesMenu div').each(function(item3,index3){
																   
								var outer_element = item.getElement('a').getProperty('id').toString().trim();
								var inner_element = item3.getProperty('id').toString().trim();
								
								
								if ( this.Right(outer_element, 3) == this.Right(inner_element, 3) )
									$(item3).style.display = 'block';
								else
									$(item3).style.display = 'none';
									
								
						}.bind(this));
						
							
					 }.bind(this));

				 
			}.bind(this)); 
			
		if (resetMenues && $('sub_menu_prp'))
			$('sub_menu_prp').style.display = 'block';

		
		
	}, 
	
 	Left : function(str, n){
		if (n <= 0) 
			return "";
		else if (n > String(str).length)
			return str;
		else
			return String(str).substring(0,n);
	}, 
	Right : function(str, n){
		if (n <= 0)
		   return "";
		else if (n > String(str).length)
		   return str;
		else {
		   var iLen = String(str).length;
	    	return String(str).substring(iLen, iLen - n);
		}
	}, 
	isArray : function(obj) { return (obj.constructor.toString().indexOf('Array') != -1); }, 
	guid : function() { return (this.S4()+this.S4()+"-"+this.S4()+"-"+this.S4()+"-"+this.S4()+"-"+this.S4()+this.S4()+this.S4()); }, 
	S4 : function() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1); } 
});
