$(function () {
	// First tier navigation
	$('.level-1,.level-2').hide();
	if($(this).find('.level-1').length>0) {
		$('.level-0 li').hover(
			function(){	
				var active = $(this).hasClass('active');
				if(active) $(this).addClass('had');
				else $(this).addClass('active');
				var moffset = $(this).find('.level-1').parent().offset();
				var poffset = $('.shell').offset();
				var menuwidth = $(this).find('.level-1').outerWidth();
				var contentwidth = $('.shell').innerWidth()+poffset.left;
				if(menuwidth+moffset.left > contentwidth) {
					var diff = menuwidth+moffset.left-contentwidth;
					$(this).find('.level-1').css('left','-'+(diff+20)+'px');
				};
				$(this).find('.level-1').stop(true,true).fadeIn('fast');
			},
			function() {
				if(!$(this).hasClass('had')) $(this).removeClass('active');
				else $(this).removeClass('had');
				$(this).find('.level-1').stop(true,true).fadeOut('fast');
			}
		);
	}
	// Second tier navigation
	$('.level-1 li').mouseover(
		function() {
			if($(this).find('.level-2').length>0) {
				var moffset = $(this).find('.level-2').parent().offset();
				var poffset = $('.shell').offset();
				var menuwidth = ($(this).find('.level-2').outerWidth()+$(this).outerWidth());
				var contentwidth = $('.shell').innerWidth()+poffset.left;
				if(menuwidth+moffset.left > contentwidth) {
					var diff = menuwidth+moffset.left-contentwidth;
					$(this).find('.level-2').css('left','-'+(diff+20)+'px');
				};
				$(this).find('.level-2').stop(true,true).fadeIn('fast');
			}
		}
	);
	$('.level-1 li').mouseleave(
		function() {
			if($(this).find('.level-2').length>0) {
				if(!$(this).find('.level-2').hasClass('level-2-on')) {
					$(this).find('.level-2').stop(true,true).fadeOut('fast');					
				}
			}
		}
	);
	$('.level-2').live('mouseenter', function(){
		$(this).addClass('level-2-on');											  
	});
	$('.level-2').live('mouseleave', function(){
		$(this).fadeOut('fast');
		$(this).removeClass('level-2-on');	
	});
	// Find local site
	$('.contactus').live('mouseenter',
		function() {
			$('#contact').slideToggle('slow');
		}
	);
	$('#contact').live('mouseleave', 
		function(){
			$('#contact').fadeOut('slow');
		}
	);
	
	$('form').submit(function(){
		$('.required-error').removeClass('required-error');
		var proceed	= true;
		$('.required').each(function(){
			if ($(this).val() == '') {
				$(this).addClass('required-error');
				proceed = false;
			}
		});
		return proceed;
	});
	
	$('.required-error').blur(function(){
		if ($(this).val() != '') $(this).removeClass('required-error');
	});
	
	
	$('.submit').mouseenter(function(){
		$('.submit').attr('src', '/assets/img/common/btn-search-txt-over.gif' );							 
									 
	}).mouseleave(function() {
		$('.submit').attr('src', '/assets/img/common/btn-search-txt.gif' );	
	});
	
	$('.scrollpane').jScrollPane({showArrows:true, arrowSize:17, scrollbarWidth:17, dragMaxHeight:15});
	$('.listlinks li:last').removeClass('brd-bot');
	
	$('a.reginf').colorbox({
		inline: true,
		href: $(this).attr('href'),
		opacity: 0.7
	});
	
});
