var ba = {
	catalog : 'NMS11',
	catItems : [],
	cls : '.beautyAwards',
	omni : '&evar=beautyAwardsFriend',
	domain: 'http://' + document.location.host,
	prodId : document.location.href.match(/cprod|prod[0-9]+/),
	cheetahStart : 'http://ebm.neimanmarcusemail.com/r/regf2?aid=427197311&n=2&a=0',
	popWidth : 585,
	popHeight: 700,
	counter: 0
};

ba.setup = function(){
	var	i, itemCount = 0,
		potentialElems = $jq(ba.cls),
		itemRequest = [],
		tempItem = '',
		pr = new SP_Product();
	
	$jq(potentialElems).each(function(){
		tempItem = $jq(this).closest("td:contains('" + ba.catalog + "_')").find("font:contains('" + ba.catalog + "_')").html();
		if (tempItem) {
			itemCount++
			tempItem = tempItem.replace(ba.catalog + '_','');
			itemRequest[itemCount - 1] = tempItem;
			ba.catItems[itemCount - 1] = {
				idn : itemCount - 1,
				elem : this,
				itemId : tempItem,
				group : $jq(this).attr('group')
			};
		}
	});
	
	pr.getProducts(ba.catalog, itemRequest.join(','), function(){
		i = 0;
		for (i=0; i < pr.data.products.SPProduct.length; i++) {
			ba.catItems[i].vendor = pr.data.products.SPProduct[i].cmDesignerName;
			ba.catItems[i].prodName = pr.data.products.SPProduct[i].displayName;
			ba.catItems[i].image = ba.domain + '/products/mn/NM' + ba.catItems[i].itemId + '_mn.jpg';
			ba.catItems[i].link = ba.domain + '/store/catalog/prod.jhtml?itemId=' + ba.prodId + ba.omni;
		}
		
		$jq(potentialElems).each(function(e){
			//$jq(this).html('<img src="/category/beautyAwards/vote_bottom.gif" border="0">');
			$jq(this).html('<span class="" style="background:#EF5C87; cursor: pointer; padding: 2px 4px; -moz-border-radius: 3px; -webkit-border-radius: 3px;color: #fff; text-decoration: none; display: block;">Submit Your Vote for This Item</span>');
			$jq(this).click(function(){
				ba.vote(e);
			});
		});
	}, pr);
	
	$jq('.ba_vote_top')[0].style.display="inline";
	$jq('a.forwardFriend:eq(1)').closest('table').parent().parent().next().children('td').append('<a name="beautyAwardsAnchor">&nbsp;</a>');
};

ba.vote = function(n){
	var finalURL = ba.cheetahStart +
		'&GROUP=' + escape(ba.catItems[n].group) + 
        '&PRODNAME=' + escape(ba.catItems[n].prodName) + 
        '&VENDOR=' + escape(ba.catItems[n].vendor) + 
        '&IMAGE=' + escape(ba.catItems[n].image) + 
        '&ITEMID=' + ba.catalog + '_' + ba.catItems[n].itemId + 
        '&LINK=' + escape(ba.catItems[n].link);
	finalURL = finalURL.replace(/ /g, '\+');
	
	popUp(finalURL, ba.popWidth, ba.popHeight, 'no');
	
	// Omniture Stuff
	s.prop1 = ba.catalog + '_' + ba.catItems[n].itemId + ':vote_' + ba.catItems[n].group;
	s.t();
};

/*
$jq(document).ready(function(){
	if (ba.counter > 0) {
		ba.setup();
	}
});

*/
