$(function() {
    $('body#synopsis ul#first-nav li strong, body#synopsis ul#first-nav li a:not(strong a)').append('<b class="first-round"></b><b class="second-round"></b>');

	$('a[class~="external-link"]').click(function() {
		window.open($(this).attr('href'));
		return false;
	});

	$('input, textarea').focus(function() {
		$(this).parent().addClass('focus');
	}).blur(function() {
		$(this).parent().removeClass('focus');
	});

	$('input.toggleval').each(function() {
		$(this).toggleval();
	});

	$('div#header form button, div#content form.inline button').each(function() {
		$(this).attr('title', $(this).text());
	});

	if(!($.browser.msie && parseInt($.browser.version.substr(0,1)) <= 7)) {
		$('ul#third-nav button').closest('li').css({'padding': '0', 'text-indent': '0'});
	}

	$('ul#second-nav').elementCounter('li', 'z-index', true);

	$('dl.image span').each(function() {
		$(this).attr('title', $(this).text());
	});
	// Fancybox
	if(!($.browser.msie && parseInt($.browser.version.substr(0,1)) <= 6)) {
		$('dl.image.fancy a, a.fancybox').each(function() {
			var t = $(this).attr('title');
			var def_t = '&copy;&nbsp;' + new Date().getFullYear() + ' SOLARWATT&nbsp;AG';
			$(this).fancybox({
				'padding': 0
				,'centerOnScroll': true
				,'overlayColor': 'black'
				,'titlePosition': 'over'
				,'title': (t == undefined ? def_t : t)
				,'transitionIn': 'elastic'
				,'transitionOut': 'none'
				,'type': 'image'
			});
		});
	}
});

$.fn.elementCounter = function(element, option, revert) {
	return $(this).each(function() {
		var elementCount = $(this).children(element).length;
		for(var i = 1; i <= elementCount; i++) {
			var count = i;
			if(revert) count = elementCount - i + 1;
			$(this).children(element + ':nth-child(' + i + ')').attr('style', option + ': ' + count);
		}
	});
};


