
// logo click

$(function () {
	$('#logo')
		.css('cursor', 'pointer')
		.click(function (e) {
			e.preventDefault();
			document.location = '/';
		});
});

// preload images

$(function () {
	$('<img>').attr('src', '/wp-content/themes/divine/style/images/main-menu-events-hover.gif');
	$('<img>').attr('src', '/wp-content/themes/divine/style/images/main-menu-divine-picks-hover.gif');
	$('<img>').attr('src', '/wp-content/themes/divine/style/images/main-menu-mom-of-the-month-hover.gif');
	$('<img>').attr('src', '/wp-content/themes/divine/style/images/main-menu-brought-to-you-by-divine-hover.gif');
	$('<img>').attr('src', '/wp-content/themes/divine/style/images/main-menu-media-hover.gif');
});

// png ie fix

$(function () {
	if ($.browser.msie && $.browser.version >= 6) {
		$('.pngFix, #mcCalendar, .mcDate, .mcEventPane').each(function () {
			try {
				if ($(this).css('background-image').match(/\.png(['"]?\))?$/i)) {
					if ($.browser.version <= 7) {
						DD_belatedPNG.fixPng(this);
					}
				} else {
					$(this).css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, src='" + $(this).attr('src') + "', sizingMethod='scale')");
					$(this).attr('src', '/images/blank.gif');
				}
			} catch(err) {}
		});
	}
});

// rounded corners

$(function () {
	DD_roundies.addRule('#headerContainer #topMenu li a', '8px', false);
});

// custom scroll bar

$(function () {
	$('.scrollPane').jScrollPane({
		scrollbarWidth: 28
	});
});

// calendar events

$(function () {
	var hitBox = $('#hitBox');
	hitBox.click(function (e) {
		hitBox.hide('fast');
		$('.mcEventPane').fadeOut('fast', function () {
			$(this).remove();
		});
	});
	function showHitBox() {
		hitBox
			.width($('body').width())
			.height($('body').height())
			.show('fast');
	}
	$('.eventLink').click(function (e) {
		e.preventDefault();
		
		mcEvent = events[this.hash.slice(this.hash.indexOf('#')+1)];
		
		var pos1 = $(this).position();
		var pos2 = $(this).offsetParent().position();
		
		var eventPane = $('<div class="mcEventPane"><div class="mcEventPaneInner">\
				<div class="mcEventPaneTitle"><a href="'+mcEvent.url+'&ctz=America/New_York" target="_blank">'+mcEvent.title+' <span style="font-size:10px;">[More Info]</span></a></div>\
				<div class="mcEventPaneStartTime">'+mcEvent.startTime+'</div>\
				<div class="mcEventPaneWhere">'+mcEvent.where+'</div>\
				<div class="mcEventPaneContent">'+mcEvent.content+'</div>\
				<div class="mcEventPaneUrl"><a href="'+mcEvent.url+'&ctz=America/New_York" target="_blank"><img src="/wp-content/themes/divine/style/images/cal-icon.png" alt="" class="pngFix" /></a></div>\
			</div></div>')
			.css('top', pos1.top+pos2.top-67)
			.css('left', pos1.left+pos2.left-260)
			.css('display', 'none');
		var panes = $('.mcEventPane');
		if (panes.length == 0) {
			$('#mcCalendar').append(eventPane);
			eventPane.fadeIn('fast');
			showHitBox();
		} else {
			panes.fadeOut('fast', function () {
				$(this).remove();
				$('#mcCalendar').append(eventPane);
				eventPane.fadeIn('fast');
			});
		}
	});
});

// fix hrs

$(function () {
	$('hr').filter(function () {
		if ($(this).parent('div.hr').length == 0) {
			return true;
		} else {
			return false;
		}
	}).wrap('<div class="hr"></div>');
});