 var baseBGposX = -386;
 var ContentWidth = 1010;
function trackCall(obj){
	for (var i in obj) {
		s[i] = obj[i];
	}
	s.server="MHS";
	s.linkInternalFilters="javascript:,subscribe.hearstmags.com,www.myholidayshopper.com"
	var s_code=s.t();if(s_code)document.write(s_code);
}
$(document).ready(function(){
	
	var endIndex = location.href.indexOf("com");
	var finalwebroot = location.href.substr(0,endIndex+4);
	if(endIndex>0){
		webroot = finalwebroot;
	}
	
	adjustBodyBG();
	//initDeleteProductBtns();
	
	// Init "Edit relation" link
	$("#user_top_box_left span a").click(function(){
		displayInlineRelationBox();
		return false;
	});
	
	// Init "Edit relation" cancel-btn
	$("#edit_recipient a.cancel_add_recipient").click(function(){
		$("#edit_recipient").hide();
	});
	
	// Init "Edit relation" done-btn
	$("#edit_recipient a.done_add_recipient").click(function(){
		var current_id = $(this).attr("id").split("_")[1];
		if($("#edit_recipient input#new_name").val() != "") {
			var data = {
						name : $("#edit_recipient input#new_name").val(),
						tags : $("#edit_recipient select#new_relation").val(),
						id : current_id
						};

			$.post(webroot + "/widget/widgets/updateRelation", data, function(data, textStatus) {
				window.location = window.location;
			});
		} else {
			alert("Please enter Name");
			$("#edit_recipient input#new_name").focus().css("border-color", "#f00");
		}
		return false;
	});
	
	// Init "Add New Gift List"
	$("div#yourlists_top a#btn_add_list").click(function(){
		showAddRecipientBox2();
	});
	
	// Init "Done" in "Add new Gift List" popup
	$("div#add_recipient2 a.done_add_recipient").click(function(){
		if($("div#add_recipient2 input#new_name").val() != "") {
			var data = {name : $("div#add_recipient2 input#new_name").val(), relation : $("div#add_recipient2 select#new_relation").val()};	
			$.post(webroot + "/widget/widgets/addList2", data, function(data, textStatus) {
				window.location.reload();
			});
		} else {
			alert("Please enter Name");
			$("div#add_recipient2 input#new_name").focus().css("border-color", "#f00");
		}
		return false;
	});
	
	// Init the "Cancel" btn in the Add Recipient Box
	$("div#add_recipient2 a.cancel_add_recipient").click(function(){
		$("#add_recipient2").hide();
		return false;
	});
	
});
/********************************
 *  common usage 
 *******************************/
function adjustBodyBG(){
	if($("body").width()<1014){
		$("#bgholder").width(1400);
		$("#bgholder").css({backgroundPosition:"0px 0px"});
	}else{
		$("#bgholder").width($("body").width());
		var newPos = ($("body").width()- 1014 + baseBGposX)/2;
		var newPosStr = newPos+"px 0px"; 
		$("#bgholder").css({backgroundPosition:newPosStr});
	}
}

function initDeleteProductBtns(){
	
}

function displayInlineRelationBox() {
	var newLeft = ($(window).width() / 2) - 200;
	$("#edit_recipient").show().css("top", "300px").css("left", newLeft + "px");
}

function showAddRecipientBox2() {
	var newLeft = ($(window).width() / 2) - 200;
	$("#add_recipient2").css("left", newLeft + "px");
	$("#add_recipient2").css("top", "300px");
	$("#add_recipient2").show();
}
function relaoadRecent(){
	$("#recentViewed").load("<?php echo $this->webroot.'products/recentViewed';?>");
}