﻿function hoverOver(el) {
	var aClassNames = el.attr("class").split(' ');
	if(aClassNames.length == 2) {
		$("." + aClassNames[1] + " ul").slideDown("slow");
	}
}

function newsRoll(index) {
	
	if ($('dl.news dd').length == index) { index = 0; }
	$('dl.news dd:eq(' + index + ')').show("drop",{direction:"down"},1000);
	$('dl.news dd:gt(' + index + '), dl.news dd:lt(' + index + ')').hide();
	index++;
	setTimeout('newsRoll(' + index + ')',12000);
	
	// lastNewsItem.toggle("drop",{direction:"down"},1000);
}

function filterList(target) {
	
	var index = $(target).text();
	
	$('#filterLawyers .active').removeClass('active');
	$(target).addClass('active');
	
	if (index.length > 2) {
		$('#theList > li').show();
	} else {
		$('#theList > li').hide();
		$('#theList > li.' + index).show();
	}
}

function setFilters() {	
	
	$('#filterLawyers .active').removeClass('active');
	$('#theList > li').hide();
	$('#filterLawyers a').each(function()
	{
		$(this).click(function(){
		   filterList(this);
		   return false;
		});		
	});
	/*
	var filters = "<span>Filters</span>",
		unique = new Array();
	
	$('#theList li').each(function()
	{
		var className = $(this).attr("class"),
			in_array = $.inArray(className, unique) + 1;
		if ( !in_array ) {
			filters += '<a href="#" class="filter" onclick="filterList(this); return false;">' + className + '</a> | ';
			unique[unique.length] = className;
		}
	});
	filters += '<a href="#" class="filter active" onclick="filterList(this); return false;">View All</a>';
	$('#filterLawyers').html(filters);
	*/
}

/* IE7 bugfix (message) */
function resetFooter()
{
	$('#temporary').hide();
	$('#footer').show();
}

function setMessage() 
{
	var $target = $('#temporary');
	if ( $target.length ) 
	{
		$target.addClass('onthemove').click(function() {
		
			$(this).slideUp("slow", resetFooter());
			
		}).find('strong').css({
			
			'margin-bottom' : 0,
			'padding'		: '2% 20%',
			'width'			: '60%'
			
		}).prepend('<u>Close</u>');
	}
}

$(document).ready(function() {
						   
	// Searchbox
	var lang = $('body').attr('lang'),
		msg = [];
	msg['en'] = 'Type keywords';
	msg['ru'] = 'Введите ключевые слова';
	
	$("#s").attr("value",msg[lang]).after('<input type="hidden" name="lang" value="' + lang + '" />');
	$("#s").focus(function() { $(this).attr("value",""); }).blur(function() { if ($(this).attr("value").length == 0) { $(this).attr("value",msg[lang]); } });	
	
	// Secondary Navigation;
	$("#secondaryNavigation ul").hide();
	$("#secondaryNavigation .current_page_item ul, #secondaryNavigation .current_page_parent ul").show();
	
	// Hover function
	$("#secondaryNavigation > li").hover(function() { hoverOver($(this)); },function() {});
	$("#secondaryNavigation").hover(function() {},function() { $("#secondaryNavigation li:not('.current_page_item, .current_page_parent, .current_page_ancestor') ul:visible").slideUp('slow'); });
	
	// Fully justify the main navigation elements
	function is_FF_Win(browser) {
		var mozilla = browser.indexOf("Mozilla");
		var windows = browser.indexOf("Windows");
		var firefox = browser.indexOf("Firefox");
		if(mozilla > -1 & windows > -1 & firefox > -1) {
			return true;
		}
		return false;
	}
	
	var browser = navigator.userAgent;
	var navWidth = $('#mainNav').width(); // 840 px
	var navElements = $('#mainNav > li');
	var elements = navElements.length;
	var whitespace =  parseInt(navWidth);
	
	// Reset margins
	$('#mainNav a').css('margin', 0);
	
	for(i=0; i<elements; i++) {
		
		whitespace = whitespace -  parseInt($(navElements[i]).width());
	}
	var newMargin = Math.floor(whitespace / (elements - 1));
	
	// Hack for Firefox on Windows
	if (is_FF_Win(browser)) { newMargin = newMargin - 0.5; }

	$('#mainNav a').css('margin-right',newMargin);
	$('#mainNav a:last').css('margin','0');
	
	// Color intro paragraph
	$('h2 + p').css('color', '#CC0C2F');
	
	// Add tab-box
	$("#tabs").tabs({ event: 'mouseover' });
	
	// Homepage Newsroll effect
	newsRoll(0);
	
	// Filter List (team)
	setFilters();
	
	// Verhuisboodschap
	// setMessage();
});
