$(function() {
	if (!$.browser.msie) return;

	/* IE 7 and IE 8 */
	if ($.browser.version < 9.0) {
		/* menu */
		$('#menu li:last-child').css('border-width', '0');

		/* profile */
		$('.boxes-4 > div:last-child').css('margin-right', '0');

		/* search */
		$.bind('_postLoad', function(e) {
			$('#search .ui-slider li:first-child span.ui-slider-label, #search .ui-slider li:last-child span.ui-slider-label').css('display', 'none');
		});

		/* datepicker */
		$.bind('_postLoad', function(e) {
			$('.datehour img + select').css('margin-left', '40px');
		});

		/* events-... */
		$.bind('_preLoad', function(e) {
			e.scope.find('.events-boxes > li a.image span img').css('margin-top', function() { return '-' + ((parseInt(this.height) - 134) / 2) + 'px'; });

			e.scope.find('.events-boxes.index > li:nth-child(3n+1), .events-boxes.index > li:nth-child(3n+2)').css('margin-right', '7px');
			/* fixme */
			e.scope.find('.events-boxes.search > li:nth-child(3n+1), .events-boxes.search > li:nth-child(3n+2)').css('margin-right', '7px');
			e.scope.find('.events-boxes.search.hack > li:nth-child(3n+1), .events-boxes.search.hack > li:nth-child(3n+2)').css('margin-right', '4px');
		});
	}

	/* IE 7 */
	if ($.browser.version < 8.0) {
		$('#search .rangeSlider').replaceWith('<span class="rangeSlider" id="radiusSlider"></span>');

		/* search */
		var tmp = $('<span style="position: relative; display: inline-block; width: 198px; height: 15px; margin-right: 10px; overflow: hidden;"></span>');
		tmp.append($('#search .where').clone());
		$('#search .where').replaceWith(tmp);
		$('#search .where').each(function(index) {
			$(this).css('position', 'absolute');
			$(this).css('left', '-3px');
			$(this).css('top', '-3px');
			$(this).css('width', '203px');
			$(this).css('height', 'auto');
		});
		var tmp = $('<span style="position: relative; display: inline-block; width: 130px; height: 16px; overflow: hidden;"></span>');
		tmp.append($('#search .category').clone());
		$('#search .category').replaceWith(tmp);
		$('#search .category').each(function(index) {
			$(this).css('position', 'absolute');
			$(this).css('left', '-3px');
			$(this).css('top', '-3px');
			$(this).css('width', '135px');
		});
		$('#search').prepend('<span style="float: left; width: 21px; height: 61px; margin-right: 8px; background: url(/images/nearby/search.png);"></span>');

		/* events-... */
		$.bind('_preLoad', function(e) {
			$('#events-user').css('overflow', 'auto').css('margin-bottom', '20px');
			$('#events-user li').css('float', 'left');
		});


		$('.events li').prepend('<span style="display: block; margin-left: -6px; width: 196px; height: 2px; background: #f9f9f9; border-bottom: 2px solid #c3c3c3;"></span>');
		$('.brown.events li > span:first-child').each(function(index) {
			$(this).css('border-top', '5px solid #b98441');
		});
		$('.green.events li > span:first-child').each(function(index) {
			$(this).css('border-top', '5px solid #9ba753');
		});

		$('.locations li p').prepend('<span style="position: absolute; top: 1px; left: 1px; right: 1px; display: block; height: 2px; background: #f9f9f9; border-top: 5px solid #5b79a0; border-bottom: 2px solid #c3c3c3;"></span>');
		$('.locations li h3').prepend('<span style="position: absolute; display: block; width: 30px; height: 30px; left: 50%; bottom: 0; margin: 0 0 -30px -15px; background: url(/images/nearby/arrow.bottom.png);"></span>');


		$('.categories ul li').prepend('<span style="display: block; height: 2px; background: #f9f9f9; border-top: 5px solid #7d7d7d; border-bottom: 2px solid #c3c3c3;"></span>');
		$('.categories h3').prepend('<span style="position: absolute; display: block; width: 30px; height: 30px; left: 50%; bottom: 0; margin: 0 0 -30px -15px; background: url(/images/nearby/arrow.bottom.png);"></span>');

		$('.tooltip').append('<span style="position: absolute; display: block; width: 30px; height: 30px; left: 50%; top: 50%; margin: -15px 0 0 -135px; background: url(/images/nearby/arrow.left.png);"></span>');

		for (var i = 0; i < document.styleSheets.length; ++i) {
			var mysheet = document.styleSheets[i];
			for (var j = 0; j < mysheet.rules.length; ++j) {
				if (mysheet.rules[j].selectorText == '.slideshow > DIV > SPAN') {
					mysheet.removeRule(j);
				}
			}
		}
		$('.slideshow > div > span')
		.css('display', 'inline-block')
		.css('width', '100%')
		.css('text-align', 'center');
		$('.slideshow > div > span').each(function(index) {
			$(this).html('<span style="white-space: normal;">' + $(this).html() + '</span>');
		});
	}
});


