/* IE6 flicker fix
-------------------------------------------------- */
try {document.execCommand("BackgroundImageCache", false, true);} catch(err){}
$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);

$(document).ready(function() {
	$('.ihasahover').hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');});

	checkDropdowns();
});

$(document).ready(function() {
	/* resize header dropdowns */
	$('P.selecta A').each(function(b,a){
		if( $(a).outerWidth() > $($(a).attr('href')).outerWidth() ){
			$($(a).attr('href')).css({width: $(a).outerWidth() + 'px'});
			$(a).css({width: $(a).outerWidth() - 20 + 'px'});
		} else {
			$($(a).attr('href')).css({width: $($(a).attr('href')).outerWidth() + 'px'});
			$(a).css({width: $($(a).attr('href')).outerWidth() - 20 + 'px'});
		}
	});

	if(js_site_lang == 'by')
	{
		var oRussianMonths = [
			['Янв', 'янв'],
			['Фев', 'фев'],
			['Мар', 'мар'],
			['Апр', 'апр'],
			['Май', 'мая'],
			['Июн', 'июн'],
			['Июл', 'июл'],
			['Авг', 'авг'],
			['Сен', 'сен'],
			['Окт', 'окт'],
			['Ноя', 'ноя'],
			['Дек', 'дек']
		];

		$("span.date").each(function(){
			var $this = $(this);

			$.each(oRussianMonths, function(id, val){
				var date = $this.html();
				$this.html(date.replace(val[0], val[1]));
			});
		});
	}

	$("ul.type09 li:odd").css('float','right');
});

$(document).ready(function() {
	$('P.expandable').each(function(i,a){
		$('A', a).click(function(){
			if($(this).hasClass('open')){
				$(this).removeClass('open');
				$($('A', a).attr('href')).addClass('hidden');
			} else {
				$(this).addClass('open');
				$($('A', a).attr('href')).removeClass('hidden');
			}
			return false;
		});
		if(!$('A', a).hasClass('open')){
			$($('A', a).attr('href')).addClass('hidden');
		}
	});
});

/* Dropdowns */

var timerDrop = '';
var prevDrop = '';
var prevDropOwner = '';

function showDrop(rel,target,open_left){
	window.clearTimeout(timerDrop);
	if(rel != prevDropOwner){realHideDrop();} else {return false;}
	prevDrop = target;
	prevDropOwner = rel;
	$(target).removeClass('drop-hidden').css({
		top: $(rel).offset().top + $(rel).outerHeight() - 1 + 'px',
		left: (open_left == true ? ($(rel).offset().left - $(target).outerWidth() + $(rel).outerWidth() + 47) : $(rel).offset().left) + 'px'
	}).hover(cancelHideDrop,hideDrop);
	$('SPAN.dropstart SPAN.a',$(target)).css({
		width: $(rel).outerWidth() + 'px'
	})
	$(rel).addClass('open');
	/*$(window).resize(function(){
		$(rel)[0].style.top = $(rel).offset().top + $(rel).outerHeight() - 1 + 'px';
		$(rel)[0].style.left = $(rel).offset().left + 'px';
	});*/
}
function cancelHideDrop(){
	window.clearTimeout(timerDrop);
}
function hideDrop(){
	window.clearTimeout(timerDrop);
	timerDrop = window.setTimeout('realHideDrop()',150);
}
function realHideDrop(){
	$(prevDrop).addClass('drop-hidden');
	$(prevDropOwner).removeClass('open')
	prevDrop = '';
	prevDropOwner = '';
}

function checkDropdowns(){

	var sSelectedValues2 = "";
	$.each($('.practice_area_checkbox'), function(){
		if($(this).is(':checked')) {
			sSelectedValues2 += $(this).parent().text() +', ';
		}
	});
	sSelectedValues2 = rtrim(sSelectedValues2, ", ");

	$('.selected_practice_areas').html(sSelectedValues2);

	sSelectedValues2 = "";
	$.each($('.location_checkbox'), function(){
		if($(this).is(':checked')) {
			sSelectedValues2 += $(this).parent().text() +', ';
		}
	});
	sSelectedValues2 = rtrim(sSelectedValues2, ", ");
	$('.selected_locations').html(sSelectedValues2);

	sSelectedValues2 = "";
	$.each($('.language_checkbox'), function(){
		if($(this).is(':checked')) {
			sSelectedValues2 += $(this).parent().text() +', ';
		}
	});
	sSelectedValues2 = rtrim(sSelectedValues2, ", ");
	$('.selected_languages').html(sSelectedValues2);

	sSelectedValues2 = "";
	$.each($('.type_checkbox'), function(){
		if($(this).is(':checked')) {
			sSelectedValues2 += $(this).parent().text() +', ';
		}
	});
	sSelectedValues2 = rtrim(sSelectedValues2, ", ");
	$('.selected_types').html(sSelectedValues2);


	// news

	sSelectedValues2 = "";
	$.each($('.news_practice_area_checkbox'), function(){
		if($(this).is(':checked')) {
			sSelectedValues2 += $(this).parent().text() +', ';
		}
	});
	sSelectedValues2 = rtrim(sSelectedValues2, ", ");

	$('.news_selected_practice_areas').html(sSelectedValues2);

	sSelectedValues2 = "";
	$.each($('.news_location_checkbox'), function(){
		if($(this).is(':checked')) {
			sSelectedValues2 += $(this).parent().text() +', ';
		}
	});
	sSelectedValues2 = rtrim(sSelectedValues2, ", ");
	$('.news_selected_locations').html(sSelectedValues2);


	// people

	sSelectedValues2 = "";
	$.each($('.people_practice_area_checkbox'), function(){
		if($(this).is(':checked')) {
			sSelectedValues2 += $(this).parent().text() +', ';
		}
	});
	sSelectedValues2 = rtrim(sSelectedValues2, ", ");

	$('.people_selected_practice_areas').html(sSelectedValues2);

	sSelectedValues2 = "";
	$.each($('.people_location_checkbox'), function(){
		if($(this).is(':checked')) {
			sSelectedValues2 += $(this).parent().text() +', ';
		}
	});
	sSelectedValues2 = rtrim(sSelectedValues2, ", ");
	$('.people_selected_locations').html(sSelectedValues2);

	sSelectedValues2 = "";
	$.each($('.people_language_checkbox'), function(){
		if($(this).is(':checked')) {
			sSelectedValues2 += $(this).parent().text() +', ';
		}
	});
	sSelectedValues2 = rtrim(sSelectedValues2, ", ");
	$('.people_selected_languages').html(sSelectedValues2);
}

function rtrim ( str, charlist ) {
	// Removes trailing whitespace
	//
	// version: 1008.1718
	// discuss at: http://phpjs.org/functions/rtrim    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +      input by: Erkekjetter
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   bugfixed by: Onno Marsman
	// +   input by: rem    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
	// *     example 1: rtrim('    Kevin van Zonneveld    ');
	// *     returns 1: '    Kevin van Zonneveld'
	charlist = !charlist ? ' \\s\u00A0' : (charlist+'').replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\\$1');
	var re = new RegExp('[' + charlist + ']+$', 'g');
	return (str+'').replace(re, '');
}


//-------------------------------------------------------------------------------------------------------
// ClearTypeFadeTo / ClearTypeFadeIn / ClearTypeFadeOut
// Notes on the interaction of ClearType with DXTransforms in IE7
// http://blogs.msdn.com/ie/archive/2006/08/31/730887.aspx
(function($) {
	$.fn.ClearTypeFadeTo = function(options) {
		if (options)
				$(this)
						.show()
						.each(function() {
								if (jQuery.browser.msie) {
										// Save the original background color
										$(this).attr('oBgColor', $(this).css('background-color'));
										// Set the bgColor so that bold text renders correctly (bug with IE/ClearType/bold text)
										$(this).css({'background-color': (options.bgColor ? options.bgColor : '#fff')})
								}
						})
						.fadeTo(options.speed, options.opacity, function() {
								if (jQuery.browser.msie) {
										// ClearType can only be turned back on if this is a full fade in or
										// fade out. Partial opacity will still have the problem because the
										// filter style must remain. So, in the latter case, we will leave the
										// background color and 'filter' style in place.
										if (options.opacity == 0 || options.opacity == 1) {
												// Reset the background color if we saved it previously
												$(this).css({'background-color': $(this).attr('oBgColor')}).removeAttr('oBgColor');
												// Remove the 'filter' style to restore ClearType functionality.
												$(this).get(0).style.removeAttribute('filter');
										}
								}
								if (options.callback != undefined) options.callback();
						});
	};

	$.fn.ClearTypeFadeIn = function(options) {
		if (options)
				$(this)
						.css({opacity: 0})
						.ClearTypeFadeTo({speed: options.speed, opacity: 1, callback: options.callback});
	};

	$.fn.ClearTypeFadeOut = function(options) {
		if (options)
				$(this)
						.css({opacity: 1})
						.ClearTypeFadeTo({speed: options.speed, opacity: 0, callback: options.callback});
	};
})(jQuery);

