$(document).ready(function(){
	$("div#main-image, div#unit-main-image").supersleight({shim: '/mmlib/js/supersleight/x.gif'});
	
	$("input.placeholder").focus(function(){
		if($(this).hasClass("placeholder")){
			$(this).val("");
			$(this).removeClass("placeholder");
		}
	});
	
	$('#site-search').focus(function() {
		if($(this).val() == "Search") {
			$(this).val("");
		}
	}).blur(function() {
		if($(this).val() == "") {
			$(this).val("Search");
		}
	});
	
	$('input[name=email]').focus(function() {
		if($(this).val() == "Your e-mail address") {
			$(this).val("");
		}
	}).blur(function() {
		if($(this).val() == "") {
			$(this).val("Your e-mail address");
		}
	});
	
	$("div.tools ul li a").hover(function(){
		$("div#tools-popup-container p").html($(this).children("img").attr("title"));
		var offset = $(this).offset();
		$("div#tools-popup-container").css("display", "block");
		$("div#tools-popup").css({
			"left": 5 + offset.left - $("div#tools-popup-container p").width() / 2,
			"top": offset.top
		});
	},
	function(){
		$("div#tools-popup-container").css("display", "none");
	});

	$("select#event-range").change(function(){
		$(this).parent().parent().submit();
	});
	
	if( !$('body').hasClass('template-list') ) {
		// Toggle class for corner graphics based on screen width
		$(window).resize(function(){
			if($(document).width() > 1100 ) {
				$('body').removeClass('thin');
			} else {
				$('body').addClass('thin')
			}
		});
		if($(document).width() < 1100 ) {
			$('body').addClass('thin')
		}
	} else {
		$('body').addClass('thin');
	}
	
	//comments
	$('a.link-offensive-comment').click(function(){
		$(this).next().next().slideToggle('fast');
		return false;
	});
	
	$('input.offensive-reason').focus(function(){
		if($(this).hasClass('placeholder')){
			$(this).val('');
			$(this).removeClass('placeholder');
		}
	});
	
	$('form.form-offensive').submit(function(){
		var reason = $(this).children('input.offensive-reason');
		if(reason.hasClass('placeholder')){
			$(reason).val('');
		}
	});
	
	//stop site search from submitting default search text
	$("form#search-form").submit(function(){
		$(this).find('input.placeholder').val('');
	});
	
	// Check for mobile devices
	var reg = new RegExp("(up\.browser|up\.link|mmp|symbian|smartphone|midp|wap|phone|windows ce|pda|mobile|mini|palm|ipad)", "i");
	if(navigator.userAgent.match(reg)) {
		if($('#unit-mobile').length) {
			$('#unit-mobile').append('<p><span>Main Site</span><span>&nbsp;|&nbsp;</span><span><a href="http://m.' + window.location.hostname.replace('www.', '') + '?mobile=1">Mobile Site</span></p>');
		}
	}
	
});

