if (typeof(BOUNTEE) == 'undefined') {
	BOUNTEE		= {};
	BOUNTEE.UI	= {};
}

BOUNTEE.UI.Global	= function()
{
	var init	= function() {
		if (!$.browser.msie) $('body').addClass('dynamic').css('opacity', 0.9999);

		patchButtons();
		globalNav();
		initPopups();
	
	
	}
	
	var globalNav 	= function() {
		
		$('ul#mysoti-global li:not(.mysoti, .selected) img').mouseover(function(){
			$(this).attr('src', $(this).attr('src').replace('.png', '-over.png'));
		})

		$('ul#mysoti-global li:not(.mysoti, .selected) img').mouseout(function(){
			$(this).attr('src', $(this).attr('src').replace('-over.png', '.png'));
		})
		
	}

	var patchButtons	= function() {
		$('button').each(function(i, obj){
			$(obj).width($(this).find('strong').text().length/1.4 + 'em');
		});		
	}
	
	var initPopups	= function() {
		
		$('a.popup').click(function(e){
			e.preventDefault();
			var url	 	= $(this).attr('href') + ' div:first';
			var jsurl	= '/assets/js/' + $(this).attr('href').split('/').pop().replace('html', 'js');
			$('#popup').load(url, function(){
				$.blockUI({  
				        message: $('#popup'),  
				        css: {
							padding:        0, 
					        margin:         0, 
					        width:          '100%',  
					        top:            '10px',  
					        left:           '20%',  
					        textAlign:      'left',  
					        color:          '#fff',  
					        border:         '0', 
					        backgroundColor:'transparent', 
					        cursor:         'normal'
						} ,
						overlayCSS:  {  
						        backgroundColor:'#000',  
						        opacity:        '0.5'  
						    }
				    });
				$(this).find('.top').append('<a href="#" id="popup-close"><img src="/assets/images/close.png" alt="close" /></a>');
				$(this).find('#popup-close').click(function(e){
					e.preventDefault();
					$('#popup').children().remove();
					$.unblockUI();
				});
				
				$.getScript(jsurl);
			});
			
		});
		
	}
	
	
	return {
		init: init
	}
	
}();

jQuery(function($) { BOUNTEE.UI.Global.init(); });
