$(function() {

	// Google Analytics tracking code
	URCHIN = typeof(pageTracker)=='undefined'?true:false;
	$('.track').each(function() {
		var tag = '/'+this.name.replace(/:/g,'/');
		if($(this).is('form')) {
			$(this).submit(function() {
				URCHIN?urchinTracker(tag):pageTracker._trackEvent('form', 'submit', tag);
			});
		} else {
			$(this).click(function() {
				URCHIN?urchinTracker(tag):pageTracker._trackPageview(tag);				   
			});
		}		
	});
	
	$('.package').packagePreview();
	
    $("li.event").each( function() {
        var obj = $(this);
        $(".details-link a", obj).toggle( function() {
            $.get('/includes/events-calendar-details.php', { event_id:$(this, obj).attr('id') },function(data) { 
                $(".event-description", obj).html(data).animate({height: 'show'}, 'slow');
                $(".details-link a", obj).html("Hide Details");
            });
            return false;
        }, function(){
            $(".event-description", obj).animate({height: 'hide'}, 'slow');
            $(".details-link a", obj).html("View Details");
        });
    });

    window.ie6 = /*@cc_on!@*/false && !window.XMLHttpRequest;

    if ( ie6 ) {
	$('ul#nav-primary li').hoverClass('ie-hover');
    }
    
    $('.follow-link').initializeFollowing();
    
    $('#push-signup #email').click(function(){
       if($(this).val()=='type email address here'){
            $(this).val('');    
       }
    });

});
//Framework functions for package, event, generic expand functions
(function($) {	
	$.fn.packagePreview = function(options) {
		var defaults = {
			hideDetails : 'Hide Details',
			viewDetails : 'View Details'
		},
		opts = $.extend(defaults, options);
		return this.each(function() {
			$('.package-details a', this).toggle(function(event) {
				event.preventDefault();
				$('.share-panel').hide();
				var el = $(this);
				$.get('/includes/package-details.php', { package_id: this.id.substr(3), channel: this.rel, lang: 'en' },function(data) { 
					el.html(opts.hideDetails).parent().addClass('active').parent().find('.package-long').hide().html(data).slideDown('slow');
				});
			},function(event) { 
				event.preventDefault();
				$('.share-panel').hide();
				$(this).html(opts.viewDetails).parent().removeClass('active').parent().find('.package-long').slideUp('slow', function() { 
					$(this).html(''); 
				});
			});
		});
	};
	$.fn.expand = function(options) {
		var defaults = {
			openText: 'View Details',
			closeText: 'Hide Details',
			longClass: '.package-long'
		},
		opts = $.extend(defaults, options);
		return this.each(function() {
			var obj = $(this);
			var tog = $('<div />').addClass('toggle');
			var control = $('<a />').attr('href', '#')
							.addClass('toggler')
							.html(opts.openText)
							.appendTo(tog)
							.toggle(function() { $(opts.longClass, obj).slideDown('slow'); $(this).html(opts.closeText).addClass('open'); },
									function() { $(opts.longClass, obj).slideUp('slow'); $(this).html(opts.openText).removeClass('open'); });
			
			$(opts.longClass, obj).after(tog).hide();
		});
	};

	$.fn.eventPreview = function(options) {
		var defaults = {
			hideDetails : 'Hide 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('/direct/events-calendar-ajax.php', { permalink: temp[0], rssfeed: temp[1], lang: LANG, op: 'details' },function(data) { 
						el.html(opts.hideDetails).parent().addClass('active').parent().children('.event-description').hide().html(data).slideDown('slow');});
				}
			});
		});
	};
	
})(jQuery);

$.fn.initializeFollowing = function() {
	return this.each(function() {
		$('.follow-link').live('click',function(event) {
			event.preventDefault();
			$('.follow-panel').hide();
			$(this).siblings('.follow-panel').css('display','inline');
		});
		$('.follow-close').live('click',function(event){
			event.preventDefault();
			$(this).parent().slideUp('fast');
		});
	});
};
	
$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};   

function validate(frm) {
    var o = frm.email.value;
    valid = /^[a-z0-9_+.-]+\@(?:[a-z0-9-]+\.)+[a-z0-9]{2,4}$/i.test(o); 
    if(!valid){ 
        alert('You must enter a valid email address');
        return false;
    }
    
    return true;
}
