$(document).ready(function(){
	
	// Login reminder
	if(!globals.SIGNED_IN && $.cookies.get('hibbett_mvp_rewards_popup') == null)
	{
		message = 'If you are a Hibbett Sports&reg; MVP Rewards Participant, please be sure to log in to your account so that you can earn Points for interacting with the website.<br /><br />If you have not registered for the Program, <a href="#sign_up" onclick="mvp_ajax(\'#sign_up\');">click here to register</a> and start earning points towards your free stuff!';
		message += '<br /><br /><label><input type="checkbox" id="hibbett_mvp_rewards_popup" class="do_not_show" value="1" /> Do not show this again.</label>';
		settings = { sticky: true, theme:'message', header:'Login Credentials' };
		$.gritter.add({
			title: settings.header,
			text: message,
			sticky: settings.sticky,
			class_name: settings.theme
		});
	}
	
	// Coupon reminder if signed in
	if(globals.SIGNED_IN && $.cookies.get('mvp_coupon_popup') == null)
	{
		message = 'Remember to check your available coupons. Hibbett Sports&reg; MVP Rewards members get a 20% off coupon just for signing up!';
		message += '<br /><br /><label><input type="checkbox" id="mvp_coupon_popup" class="do_not_show" value="1" /> Do not show this again.</label>';
		settings = { sticky: true, theme:'warning', header:'Coupons' };
		
		$.gritter.add({
			title: settings.header,
			text: message,
			sticky: settings.sticky,
			class_name: settings.theme
		});
	}
	
	// "Do not show again" cookie
	$(".do_not_show").click(function(){
		date = new Date();
		if($(this).is(':checked')){
			$.cookies.set( $(this).attr('id'), 'off', {expiresAt:new Date(date.getFullYear()+2, date.getMonth(), date.getDate())} );
		} else {
			$.cookies.del( $(this).attr('id') );
		}
	});
	
	// Dock close button
	$("#btn-close").live('click', function(){
		mvp_close();
	});
	
	// Dock navigation items
	$('#mvpdoc-nav ul li a.ajax').click(function(){
		$(this).parent('li').addClass('active').siblings('li').removeClass('active');
		var arrow = $('<div class="arrow"></div>');
		arrow.css({
			'position':'absolute',
			'left':'50%',
			'margin-left':-20
		});
		$(this).append(arrow);
	
		mvp_ajax($(this).attr('href'));
		return false;
	});
	
});

function mvp_ajax(url, params, target)
{
	params = params != undefined ? params : '' ;
	target = target != undefined ? target : $('#mvpdoc-content') ;
	
	target.css({ 'margin-top':30, 'padding':10 }).html(preloader('loading...')).show();
	
	url = url.indexOf('#', 0) == -1 ? url : url.split('#')[1] ;
	
	url = '/ajax_auth/'+url+'/'+params;
	$.ajax({
		url: url,
		success: function(response){
			target.html(response);
		},
		error: function(response){
			
		}
	});
}

function mvp_close()
{
	$('#mvpdoc-nav li').removeClass('active');
	$('#mvpdoc-content').animate({ 'margin-top':-($('#mvpdoc-content').outerHeight())+30 }, 'normal', 'swing');
}
