var menuAnimating = false;
var lang, langID;
var textSearch = {
	'de': 'Volltextsuche',
	'en': 'Text search',
	'fr': 'Recherche'
};

var proMtec = {
	'de': 'proMtec',
	'en': 'proMtec',
	'fr': 'proMtec'
};

$(document).ready(function() {
	lang = $('html').attr('lang');
	langID = {"de": 0, "en": 1, "fr": 2}[lang];

	// show search field default keyword
	$('#searchform .macina_searchbox_inputbox')
		.val(textSearch[lang])
		.css('color', '#666')
		.focus(function() {
			$(this).css('color', '#000');
			if($(this).val() == textSearch[lang]) $(this).val('');
		})
		.blur(function() {
			$(this).css('color', '#666');
			if($(this).val() == '') $(this).val(textSearch[lang]);
		});

	// animate menu
	$('#menu>ul>li:not(.active)>ul').hide();
/*
	$('#menu>ul>li:not(.active):has(ul)>a').toggle(function() {
		$(this).parent().children('ul:eq(0)').slideDown();
		return false;
	},
	function() {
		$(this).parent().children('ul:eq(0)').slideUp();
		return false;
	});
*/
	$('#menu>ul>li:not(.active):has(ul)').hover(function() {
		if(!menuAnimating) {
			menuAnimating = true;
			$(this).children('ul:eq(0)').stop(true, true).slideDown(400, function() {
				menuAnimating = false;
			});
		}
	},
	function() {
		if(!menuAnimating) {
			menuAnimating = true;
			$(this).children('ul:eq(0)').stop(true, true).slideUp(400, function() {
				menuAnimating = false;
			});
		}
	});

	// swap language list against selector
	$('#language').append('<select id="lang" name="lang"></select>');
	$('#language ul li a').each(function(index) {
		var href = $(this).attr('href');
		var text = $(this).html();
		$('#language select').append('<option value="' + href +'"' + ((index == langID) ? ' selected' : '') + '>' + text + '</option>');
	});
	$('#language ul').remove();

	// style select box
	$('select')
		.uniform()
		.change(function() {
			var index = $(this).index($(this).children(':selected'));
			if(index != langID) document.location.href = $(this).val();
		});

	// embed flash movie for browsers other than IE6
	if(!($.browser.msie && ($.browser.version.substr(0,1)=="6"))) {
		$('#titlebar').wrapInner('<div id="flash_movie">');
		var flashvars = {};
		var params = {};
		params.base = 'http://www.pro-m-tec.de/';
		params.play = 'true';
		params.loop = 'true';
		params.scale = 'showall';
		params.wmode = 'transparent';
		params.allowFullScreen = 'false';
		params.allowScriptAccess = 'sameDomain';
		var attributes = {};
		attributes.id = 'flash_content';
		swfobject.embedSWF("/fileadmin/swf/header.swf", "flash_movie", 727, 143, "9", null, flashvars, params, attributes);
	}

	if($('area').length > 0) {
		$('body').append('<div id="info_bubble"></div>');
		$('#info_bubble').css({'position': 'absolute', 'display': 'block', 'background': '#ebf6fa', 'color': '#002d70', 'padding': '3px', 'display': 'none', 'opacity': '0.7'});
	}

	$('area').hover(function(e) {
		var offset = $(this).offset();
		var coords = $(this).attr('coords').split(',');
		var x = offset.left * 1 + coords[0] * 1;
		var y = offset.top * 1 + coords[1] * 1;
		var altText = $(this).attr('alt');
		$('#info_bubble').html(proMtec[lang] + ' ' + altText).css({'left': (x + 20) + 'px', 'top': y + 'px'}).show();
	},
	function() {
		$('#info_bubble').hide();
	});
});