$(document).ready(function() {
  
	
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
		
		var x = $(this).find(".sub").attr("lang");
		//alert("#"+x);
		$("#"+x).addClass("active");
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		
	}
	
	function megaHoverOut(){
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	 	var x = $(this).find(".sub").attr("lang");
		$("#"+x).removeClass("active");
	}


	var config = {   
		 sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 100, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);
	
	$("ul.dropdown li").hover(function(){    
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');    
    }, function(){    
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');    
    });
	$("a").focus(function(){this.blur()});

});
jQuery.fn.initMenu = function() {  
    return this.each(function(){
        var theMenu = $(this).get(0);
        $('.acitem', this).hide();
        $('div.expand > .acitem', this).show();
        $('div.expand > .acitem', this).prev().addClass('active');
        $('div div.profileHead', this).click(
            function(e) {
           e.stopImmediatePropagation();
                var theElement = $(this).next();
                var parent = this.parentNode.parentNode;
                 if(theElement.hasClass('acitem') && theElement.is(':visible')) {
                        if($(parent).hasClass('collapsible')) {
                            $('.acitem:visible', parent).first().slideUp(500, 
                            function() {
                                $(this).prev().removeClass('active');
                            }
                        );
                        return false;  
                    }
                    return false;
                }
                if(theElement.hasClass('acitem') && !theElement.is(':visible')) {         
                    $('.acitem:visible', parent).first().slideUp(1000, function() {
                        $(this).prev().removeClass('active');
                    });
                    theElement.slideDown('normal', function() {
                        $(this).prev().addClass('active');
                    });
                    return false;
                }
            }
      
    );
});
};

$.fn.tabsBasic = function() {
	var par=$(this);
	$(" > ul li:first", this).addClass('focus');
	$(" > div:first", this).show();
	$(" > ul li", this).click(function(){
		var wrapper=$(this).parent().parent()
		var getIndex=$(wrapper).find("> ul li").index(this);
		$(wrapper).find("> ul li").removeClass('focus');
		$(this).addClass('focus');
		$(wrapper).find(" > div").hide();
		$(wrapper).find(" > div:eq("+getIndex+")").show();		
	});			
}
function tabPointer(b,c){$(b).click(function(){
	var a=$(b).index(this);$(c).fadeOut(0,function(){$(c+':eq('+a+')').show()}); $(c+':eq('+a+') a').click();$(b).removeClass('focus').filter(b+':eq('+a+')').addClass('focus')}
)};
$.fn.initVal = function(value) {
	$(this).val(value);
	$(this).focus(function(){
		if($(this).val()==value){$(this).val('')}
	});
	$(this).blur(function(){
		if($(this).val()==''){$(this).val(value)}
	});
}


//set top padding of the workspace to the height of the ribbon
function setTopPadding() {
   var wrkElem = document.getElementById('s4-workspace');
   var ribHeight = document.getElementById('s4-ribbonrow').offsetHeight;
   if (window.location.search.match("[?&]IsDlg=1")) {
      //margin works better for dialogs b/c of scrollbars
      wrkElem.style.marginTop = ribHeight + 'px';
      wrkElem.style.paddingTop = '0px';
   }
   else {
     //padding works better for the main window
     wrkElem.style.paddingTop = ribHeight + 'px';
   }
}

// bind top padding reset to ribbon resize event so that the page always lays out correctly.
//ExecuteOrDelayUntilScriptLoaded(function () { SP.UI.Workspace.add_resized(setTopPadding); }, "init.js");



