/*

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 = 'cartAdd.php?script=' + id + '&ajax';
	
	$$$.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();
			count = (count * 1) + 1;
			
			$$$('#cartCount').fadeOut();
			$$$('#cartCount').html(count);
			$$$('#cartCount').fadeIn();
		}
		else
		{
			showMessage(data, 0);
		}
	});
}

// type: 0 = error, 1 = success
function showMessage(msg, type)
{
	// To stop the bubble from toggling
	$$$('#cartbubble').hide();

	var className = (type == 0) ? 'error' : 'success';
	
	// Get rid of existing classes
	$$$('#cartbubble').removeClass('error');
	$$$('#cartbubble').removeClass('success');
	
	// Add the new class
	$$$('#cartbubble').addClass(className);
	
	$$$('#cartbubble').html(msg);
	
	$$$('#cartbubble').animate({opacity: 'toggle', height: 'toggle'}, 'medium');
	setTimeout('hideMessage()', 4000);
}

function hideMessage()
{
	$$$('#cartbubble').fadeOut();
}