// function to toggle the "share" button in and out
function toggleShare() {
    $("#shareIt").slideToggle('slow');
}

function showLoginModal(src){
	$('#showLoginModalFrame').attr('src', src);
	$('#showLoginModalContainer').modal({
		overlay:80,
		overlayCss: {backgroundColor:"#4e552c"},
		overlayClose: true,
        closeHTML: '',
		zIndex: 1000,
		escClose: true,
		autoResize: true, 
		onClose: function() { 
					top.location.href = top.location.href;
				 },
		minHeight: 454, //this fixes IE bug when the width and height is not set in the style sheet!!
		maxWidth: 755 //this fixes IE bug!!
		
	});	
}

function showSignUpModal(src){
	$('#showSignUpModalFrame').attr('src', src);
	$('#showSignUpModalContainer').modal({
		overlay:80,
		overlayCss: {backgroundColor:"#4e552c"},
		overlayClose: true,
        closeHTML: '',
		zIndex: 1000,
		escClose: true,
		autoResize: true, 
		onClose: function() { 
			top.location.href = top.location.href;
		 },
		minHeight: 454, //this fixes IE bug when the width and height is not set in the style sheet!!
		maxWidth: 755 //this fixes IE bug!!
		
	});	
}

function showSendToFriendModal(src){
	$('#showSendToFriendModalFrame').attr('src', src);
	$('#showSendToFriendModalContainer').modal({
		overlay:80,
		overlayCss: {backgroundColor:"#4e552c"},
		overlayClose: true,
        closeHTML: '',
		zIndex: 1000,
		escClose: true,
		autoResize: true, 
		onClose: function() { 
					top.location.href = top.location.href;
				 },
		minHeight: 280, //this fixes IE bug when the width and height is not set in the style sheet!!
		maxWidth: 755 //this fixes IE bug!!
		
	});	
}

function showNewsletterSubscribeModal(src){
	$('#showNewsletterSubscribeFrame').attr('src', src);
	$('#showNewsletterSubscribeContainer').modal({
		overlay:80,
		overlayCss: {backgroundColor:"#4e552c"},
		overlayClose: true,
		zIndex: 1000,
        closeHTML: '',
		escClose: true,
		autoResize: true, 
		onClose: function() {
					//top.location.href = top.location.href;
				 },
		minHeight: 454, //this fixes IE bug when the width and height is not set in the style sheet!!
		maxWidth: 755 //this fixes IE bug!!
		
	});
    
}

function frontEndLogout() {	

	$.ajax({
		type: "GET",
		url:  "/includes/logout.php",
		data: "logout=1",
		dataType: "html",
		timeout: 10000,
		dataType: 'json',
		success: function(data) {
			if (data.status || data.status == 'true' || data.status == '1') {
				window.top.location = '/'; 
			} 
		}
	})	
}

function addToRecipeBook(recipe, user, product) {

	/* First check how many arguments are there. */
	if(arguments.length == 2) {
	
		/* The user needs to log in first. */
		showLoginModal('/lightboxes/login.php?addRecipe='+recipe);
		
	} else if(arguments.length == 3){

		$.ajax({
			type: "GET",
			url:  "/includes/addRecipe.php",
			data: "recipe="+ recipe + "&user=" + user + "&product=" + product,
			timeout: 10000,
			dataType: 'json',
			success: function(data) {
				if (data.status == '1') {
					alert('You must log in first!');
				}
				if(data.status == '2') {
					alert('Please enter correct parameters');
				}
				if(data.status == '3') {
					alert('Recipe already in your recipe book');
				}
				if(data.status == '4') {
					$('#'+recipe).html(' ');
					$('#'+recipe).html('<span class="fr"><a href="/recipes/my-recipe-book/">My recipe book</a></span>');
				}
				if(data.status == '0') {
					alert('<span class="fr">Recipe could not be added, please try again later</span>');
				}
			}
		})
	}
}

function showCompetitionModal(src,width,height){
    $('#showCompetitionFrame').attr('width',width).attr('height',height);
    $('#showCompetitionFrame').attr('src', src);
    $('#showCompetitionContainer').modal({
        overlay:80,
        overlayCss: {backgroundColor:"#4e552c"},
        overlayClose: true,
        closeHTML: '',
        zIndex: 1000,
        escClose: true,
        autoResize: true, 
        onClose: function() { 
            top.location.href = top.location.href;
         },
        minHeight: 454, //this fixes IE bug when the width and height is not set in the style sheet!!
        maxWidth: 755 //this fixes IE bug!!
        
    });    
}
