/*

Final Prestige
Global JavaScript Methods

Developed by Steven McTainsh (smctainsh.com). For support enquiries, please contact the developer at http://www.smctainsh.com/contact/.

*/

// Prevent prototype conflicts
var $$$ = jQuery.noConflict();

function toggleLogin()
{
	$$$('#loginslide').slideToggle();
}

function toggleClient()
{
	$$$('#ctrls').slideToggle();
}

function addToCart(id, title, el)
{
	url = 'fulfillment/cartAdd.php?script=' + id + '&ajax';
	$$$(document).css('cursor', 'wait');
	
	$$$.get(url, function(data)
	{
		if(data == 'NOTLOGGEDIN')
		{
			showMessage('You cannot add this product to your cart because you are not logged in. Log in and try again.', 0);
		}
		else if(data == 'SUCCESS')
		{
			showMessage('\'' + title + '\' was successfully added to your cart.', 1);
		
			count = ($$$('#cartCount').html() * 1) + 1;
			
			$$$('#cartCount').fadeOut();
			$$$('#cartCount').html(count);
			$$$('#cartCount').fadeIn();
		}
		else
		{
			showMessage(data, 0);
		}
		
		$$$(document).css('cursor', 'default');
	});
}

// type: 0 = error, 1 = success
function showMessage(msg, type)
{	
	var element = document.createElement('div');
	$$$(element).hide();
	
	var className = (type == 0) ? 'error' : 'success';
	
	// Add the new class
	$$$(element).addClass(className);
	
	$$$(element).html(msg);
	
	$$$('#cartbubble').append(element);
	
	$$$(element).fadeIn();
	
	setTimeout(function() {
		var el = $$$('#cartbubble div').get(0);
		$$$(el).remove();
	}, 4000);
}
