$(document).ready(function()
{
	var productTitle = $('.products-left-description h1').text(),
		productType = productTitle.split(' '),
		productLine = productTitle.replace('\'', '').split(' ');
		
	/*****************************************
	*	PRODCUT LINE
	*****************************************/
	if(productLine[0] == 'Calming' || productLine[0] == 'Purifying' || productLine[0] == 'Revitalizing' || productLine[0] == 'Gentlemans')
	{
		var line = '';
		
		$.ajax({
		type: 'GET',
		url: '/products/index.php?main_page=rss_feed&feed=products',
		dataType: 'xml',
		success: function(xml)
		{
			$(xml).find('rss').find('channel').find('item').each(function(i)
			{
				var ptitle = $(this).find('title').text(),
					purl = $(this).find('link').text(),
					pimage = $(this).find('enclosure').attr('url'),
					pline = ptitle.replace('\'', '').split(' '),
					pstarter = ptitle.split(' ');
					x = 0;

				if(pline[0] == productLine[0] || pline[1] == productLine[0])
				{
					if(x <=2)
					{
						line += '<div class="products-right-line-item"><a href="'+ purl +'" title="' + ptitle +'">';
						
						if(pstarter[4] == 'Set' || pstarter[5] == 'Set')
							line += '  <img src="' + pimage + '" alt="' + ptitle + '" width="124" style="padding-top:48px;" /><br />';
						else
							line += '  <img src="' + pimage + '" alt="' + ptitle + '" height="180" /><br />';
						
						line += ptitle + '</a><br />';
						line += '<a href="' + purl + '" title="Learn more about ' + ptitle + '" class="add"><span>Add to Cart</span></a>';
						line += '</div>';
					}	
					x++
				}
			}); 
			$('.products-right-line').append(line);
		}});
	} else {
		var line = '';
		
		$('.products-right-line h4').text('Other products:');
		
		$.ajax({
		type: 'GET',
		url: '/products/index.php?main_page=rss_feed&feed=products',
		dataType: 'xml',
		success: function(xml)
		{
			$(xml).find('rss').find('channel').find('item').each(function(i)
			{
				var ptitle = $(this).find('title').text(),
					purl = $(this).find('link').text(),
					pimage = $(this).find('enclosure').attr('url'),
					pline = ptitle.replace('\'', '').split(' '),
					pstarter = ptitle.split(' ');
				
				if(i <= 2)
				{
					line += '<div class="products-right-line-item"><a href="'+ purl +'" title="' + ptitle +'">';
					
					if(pstarter[4] == 'Set' || pstarter[5] == 'Set')
						line += '  <img src="' + pimage + '" alt="' + ptitle + '" width="124" /><br />';
					else
						line += '  <img src="' + pimage + '" alt="' + ptitle + '" height="180" /><br />';
					
					line += ptitle + '</a><br />';
					line += '<a href="' + purl + '" title="Learn more about ' + ptitle + '" class="add"><span>Add to Cart</span></a>';
					line += '</div>';
				}
			}); 	
			$('.products-right-line').append(line);
			
		 }});
	}
	
	/*****************************************
	*	PRODCUT TYPE
	*****************************************/
	if(productType[2] == 'Serum' || productType[2] == 'Balm')
	{
		var header = 'Other Willamina ' + productType[2] + '\'s:',
			products = '';
			
		$.ajax({
		type: 'GET',
		url: '/products/index.php?main_page=rss_feed&feed=products',
		dataType: 'xml',
		success: function(xml)
		{
			$(xml).find('rss').find('channel').find('item').each(function(i)
			{
				var ptitle = $(this).find('title').text(),
					purl = $(this).find('link').text(),
					pimage = $(this).find('enclosure').attr('url'),
					ptype = ptitle.split(' ');
				
				if(ptype[2] == productType[2] || ptype[3] == productType[2])
				{
					products += '<div class="products-right-other-item"><a href="'+ purl +'" title="' + ptitle +'">';
					products += '  <img src="' + pimage +'" alt="' + ptitle + '" height="180" /><br />';
					products += ptitle + '</a><br />';
					products += '<a href="' + purl + '" title="Learn more about ' + ptitle + '" class="add"><span>Add to Cart</span></a></div>';
				}
			}); 
			$('.products-right-other').append(products);
		}});
		
		$('.products-right-other h4').text(header);		
	} else {
		var header = 'Other Willamina Serum\'s:',
			products = '';
			
			$('.products-right-other h4').text('Other Willimina Serum\'s:');	
			
		$.ajax({
		type: 'GET',
		url: '/products/index.php?main_page=rss_feed&feed=products',
		dataType: 'xml',
		success: function(xml)
		{
			$(xml).find('rss').find('channel').find('item').each(function(i)
			{
				var ptitle = $(this).find('title').text(),
					purl = $(this).find('link').text(),
					pimage = $(this).find('enclosure').attr('url'),
					ptype = ptitle.split(' ');
				
				if(ptype[2] == 'Serum' || ptype[3] == 'Serum')
				{
					products += '<div class="products-right-other-item"><a href="'+ purl +'" title="' + ptitle +'">';
					products += '  <img src="' + pimage +'" alt="' + ptitle + '" height="180" /><br />';
					products += ptitle + '</a><br />';
					products += '<a href="' + purl + '" title="Learn more about ' + ptitle + '" class="add"><span>Add to Cart</span></a></div>';
				}
			}); 
			$('.products-right-other').append(products);
		}});		
	}
	resize();
});