$(document).ready(function(){
	
	$("#navigation li:first").css("padding-top", "12px");
	$("#navigation li:last").css("border-bottom", "none").css("padding-bottom", "12px");
	
	$("span.closeTrigger").css("display", "inline");
	$("div#bondingVidMainCopy").css("display", "block");
	//$("p.JSfootnote").css("display", "none");
	
	$("#prod1body.closedBody").load("baby-products-1.jsp #prod1body");
	$("#prod2body.closedBody").load("baby-products-2.jsp #prod2body");
	$("#prod3body.closedBody").load("baby-products-3.jsp #prod3body");
	$("#prod4body.closedBody").load("baby-products-4.jsp #prod4body");
	
	$("#footerLinks a[rel='popup']").click(function(){
		window.open(this.href, "_blank", "width=570,height=600,scrollbars,location,resizable");
		//window.open(this.href, "_blank");
		return false;
	});
	$("a[rel='popup2']").click(function(){
		//window.open(this.href, "_blank");
		window.open(this.href, "_blank", "width=570,height=600,scrollbars,location,resizable");
		//window.self.close();
		return false;
	});
	
	$("ul#sitemap a:not([rel])").click(function(){
		window.opener.document.location = this.href;
		window.close();
		return false;
	});
	
	$("a[rel='leavingPopup']").click(function(){
		window.opener.document.location = this.href;
		window.close();
		return false;
	});
	
	$("a[rel='external']").click(function(){
		window.open(this.href, "_blank");
		return false;
	});
	
	$("a[rel='privacychange']").click(function(){
		window.open("policychange.jsp?url="+escape(this.href), "_blank", "width=325,height=325");
		return false;
	});
	
	$("a.pdfButton").attr("target","_blank");
	
	$("div#ppButtons input#declineButton").click(function(){
		window.close();
	});
	$("div#ppButtons input#acceptButton").click(function(){
		//window.opener.document.location = "http://www.babycenter.com/";
		
		var theLink = unescape(document.location.href.split("?")[1].split("=")[1]);
		window.open(theLink, "new_win","location,menubar,resizable");
		window.close();
	});
	$("span.req").css("display","inline");
	
	Pinkjs.setTriggers();
	Pinkjs.grabLinks();
	Pinkjs.initProdMenu();
	
	Pinkjs.setupAddFriends(1);
	
	$("form#tellfriendForm").submit(function(){
		Pinkjs.checkForm(this);
		return false;
	});
});


function goFullScreen(wVid) {
	//alert(wVid);
	var ww = screen.availWidth;
	var wh = screen.availHeight;
	
	var vWin = window.open("vidfull.jsp?"+wVid, "videoFull", "width="+ww+",height="+wh);
	vWin.moveTo(0,0);
}

function closeFullScreen() {
	window.close();
}





function hbxMediaPlay(hbxFileName, hbxCurrentPos, hbxEndPos, hbxFlashVersion) {
_hbSet('m.f',hbxFileName);
_hbSet('m.cp',hbxCurrentPos);
_hbSet('m.ep',hbxEndPos);
_hbSet('m.s','play');
_hbSet('m.cl','Flash Player');
_hbSet('m.cv',hbxFlashVersion);
_hbSet('m.tt','e');
_hbSend();
}
 
function hbxMediaPause(hbxFileName, hbxCurrentPos, hbxEndPos, hbxFlashVersion) {
_hbSet('m.f',hbxFileName);
_hbSet('m.cp',hbxCurrentPos);
_hbSet('m.ep',hbxEndPos);
_hbSet('m.s','pause');
_hbSet('m.cl','Flash Player');
_hbSet('m.cv',hbxFlashVersion);
_hbSet('m.tt','e');
_hbSend();
}
 
function hbxMediaStop(hbxFileName, hbxCurrentPos, hbxEndPos, hbxFlashVersion) {
_hbSet('m.f',hbxFileName);
_hbSet('m.cp',hbxCurrentPos);
_hbSet('m.ep',hbxEndPos);
_hbSet('m.s','stop');
_hbSet('m.cl','Flash Player');
_hbSet('m.cv',hbxFlashVersion);
_hbSet('m.tt','e');
_hbSend();
}
 
function hbxMediaPlayProgress(hbxFileName, hbxCurrentPos, hbxEndPos, hbxFlashVersion) {
_hbSet('m.f',hbxFileName);
_hbSet('m.cp',hbxCurrentPos);
_hbSet('m.ep',hbxEndPos);
_hbSet('m.s','playp');
_hbSet('m.cl','Flash Player');
_hbSet('m.cv',hbxFlashVersion);
_hbSet('m.tt','e');
_hbSend();
}






Pinkjs = {
	clickCloseTrigger:function(wTrigger, menuAlreadyTweaked){
		if(wTrigger != 0) {
			$(wTrigger).text("View Product").blur().parent("span").removeClass("closeTrigger").addClass("openTrigger").css("display","inline");
			
			$(wTrigger).parents(".productHeader").removeClass("currentHeader").css("background-position","left top").next(".productBody").slideUp("fast");
		}
		
		if(!menuAlreadyTweaked) {
			Pinkjs.tweakMenu(0);
		}
	
		Pinkjs.setTriggers();
	},
	clickOpenTrigger:function(wTrigger){
		var currOpen = $(".closeTrigger a");
		
		$(wTrigger).text("Close").blur().parent("span").removeClass("openTrigger").addClass("closeTrigger").css("display","inline");
		
		$(wTrigger).parents(".productHeader").addClass("currentHeader").css("background-position","left bottom").next(".productBody").slideDown("fast");
		
		
		Pinkjs.tweakMenu(wTrigger);
		
		if(currOpen.length > 0) {
			Pinkjs.clickCloseTrigger(currOpen[0], true);
		} else {
			Pinkjs.setTriggers();
		}
	},
	setTriggers:function(){
		$(".closeTrigger a").unbind().click(function(){
			Pinkjs.clickCloseTrigger(this);
			return false;
		});
		$(".openTrigger a").unbind().click(function(){
			Pinkjs.clickOpenTrigger(this);
			return false;
		});
	},
	initProdMenu:function() {
		$("ul#productsSubnav li a").click(function(){
			var menuItems = $("ul#productsSubnav li a");
			var prodLinks = $("span.prodTrigger a");
			var clickInd  = $("ul#productsSubnav li a").index(this);
			$(prodLinks[clickInd]).click();
			/*if(clickInd == 3) {
				$("div#mainNavBottom").removeClass("sub");
			} else {
				$("div#mainNavBottom").addClass("sub");
			}*/
			return false;
		});
	},
	tweakMenu:function(wTrigger){
		var pageRef = (wTrigger != 0) ? wTrigger : null;
		
		var thePageNames = new Array("Make+Your+Touch+_Lotion", "Make+Your+Touch+_Cream", "Make+Your+Touch+_Wash", "Make+Your+Touch+_Oil");
		
		var menuItems = $("ul#productsSubnav li a");
		for(var x=0; x<menuItems.length; x++){
			if(menuItems[x].href == pageRef) {
				$(menuItems[x]).parent("li").addClass("at");
				//alert(thePageNames[x]);
				_hbPageView(thePageNames[x]+"_ajax", "Ethos");
			} else {
				$(menuItems[x]).parent("li").removeClass("at");
			}
		}
	},
	grabLinks:function() {
		$("map#tagmap area").click(function(){
			var num = this.id.substr(4,this.id.length-1);
			Pinkjs.replaceVideo(num, true);
			return false;
		});
		
		$("ul#videosSubnav li a").click(function(){
			Pinkjs.replaceVideo($("ul#videosSubnav li a").index(this)+1, true);
			this.blur();
			return false;
		});
		
		$("ul#adsSubnav li a").click(function(){
			Pinkjs.replaceAd($("ul#adsSubnav li a").index(this)+1, true);
			this.blur();
			return false;
		});
		$("ul.adCopyLinks li a").click(function(){
			Pinkjs.replaceAd($("ul.adCopyLinks li a").index(this)+1, true);
			this.blur();
			return false;
		});
		$("ul#animsSubnav li a").click(function(){
			Pinkjs.replaceAnim($("ul#animsSubnav li a").index(this)+1, true);
			this.blur();
			return false;
		});
		$("ul.animCopyLinks li a").click(function(){
			Pinkjs.replaceAnim($("ul.animCopyLinks li a").index(this)+1, true);
			this.blur();
			return false;
		});
		$("ul.animSpanishCopyLinks li a").click(function(){
			Pinkjs.replaceAnimSpanish($("ul.animSpanishCopyLinks li a").index(this)+1, true);
			this.blur();
			return false;
		});
	},
	replaceVideo:function(num, auto){
		var aPlay = (auto ? "autoplay=true" : "");
		if(document.getElementById("adsSubnav")) {
			Pinkjs.replaceAd(num);
		} else {
			if(document.getElementById("videosSubnav")) {
				var FO = {
					movie:			"images/swf/pinkplayer.swf",
					width:			"462",
					height:			"337",
					majorversion:	"8",
					build:			"0",
					flashvars:		"videoUrl=video/tip&videoNo="+num+"&maxVideoNo=10&"+aPlay,
					wmode:			"transparent"
				};
				UFO.create(FO, "bondingVideoDiv");
				
				Pinkjs.tweakVideoMenu(num);
				_hbPageView("Bonding+Tips"+num+"_ajax", "Ethos");
				$("div.contentTag img").attr("src", "images/title/tag-videos"+num+".gif");
				$("#bondingVidMainCopy").load("baby-bonding-tips"+((num > 1) ? num : '')+".jsp #bondingVidMainCopy h3");
			} else if(document.body.id == "animShortsSpanish") {
				Pinkjs.replaceAnimSpanish(num);
			} else if(document.body.id == "animShorts") {
				Pinkjs.replaceAnim(num);
			} else if(document.body.id == "homepage") {
				var FO = {
					movie:			"images/swf/pinkplayer.swf",
					width:			"462",
					height:			"337",
					majorversion:	"8",
					build:			"0",
					flashvars:		"videoUrl=video/fourSigns&videoNo=&maxVideoNo=",
					wmode:			"transparent"
				};
				UFO.create(FO, "homepageVid");
			}
		}
	},
	replaceAd:function(num, auto){
		var aPlay = (auto ? "autoplay=true" : "");
		var whichVid = num;
		if(num == 2) {
			whichVid = Math.round(Math.random())+2;
		}
		
		var FO = {
			movie:			"images/swf/pinkplayer.swf",
			width:			"462",
			height:			"337",
			majorversion:	"8",
			build:			"0",
			flashvars:		"videoUrl=video/ad&videoNo="+whichVid+"&maxVideoNo=2&"+aPlay,
			wmode:			"transparent"
		};
		UFO.create(FO, "bondingVideoDiv");
		
		Pinkjs.tweakVideoMenu(num);
		_hbPageView("Tell+Us+How+"+num+"_ajax", "Ethos");
		$("#bondingVidMainCopy").load("baby-bonding-experiences"+((num > 1) ? num : '')+".jsp #bondingVidMainCopy h3");
	},
	replaceAnim:function(num, auto){
		var aPlay = (auto ? "autoplay=true" : "");
		
		var FO = {
			movie:			"images/swf/pinkplayer.swf",
			width:			"462",
			height:			"337",
			majorversion:	"8",
			build:			"0",
			flashvars:		"videoUrl=video/anim&videoNo="+num+"&maxVideoNo=3&"+aPlay,
			wmode:			"transparent"
		};
		UFO.create(FO, "bondingVideoDiv");
		
		Pinkjs.tweakVideoMenu(num);
		_hbPageView("Animated+shorts+"+num+"_ajax", "Ethos");
		$("#bondingVidMainCopy").load("animated-shorts"+((num > 1) ? num : '')+".jsp #bondingVidMainCopy h3");
	},
	replaceAnimSpanish:function(num, auto){
		var aPlay = (auto ? "autoplay=true" : "");
		
		var FO = {
			movie:			"images/swf/pinkplayer.swf",
			width:			"462",
			height:			"337",
			majorversion:	"8",
			build:			"0",
			flashvars:		"videoUrl=video/animation_spanish&videoNo=&maxVideoNo=&"+aPlay,
			wmode:			"transparent"
		};
		UFO.create(FO, "bondingVideoDiv");
		
		Pinkjs.tweakVideoMenu(num);
		_hbPageView("Pequenas+cestas+de+caricias_ajax", "Ethos");
		$("#bondingVidMainCopy").load("caricias"+((num > 1) ? num : '')+".jsp #bondingVidMainCopy h3");
	},
	tweakVideoMenu:function(num){
		var menuVids = $("ul.subNav li");
		$("ul.subNav li").removeClass("at");
		$(menuVids[num-1]).addClass("at");
		
		if(document.getElementById("animsSubnav")){
			if(num == menuVids.length) {
				$("#mainNavBottom").removeClass("sub");
			} else {
				$("#mainNavBottom").addClass("sub");
			}
		}
	},
	setupAddFriends:function(added){
		$("div.addFriendLink").remove();
		$("div.removeFriendLink").remove();
		var friendDivs = $("div.friendFormFriendDetails");
		var countFriendDivs = friendDivs.length;
		//alert("frienddivs = " + countFriendDivs);
		if (countFriendDivs < 4) {
			$("div.friendFormFriendDetails:last").append('<div class="addFriendLink"><a href="#">Add more friends</a></div>');
			$("div.addFriendLink a").unbind().click(function(){
				Pinkjs.addAFriend();
				return false;
			});
		}
		if (countFriendDivs > 1) {
			$("div.friendFormFriendDetails:last").append('<div class="removeFriendLink"><a href="#">Remove a friend</a></div>');
			$("div.removeFriendLink a").unbind().click(function(){
				Pinkjs.removeAFriend();
				return false;
			});
		}
		
		if(added == 1) {
			var labs = $("div.friendFormFriendDetails:last label");
			var inps = $("div.friendFormFriendDetails:last input");
			$(labs[0]).attr("for","friend"+(countFriendDivs-1)+"firstname");
			$(labs[1]).attr("for","friend"+(countFriendDivs-1)+"lastname");
			$(labs[2]).attr("for","friend"+(countFriendDivs-1)+"email");
			$(inps[0]).attr("name","friend"+(countFriendDivs-1)+"firstname");
			$(inps[1]).attr("name","friend"+(countFriendDivs-1)+"lastname");
			$(inps[2]).attr("name","friend"+(countFriendDivs-1)+"email");
			$(inps[0]).attr("id","friend"+(countFriendDivs-1)+"firstname");
			$(inps[1]).attr("id","friend"+(countFriendDivs-1)+"lastname");
			$(inps[2]).attr("id","friend"+(countFriendDivs-1)+"email");
			$(inps[0]).attr("class","required");
			$(inps[1]).attr("class","required");
			$(inps[2]).attr("class","required email");
			$(inps[0]).attr("value","");
			$(inps[1]).attr("value","");
			$(inps[2]).attr("value","");
		}
		
	},
	addAFriend:function(){
		$("div.friendFormFriendDetails:last").clone().insertBefore("div.friendFormMessage");
		Pinkjs.setupAddFriends(1);
		
	},
	removeAFriend:function(){
		$("div.friendFormFriendDetails:last").remove();
		Pinkjs.setupAddFriends();
	},
	checkForm:function(wForm){
		var errors = 0;
		var reqFields = wForm.getElementsByTagName("INPUT");
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		//alert(reqFields.length);
		for(var x=0; x<reqFields.length; x++) {
			//alert(reqFields[x].className);
			if(reqFields[x].className.indexOf("email") != -1) {
				if(filter.test(reqFields[x].value)) {
					$(reqFields[x]).removeClass("error");
				} else {
					$(reqFields[x]).addClass("error");
					errors++;
				}
			} else {
				if(reqFields[x].value) {
					$(reqFields[x]).removeClass("error");
				} else {
					$(reqFields[x]).addClass("error");
					errors++;
				}
			}
		}
		
		if(errors > 0) {
			alert("Please correct the fields highlighted.");
		} else {
			this.submit();
		}
	}
}

























