/* -----------------------------------------------------------------------
	Client:		The Quincy
	Title:		Shared scripts
	Author:		Jason Garber, jgarber@esitemarketing.com
	Copyright:	E-site Marketing, LLC, http://www.esitemarketing.com
	Created:	24 April 2006
------------------------------------------------------------------------- */

/* ----- window.onload rewriting function ------------------------------- */
function addLoadEvent( func ) {
	var oldonload = window.onload;
	if ( typeof window.onload != 'function' ) {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

	// From: http://simon.incutio.com/archive/2004/05/26/addLoadEvent
	// Usage:
	// 		addLoadEvent( nameOfSomeFunctionToRunOnPageLoad );
	// 		addLoadEvent( function() { /* more code to run on page load */  });

$(function() {	
	//social media sharing
	$('.share-link').live('click',function() {
		$('.share-panel').hide();
		$(this).parents('.rss-item').find('.share-panel').css('display','inline');
		return false;
	});
	$('.share-close').click(function(){
		$(this).parents('.rss-item').find('.share-panel').slideUp('fast');
		return false;
	});
	
	//initialize calendar
	$('.vcalendar').eventPreview();
});

$.fn.eventPreview = function(options) {
	var defaults = {
		hideDetails : 'Close Details',
		viewDetails : 'View Details'
	},
	opts = $.extend(defaults, options);
	return this.each(function() {
		$('.view-details').live('click',function(event) {
			event.preventDefault();
			$('.share-panel').hide();
			if ($(this).parent().hasClass('active')) {
				$(this).html(opts.viewDetails).parent().removeClass('active').parent().children('.event-description').slideUp('slow', function() { 
					$(this).html(''); 
				});
			}
			else {
				var el = $(this);
				var temp = this.rel.split(':');
				$.get('events-calendar-ajax.php', { permalink: temp[0], rssfeed: temp[1], op: 'details' },function(data) { 
					el.html(opts.hideDetails).parent().addClass('active').parent().children('.event-description').hide().html(data).slideDown('slow');});
			}
		});
	});
};


