jQuery.noConflict();

/** 
 * Login form 
 * 
 * Login on enter
 */
function handleKeyPress(e,form){
	var key=e.keyCode || e.which;
	if (key==13){
		jQuery('#LoginForm').submit();
	}
}

// Get forget password forum
function getPasswordForm() {
	var oOptions = {
		method: "GET",
		asynchronous: true,
		onFailure: function (transport) {
			$('logincontainer').update(transport.statusText);
		},					 	 
		onSuccess: function(transport) {
			$('logincontainer').update(transport.responseText);
		}				
	};
	var oRequest = new Ajax.Updater({success: oOptions.onSuccess.bindAsEventListener(oOptions)}, '/intranet/login.web?action=getForgetPasswordForm', oOptions);
}

jQuery(document).ready(function() {
	
	jQuery("#searchForm input[type='submit']").hide(0, function () {
		var button = jQuery(this);
		var link = jQuery(document.createElement("a"));
		link.text(button.val());
		link.click(function() {button.click()});
		link.css('cursor', 'pointer');
		jQuery(this).after(link);
		jQuery(this).prev().val("");
	});
	
	/**
	 * Submenu
	 */
	jQuery("#subMenuContainer li a, #subMenuContainer li ul li a").hover(function(){
		jQuery(this).css("opacity", 0.7);
	}, function() {
		jQuery(this).css("opacity", 1);
	}); 
	
	/**
	 * Divide left over width over menu items
	 */
	var menuWidth = 0;
	jQuery("#topMenu ul li").each(function(){
		menuWidth += jQuery(this).width();
	});
	var menuCount = jQuery("#topMenu ul li").size();
	var totalWidth =  jQuery("#topMenu").width();
	var extraWidth = Math.floor((totalWidth - menuWidth) / menuCount);
	var newTotalWidth = 0;
	var newWidth = 0
	jQuery("#topMenu ul li").each(function(){
		newWidth = jQuery(this).width() + extraWidth
		newTotalWidth += newWidth;
		jQuery(this).width(newWidth);
	});	
	jQuery("#topMenu ul li").last().width((totalWidth - newTotalWidth) + newWidth);
	//Chrome 1px fix
	if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1 || jQuery.browser.msie) {
		//jQuery("#topMenu ul li:first").width(jQuery("#topMenu ul li:first").width() + 3);
	}
	
	/**
	 * Fix the padding for the topmenu mask
	 */
	var count = 0;
	var widthOfMask = 0;
	jQuery("#topMenu ul li").each(function(){
		if (count < 3) {
			widthOfMask = widthOfMask + jQuery(this).width();
		}
		count++;	
	});
	//The default right
	widthOfMask = (widthOfMask - 354) *-1;
	//jQuery("#topImageContainer img").css("right", widthOfMask +"px");	
	
	/**
	 * Add height on right side when content is too tall
	 */
	var contentHeight = jQuery("#contentContainer").outerHeight();
	if (contentHeight > 578) {
		//+ 60px for padding
		jQuery("#rightImageContainer").height(contentHeight);
	}
	
	/**
	 * Fancybox
	 */
	
	jQuery("a.fancybox").click( function(e) {
		e.preventDefault();	
	});
	
	if (jQuery("a.image").length) { 
		jQuery("a.image").fancybox({
			'zoomOpacity'			: true,
			'overlayColor' 			: '#000',
			'overlayShow'			: true,
			'overlayOpacity' 		: 0.75,
			'padding' 				: 0,
			'enableEscapeButton'	: true,
			'hideOnContentClick'	: false,
			'centerOnScroll'  		: false,
			'showCloseButton'		: true
		});
	}
	
	// Every a.fancybox_login get's renderd in 
	jQuery("a.fancybox_login").fancybox({
		'callbackOnShow'		: function() {
			jQuery("input:text:visible:first").focus();
		},
		'zoomOpacity'			: true,
		'overlayColor' 			: '#000',
		'overlayShow'			: true,
		'overlayOpacity' 		: 0.75,
		'frameWidth' 			: 462,
		'frameHeight' 			: 270,
		'padding' 				: 0,
		'enableEscapeButton'	: true,
		'hideOnContentClick'	: false,
		'centerOnScroll'  		: false
	});
	
});


	

