/* 
 * Jquery browser detect plugin to identify browser/os detection.
 * jQuery Browser Plugin - http://jquery.thewikies.com/browser/
*/
(function($){$.browserTest=function(a,z){var u='unknown',x='X',m=function(r,h){for(var i=0;i<h.length;i=i+1){r=r.replace(h[i][0],h[i][1]);}return r;},c=function(i,a,b,c){var r={name:m((a.exec(i)||[u,u])[1],b)};r[r.name]=true;r.version=(c.exec(i)||[x,x,x,x])[3];if(r.name.match(/safari/)&&r.version>400){r.version='2.0';}if(r.name==='presto'){r.version=($.browser.version>9.27)?'futhark':'linear_b';}r.versionNumber=parseFloat(r.version,10)||0;r.versionX=(r.version!==x)?(r.version+'').substr(0,1):x;r.className=r.name+r.versionX;return r;};a=(a.match(/Opera|Navigator|Minefield|KHTML|Chrome/)?m(a,[[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/,''],['Chrome Safari','Chrome'],['KHTML','Konqueror'],['Minefield','Firefox'],['Navigator','Netscape']]):a).toLowerCase();$.browser=$.extend((!z)?$.browser:{},c(a,/(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/,[],/(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/));$.layout=c(a,/(gecko|konqueror|msie|opera|webkit)/,[['konqueror','khtml'],['msie','trident'],['opera','presto']],/(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/);$.os={name:(/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase())||[u])[0].replace('sunos','solaris')};if(!z){$('html').addClass([$.os.name,$.browser.name,$.browser.className,$.layout.name,$.layout.className].join(' '));}};$.browserTest(navigator.userAgent,true);})(jQuery);

function imageResize(containerID) {
	$(containerID).each(function(){    	
		var photoImageSrc=$(this).attr("src");
		var photoImageSrcNew="";
		if(null!=photoImageSrc){			
			/* for Image size modifications -Start*/
			var slashpoint=photoImageSrc.lastIndexOf("/");
			var uspoint=photoImageSrc.lastIndexOf("_");
			var dotpoint=photoImageSrc.lastIndexOf(".");
			var srcLength=photoImageSrc.length;
			var thumbSize="_6";
			var imgPath_1=photoImageSrc.substring(0,slashpoint);
			var imgPath_2=photoImageSrc.substring(slashpoint,uspoint);
			var imgPath_3=photoImageSrc.substring(dotpoint,(srcLength));
			photoImageSrcNew=imgPath_1+imgPath_2+thumbSize+imgPath_3;			
			$(this).attr("src",photoImageSrcNew);
			$(this).attr("width","261");
			$(this).attr("height","162");
			var avatarAncStyle="display:block !important;width:261px !important;height: 162px !important;";
			var avatarImgStyle="display:block !important;width:261px !important;height: 162px !important;cursor:pointer !important;";
			$(this).children("a").attr("style",avatarAncStyle);		
			$(this).attr("style",avatarImgStyle);							
	}
	});
}


/*This is no longer used:Instead have used global redirects 
	if(location.href.match("/album/$") == "/album/") {
		window.location = location.href.substring(0, location.href.indexOf("/album/")) + "/album/ready/"
	}
	if(location.href.match("/music/$") == "/music/" ) {
		window.location = location.href.substring(0, location.href.indexOf("/music/")) + "/album/ready/"		
	}	
*/

var privacyPolicyText   = 'By registering, I acknowledge that I have reviewed and agreed to the '+ '<a target="_new" href="/privacy/" rel="external">Privacy Policy</a> and <a target="_new" href="/termsofuse/" rel="external">Terms of Service</a>' + ', and  I agree to receive marketing messages from Atlantic Records, its affiliates and Trey Songz with the latest news, updates and information about Trey Songz';

/* RTSU Start */
    var arrElementIDs = new Array();
    arrElementIDs["cmsgData[IdList][903][Male]"] = "sex";
    arrElementIDs["cmsgData[IdList][903][Female]"] = "sex";
    arrElementIDs["cmsgData[IdList][902]"] = "postalcode";
    arrElementIDs["cmsgData[IdList][901]"] = "country";
    arrElementIDs["cmsgData[email]"] = "email"; 
/* RTSU End */


/*Templates for the Merch Module */
var merchModuleTemplate = 
		'<li class="merch small item{index}">\
				<div class="merchImg"><a href="{omnitureLinksPThumb}"><img src="{merchImage}"/></a><div class="merchZoomIcon"></div></div>\
				<div class="merchDetail">\
					<div class="merchPriceWrapper"><div class="merchName"><a href="{omnitureLinksPTitle}" >{merchTitle}</a></div><div class="merchPrice">{merchPrice}</div></div>\
					<div class="merchBuy"><a href="{omnitureLinksPButton}" class="merchBuyLink">Buy Now</a></div>\
				</div>\
				<!-- HOVERCARD -->\
		</li>';

/* Templates for the Hovercard module.*/
var	merchHCTemplate ='<div class="merchHC merchHC{index}">\
							<div class="merchHCWrapper">\
								<div class="merchHCInnerWrapper">\
									<div class="merchHCHead"><a href="{omnitureLinksHTitle}">{merchTitle}</a></div>\
									<div class="merchHCBody">\
										<div class="merchHCLeftCon"><a href="{omnitureLinksHThumb}"><img src="{merchImage}" width="230px"/></a></div>\
										<div class="merchHCRightCon">\
											<h3 class="merchHCPrice">{merchPrice}</h3>\
											{merchDesc}\
											{merchSizes}\
											<div class="merchHCBuyNowCon"><a class="merchHCBuyNow" href="{omnitureLinksHButton}">Buy Now &raquo;</a></div>\
										</div>\
										<div class="clear"></div>\
									</div>\
									<div class="merchHCFoot"></div>\
								</div>\
							</div>\
						</div>';
			
var merchCountryTemplate = '<li><a class="flag {countryName}" href="{countryLink}" target="_new">{countryText}</a></li>';
var merchHeaderTemplate = '<div class="{positionClass}">\
						   		<div class="visitStore">\
									<a class="visitStoreLink" href="{merchViewAllLink}" rel="external" target="_new">Visit Artist Store</a>\
									<ul style="display: none;" class="visitStoreFlyout">\
										<!-- MERCH COUNTRIES -->\
									</ul>\
								</div>\
						   </div>';


$(document).ready(function(){
	
	/*
$(".comments").each(function(){
		
		 $(this).wrap("<div class='commentIeWrap'></div>");
	});
	
*/
	
	imageResize("#video_thumbnail-399818.video_thumbnail .videos li .img a img");
	
	
	
	$("#member_listing-408226 .members li.member .avatar .img a img").each(function(){  
		var photoImageSrc=$(this).attr("src");
		var photoImageSrcNew="";
		if(null!=photoImageSrc){
			var slashpoint=photoImageSrc.lastIndexOf("/");
			var uspoint=photoImageSrc.lastIndexOf("_");
			var dotpoint=photoImageSrc.lastIndexOf(".");
			var srcLength=photoImageSrc.length;
			var thumbSize="_6";
			var imgPath_1=photoImageSrc.substring(0,slashpoint);
			var imgPath_2=photoImageSrc.substring(slashpoint,uspoint);
			var imgPath_3=photoImageSrc.substring(dotpoint,(srcLength));
			photoImageSrcNew=imgPath_1+imgPath_2+thumbSize+imgPath_3;
			$(this).attr("src",photoImageSrcNew);
			$(this).attr("width","294");
			$(this).attr("height","294");
			var avatarAncStyle="display:block !important;width:294px !important;height: 294px !important;";
			var avatarImgStyle="display:block !important;width:294px !important;height: 294px !important;cursor:pointer !important;";
			$(this).parent().attr("style",avatarAncStyle);
			$(this).attr("style",avatarImgStyle);
			var avatarDivStyle="background:transparent url("+photoImageSrcNew+") no-repeat 0px 0px;width:294px;height:294px;";
			$(this).parent().parent().attr("style",avatarDivStyle);
			$(this).parent().parent().css('background','none');
	}
	
	});
	
	$("#photo_thumbnail-399817.photo_thumbnail .photos  li .img a img").each(function(){    	
		var photoImageSrc=$(this).attr("src");
		var photoImageSrcNew="";
		if(null!=photoImageSrc){			
			/* for Image size modifications -Start*/
			var slashpoint=photoImageSrc.lastIndexOf("/");
			var uspoint=photoImageSrc.lastIndexOf("_");
			var dotpoint=photoImageSrc.lastIndexOf(".");
			var srcLength=photoImageSrc.length;
			var thumbSize="_6";
			var imgPath_1=photoImageSrc.substring(0,slashpoint);
			var imgPath_2=photoImageSrc.substring(slashpoint,uspoint);
			var imgPath_3=photoImageSrc.substring(dotpoint,(srcLength));
			photoImageSrcNew=imgPath_1+imgPath_2+thumbSize+imgPath_3;			
			$(this).attr("src",photoImageSrcNew);
			$(this).attr("width","171");
			$(this).attr("height","162");
			var avatarAncStyle="display:block !important;width:171px !important;height: 162px !important;";
			var avatarImgStyle="display:block !important;width:171px !important;height: 162px !important;cursor:pointer !important;";
			$(this).children("a").attr("style",avatarAncStyle);		
			$(this).attr("style",avatarImgStyle);
	
								
	}
	});



	
/*START - Fix for truncating author name in the discussions page */

var discussionAuthorLen = "17";

			$('.discussion_listing .topics li .author a').each(function(){
				var trunc = (this).innerHTML;	
				if (trunc.length > discussionAuthorLen) {
					trunc = trunc.substring(0, discussionAuthorLen);
					trunc += '<span>' + '...</span>';
					(this).innerHTML = trunc;
				}	
			})		

/*END - Fix for truncating author name in the discussions page */


	
	/* Setting the browser name and classname in the top */
	$("html").addClass($.os.name);
	$("body").addClass($.browser.className);
	
	ord=Math.random()*10000000000000000;
	
	/*post a new blog fic replacing more with new */
		var $blogFootFix = $('.blog_listing .nav_meta .more a');
 $blogFootFix.filter(function(){
 return (/^Post/i).test($(this).text())
 }).parent()
 .removeClass('more')
 .addClass('new'); 
 /*end of post new blog fix*/

/*post a new blog fix replacing more with new for new blog */
		var $newblogReadMoreFix = $('#blog_listing-350371.blog_listing .articles li .description a');
 $newblogReadMoreFix.filter(function(){
 return (/^Read/i).test($(this).text())
 }).addClass('readmore'); 
 /*end of post new blog fix*/
	
	
/* for Required and Administrative icons - Starts */
	
	var prvteCont="<i class='prText'>&nbsp;&nbsp;</i>";
	
	$('#join-350410.join .annotation span.private').each(function(){
		var cont = (this).innerHTML;		
		(this).innerHTML= prvteCont+cont;
	});
	
	$('li.input.private').each(function(){
			var liCont = (this).innerHTML;		
			(this).innerHTML= liCont+prvteCont;
	});
	
	/* for Required and Administrative icons - Ends */
	
		/* Suppresses display of empty footers on IE */
	$('.module .foot:empty').addClass('empty');
	$('#html-400006 .module .foot').removeClass('empty');
	
	/* START Add "Launch Player" links to footer nav of all audio playlist modules */
	var launchLink =  $('<li class="launchPlayer"><a href="/music-player/" class="launchPlayerLink">Launch Player</a></li>');
	
	$(".song_playlist .module .content .nav_meta ul").prepend(launchLink);
	
	
	
	/* END Add "Launch Player" links to footer nav of all audio playlist modules */
	
	/* add popup onClick handler for audio player links */
	$("a.launchPlayerLink").click(function() {
			window.open("/music-player/", "Window2", "width=375,height=275,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no"); 
			return false;
	});
	
	/* Make store top nav link open in a new window */
	$('.nav_main ul li.custom a[href*=store.atlanticrecords.com]').attr("rel", "external");
		
	//display number of fans on member and community landing page.
	fanNumber = $("#member .module .content .head .title .total");
	$("#member #member_listing-572799.member_listing .module .content .head").append(fanNumber);
	
	fanNumber = $("#community_landing #member_listing-572650.member_listing .module .content .head .title .total");
	$("#community_landing #member_listing-572650.member_listing .module .content .head").append(fanNumber);


	/* 
	 *This is no longer used:Instead have used global redirects 
	 *Replace links to "Music" to links to latest album. NOTE: this will need to be reworked whenever a new album is released 
	$("a[href$=music/]").attr("href", "/album/ready/");
	
	/* Code for replacing all instances of album landing page link with album detail page link 
	$("a[href$=album/]").attr("href", "/album/ready/");*/

	
	
	/*BP3 Category */
	$("#bp3tour #photo_thumbnail-1334628 .content .foot .nav_meta ul li.more a").attr("href", "/photo/category/bp3-tour/");
	$("#bp3tour #photo_thumbnail-1334142 .module .content .foot .nav_meta ul li.more a").attr("href", "/photo/category/fans/");
	$("#bp3tour #video_thumbnail-1334143 .module .content .foot .nav_meta ul li.more a ").attr("href", "/video/category/bp3-tour/");
	/* START: Community drop-down for top nav */
	
	var communityNavCell = $(".nav_main ul li.nav-community_landing");   //change this selector to target a diffent cell in the top nav
	communityNavCell.addClass('dropdown');
	communityNavCell.append(communitySubNav);
	/* END: Community drop-down for top nav */
	
	
	
		/* START: Tours drop-down for top nav */
		
		var tourNavCell = $('.nav_main ul li.nav-tour_dates');   //change this selector to target a different cell in the top nav
		tourNavCell.addClass('dropdown');
		tourNavCell.append(tourSubNav);
	/* END: Tours drop-down for top nav */	
	
	
	/* START: Custom drop-downs for top nav */
	var $customNavs = $('.nav_main ul li.nav-custom a');
  
	  $customNavs.filter(function(){
	  return (/^Music/i).test($(this).text())
	}).parent()
  	  .addClass('nav-custom')
	  .addClass('nav-music');
	  
	  $customNavs.filter(function(){
	  return (/^Trey's Angels/i).test($(this).text())
	}).parent()
  	  .addClass('nav-custom')
	  .addClass('nav-angel');
	
	  
	 $customNavs.filter(function(){
		  return (/^Store$/i).test($(this).text())
		}).parent()
    	  .addClass('nav-custom')
		  .addClass('dropdown')
		  .addClass('nav-store')
		  .append(storeSubNav);	

	
	$(".nav_main ul li.upload a").text("Upload");
	
	/* Removing the upload from the top, and adding at the bottom; */
	uploadDiv = $(".nav_main ul li.upload");
	$(".nav_main div > ul").append(uploadDiv);
	$(".nav_main ul li.upload").css("display","block");
	
	if (location.href.indexOf("/upload/") != -1) {
			$("li.upload").addClass("active");
		}
		
	/*Hover event handler for all drop-downs in top nav */
	$(".dropdown").hover(
			function() { $(".flyoutMenu", this).show(); },
			function() { $(".flyoutMenu", this).hide(); }
	);
	
	/* Flag subnav pages in parent top nav li */
	if (location.href.indexOf("/member/") != -1) {
    if(!(location.href.indexOf("/category/member/") != -1)){ 
         communityNavCell.addClass("active");
         $("#memberNav").addClass("active");
     }  
     }
	if (location.href.indexOf("/talk/") != -1) {
			communityNavCell.addClass("active");
			$("#discussionsNav").addClass("active");
		}
	if (location.href.indexOf("/ringtones/") != -1) {
		storeNavCell.addClass("active");
		$("#ringtonesNav").addClass("active");
		}
	if (location.href.indexOf("/extras/") != -1) {
			communityNavCell.addClass("active");
			$("#extrasNav").addClass("active");
		}
	
	if (location.href.indexOf("/extras/") != -1) {
			communityNavCell.addClass("active");
			$("extrasNav").addClass("active");
		}
	
	
	
	if (location.href.indexOf("/take-a-tour/") != -1) {	
		$(".nav_main .community_landing").addClass("active");
	}
	
	if (location.href.indexOf("/album/") != -1) {
        $("a[href^=/album/]").parent(".nav-custom").addClass("active");
        
    }
    
    if (location.href.indexOf("/music/") != -1) {
        $("a[href^=/album/]").parent(".nav-custom").addClass("active");
    }	

	/* START: Merch module drop-downs */
	$(".ArtistStore").hover (
			function() { $(".flyoutMenu", this).show(); },
			function() { $(".flyoutMenu", this).hide(); }
		);
			
	$(".mainAlbumBuyDrop").hover (
		function() { $("#subMainAlbumBuy", this).show(); },
		function() { $("#subMainAlbumBuy", this).hide(); }		
	);

	$(".productLeftBuyDrop").hover (
		function() { $("#subLeftAlbumBuy", this).show(); },
		function() { $("#subLeftAlbumBuy", this).hide(); }		
	);

	$(".productCenterBuyDrop").hover (
		function() { $("#subCenterAlbumBuy", this).show(); },
		function() { $("#subCenterAlbumBuy", this).hide(); }		
	);
	
	$(".productRightBuyDrop").hover (
		function() { $("#subRightAlbumBuy", this).show(); },
		function() { $("#subRightAlbumBuy", this).hide(); }		
	);

	$(".ArtistStoreBottom").hover (
		function() { $(".flyoutMenuFooter", this).show(); },
		function() { $(".flyoutMenuFooter", this).hide(); }		
	);
	/* END: Merch module drop-downs */	
	
	
	/* Replace EOS default privacy policy and terms of use with Atlantic Records links */
		$('[href=/privacy-policy/]').attr("href", "http://www.atlanticrecords.com/privacy/eos").attr("rel", "external");
	$('[href=/terms-of-use/]').attr("href", "http://www.atlanticrecords.com/termsofuse/eos").attr("rel", "external");

	/* Make rel="external" links open in a new window */
	$("a[rel=external]").attr("target", "_new");
	/* Fixing the target for the digg link */
	$(".shareweb .digg a").attr("target", "_new");
	
	/* Setting the width of the nav bar*/
	$("#nav_global").css({width : '993px'});
	$("#nav_global").children("ul").css({width : '983px'});
	
	/* Append labels to elements in discussion module */
	$(".topics li.list .category li:first-child").prepend("Category: ");
	$(".topics li.list .activity").prepend("Replies: ");
	$(".topics li.list .date").prepend("Last Reply: ");
	
	/* Add "Close" text to close link in social media sharebox on photo and video detail pages */
	$(".sharebox .sb_head .sb_title a.shareclose").prepend("Close");
	
	/* Regarding SIFR removal in Upload page */
/*
	$('#upload .module .content .head h3').addClass('removeSifr');
	$('#upload .module .content .body h3').addClass('removeSifr');
	$('#upload .module .content .body h4').addClass('removeSifr');
*/
	
	/* Home page album links changing the title */
	$("#moduleForm382837 ul.albums li:last-child").addClass("albumsLastChild");
		
		

	
		function setSlideState(){
			if (carosActiveCurrent == 0) {
				$("#html-382836.html .content").addClass('slide1');
				$("#html-382836.html .content").removeClass('slide2');
				$("#html-382836.html .content").removeClass('slide3');
			}else if(carosActiveCurrent == 1){
				$("#html-382836.html .content").addClass('slide2');
				$("#html-382836.html .content").removeClass('slide1');
				$("#html-382836.html .content").removeClass('slide3');
			}else if(carosActiveCurrent == 2){
				$("#html-382836.html .content").addClass('slide3');
				$("#html-382836.html .content").removeClass('slide2');
				$("#html-382836.html .content").removeClass('slide1');
			}
		}
		
	var noOfImageDscDtl=$("#discussion_entry-350389 .topic .description img").length;
		for(i=0;i<noOfImageDscDtl;i++){
			var discussionImageElement = $("#discussion_entry-350389 .topic .description img:eq(" +i+ ")");
			var imgHeight=discussionImageElement.height();
			var imgWidth=discussionImageElement.width();
			if(imgHeight>200 && imgWidth>200){		
				var calcheight = (imgHeight/imgWidth)*200;		
				discussionImageElement.css("height",calcheight);	
				discussionImageElement.css("width",200);	
			}
		}
	
	var noOfImageDscDtl=$("#discussion_listing-399821 .topic .description img").length;
		for(i=0;i<noOfImageDscDtl;i++){
			var discussionImageElement = $("#discussion_listing-399821 .topic .description img:eq(" +i+ ")");
			var imgHeight=discussionImageElement.height();
			var imgWidth=discussionImageElement.width();
			if(imgHeight>200 && imgWidth>200){		
				var calcheight = (imgHeight/imgWidth)*200;		
				discussionImageElement.css("height",calcheight);	
				discussionImageElement.css("width",200);	
			}
		}
		
		//Modifying the legal text in the log in and sign up pages.
	$("body#sign_up #cmsgData\\[agreeToTerms\\]").next().html(privacyPolicyText + "").show();
	$("body#join #cmsgData\\[agreeToTerms\\]").next().html(privacyPolicyText + "").show();
	
	/*START- code which obfuscates email addresses #2420*/	
		var m_ = "mailto:";
		var a_ = "@";
		var d_ = ".";
		var i = 0;
		var j  = 0;
		var q_ = "?";
		var e_ = "=";
		
		$('span.ciReplace').each(function(){	
			if(cId[i].format == ""){
				$(this).html('<a href="'+m_+cId[i].name+a_+cId[i].domain+d_+cId[i].tld+'">'+ cId[i].name + a_+ cId[i].domain + d_+ cId[i].tld +'</a>');
			}
			else{
				if(cId[i].param == ""){
					$(this).html('<a href="'+m_+cId[i].name+a_+cId[i].domain+d_+cId[i].tld+'">'+ cId[i].format+'</a>');
				}
				else{
					$(this).html('<a href="'+m_+cId[i].name+a_+cId[i].domain+d_+cId[i].tld+q_+'subject'+e_+cId[i].param+'">'+cId[i].format+'</a>');
				}
			}
		i++;				
		});
		
		
		$('span.footReplace').each(function(){
					if(fId[j].format == ""){
				$(this).html('<a href="'+m_+fId[j].name+a_+fId[j].domain+d_+fId[j].tld+'">'+ fId[j].name + a_+ fId[j].domain + d_+ fId[j].tld +'</a>');
			}
			else{
				if(fId[j].param == ""){
					$(this).html('<a href="'+m_+fId[j].name+a_+fId[j].domain+d_+fId[j].tld+'">'+ fId[j].format+'</a>');
				}
				else{
					$(this).html('<a href="'+m_+fId[j].name+a_+fId[j].domain+d_+fId[j].tld+q_+'subject'+e_+fId[j].param+'">'+fId[j].format+'</a>');
				}
			}
			j++;		
		});	
		
	/*End - code which obfuscates email addresses #2420*/
		
	/* SP to Eos Use Plugin Configuration set the parametres as per the modulecontainer */
	$.wmgfeature.spFeatureJoin("#join .input .button.submit input", "join-350410", false, arrElementIDs, "http://www.treysongz.com/", "18116");
	$.wmgfeature.spFeatureEditProfile(".edit_profile .input .button.submit input", "edit_profile-350396", true, arrElementIDs, "http://www.treysongz.com/", "18116");
	$.wmgfeature.spFeatureEditAccountAccData(".edit_account #accountData .buttons.input .button.submit input.submit", "edit_account-350394", true, arrElementIDs, "http://www.treysongz.com/", "18116");
	$.wmgfeature.spFeatureEditAccountAccQuestions(".edit_account #accountQuestoins .buttons.input .button.submit input.submit", "edit_account-350394", true, arrElementIDs, "http://www.treysongz.com/", "18116");
	/* End SP Migration Changes */

});

function eoscInit(){
	
	
	/* --------------------- For US Tour ----------------------------- */
	
	var USCommunity = $('#ustour #html-373085.html .module .body').css('display'); 
if (USCommunity  == "none"){
$('#ustour #html-373085.html .module').css('display','none');
}
	/* --------------------- For US Tour ----------------------------- */
	
		/* --------------------- For Member detail ----------------------------- */
	
	var photoMem = $('#member_detail .photo_thumbnail .module .content .body ul').length 
if (photoMem == 0 ){
$('#member_detail .photo_thumbnail .module .content .body').css('padding','0');
}
		/* --------------------- For Member detail----------------------------- */

	
    /*$.each($('.activity .comment'), function(index, value) {
    //var newCommentNumber = $('.activity .comment').eq(index).html().replace("Comments (", "").replace(")", "");
	 var newCommentNumber;
     newCommentNumber = $('.activity .comment').eq(index).html().replace("Comments (", "").replace(")", "");
     newCommentNumber = newCommentNumber.replace("Comment (", "").replace(")", "");
     $('.activity .comment').eq(index).html(newCommentNumber); 
    });*/

	
	/* --------------------- End For comments ------------------------- */

	
	 //Modifying the legal text in the log in and sign up pages.
    $("body#sign_up #cmsgData\\[agreeToTerms\\]").next().html(privacyPolicyText + "").show();
    $("body#join #cmsgData\\[agreeToTerms\\]").next().html(privacyPolicyText + "").show(); 
	
	var photoImageSrc=$("#photo_thumbnail-1334628.photo_thumbnail .photos li:first-child a img").attr("src");
	var photoImageSrcNew="";
	if (null != photoImageSrc) {
		var slashpoint = photoImageSrc.lastIndexOf("/");
		var uspoint = photoImageSrc.lastIndexOf("_");
		var dotpoint = photoImageSrc.lastIndexOf(".");
		var srcLength = photoImageSrc.length;
		var thumbSize = "_8";
		var imgPath_1 = photoImageSrc.substring(0, slashpoint);
		var imgPath_2 = photoImageSrc.substring(slashpoint, uspoint);
		var imgPath_3 = photoImageSrc.substring(dotpoint, (srcLength));
		photoImageSrcNew = imgPath_1 + imgPath_2 + thumbSize + imgPath_3;
		$("#photo_thumbnail-1334628.photo_thumbnail .photos li:first-child a img").attr("src", photoImageSrcNew);
		var avatarDivStyle = "background:transparent url(" + photoImageSrcNew + ") no-repeat 0px 0px";
		$("#photo_thumbnail-1334628.photo_thumbnail .photos li:first-child div.img").attr("style", avatarDivStyle);
	}
	
	
	
	
}

// on click of Iggli button, populateInviteData function gets called

function populateInviteData(iTitle,iLocation,iDate) {

	//all the possible fields in this json object
	json = {		
	widget_version:"2.0",
	widget_skin:"button_square_small",
	partner_id:"137", 			//Do not change this id. This is unique
	title:iTitle,
	location:iLocation,
	date:iDate
	}
	var inviteButtons;

	//replace any current invite data using the json object
	    inviteButtons[0].setOptions(json);

	//refresh the html to reflect new data
	   	inviteButtons[0].refresh();
			
	// launch the invite
	   loadInviteInModal(0);
}

/* Functions for New Merch.*/

	/*
	 * This function is used to tag store links with different omniture tags, 
	 * to track them. This will enable us to track which links the user clicked. 
	 * 
	 * */
	function getMerchOmnitureArray(omnitureString){
		var omnitureArrayLinks = new Array();
		var omnitureStrRegex = /intcmp=(.*)(&.*|\/)$/;
		omnitureString = $.trim(omnitureString);
		if (omnitureString.charAt(omnitureString.length-1) != "/" ){omnitureString += "/";}
		writeToConsole ("This is the omnitureString " + omnitureString);
		regExCapture = omnitureString.match(omnitureStrRegex);
		//A JSON object could be used and a fuction to populate that could be used. 
		if (regExCapture != null && regExCapture != ""){
			var regularExpCapture = regExCapture[1]; 
			omnitureString = omnitureString.replace(/\/$/,'');
			omnitureArrayLinks["page-title"] = omnitureString.replace(regularExpCapture,regularExpCapture+'-page-title');
			omnitureArrayLinks["page-button"] = omnitureString.replace(regularExpCapture,regularExpCapture+'-page-button');
			omnitureArrayLinks["page-thumb"] = omnitureString.replace(regularExpCapture,regularExpCapture+'-page-thumb');
			omnitureArrayLinks["hovercard-title"] = omnitureString.replace(regularExpCapture,regularExpCapture+'-hovercard-title');
			omnitureArrayLinks["hovercard-thumb"] = omnitureString.replace(regularExpCapture,regularExpCapture+'-hovercard-thumb');
			omnitureArrayLinks["hovercard-button"] = omnitureString.replace(regularExpCapture,regularExpCapture+'-hovercard-button');
		}else{
			omnitureArrayLinks["page-title"] = omnitureString.replace(/\/$/,'?intcmp=page-title');
			omnitureArrayLinks["page-button"] = omnitureString.replace(/\/$/,'?intcmp=page-button');
			omnitureArrayLinks["page-thumb"] = omnitureString.replace(/\/$/,'?intcmp=page-thumb');
			omnitureArrayLinks["hovercard-title"] = omnitureString.replace(/\/$/,'?intcmp=hovercard-title');
			omnitureArrayLinks["hovercard-thumb"] = omnitureString.replace(/\/$/,'?intcmp=hovercard-thumb');
			omnitureArrayLinks["hovercard-button"] = omnitureString.replace(/\/$/,'?intcmp=hovercard-button');
		}				 
		return omnitureArrayLinks;
	}
	
	/*
	 * Function to add the hovercard to the template,
	 * if set in the config xml.
	 * 
	 * */
	function prepareMerchTemplate (merchHoverCardPresent){
		if (merchHoverCardPresent){
			merchModuleTemplate = merchModuleTemplate.replace("<!-- HOVERCARD -->",merchHCTemplate);
		}else{
			merchModuleTemplate = merchModuleTemplate.replace("<!-- HOVERCARD -->","");
		}
		
	}
	
	function getMerchHeader ($merchCountries,merchViewAllLink,positionClass){
		var merchHeaderString = "";
		var merchCountryString = "";
		var countryParams;
		var merchParams = {
							merchViewAllLink : merchViewAllLink,
							positionClass : positionClass};
			$merchCountries.each (function(){

				countryParams = {
					countryName : $(this).children(".countryName").html(),
					countryLink : $(this).children(".countryLink").html(),
					countryText : $(this).children(".countryText").html()
				};
				merchCountryString += merchCountryTemplate.supplant(countryParams);
				
			})

			merchViewAllLink ="javscript:void(0)"; 	
		
		merchHeaderString = merchHeaderTemplate.supplant(merchParams);
		merchHeaderString = merchHeaderString.replace("<!-- MERCH COUNTRIES -->",merchCountryString);
		return merchHeaderString;
	}
	
	/*
	 * This function generates the structure of the merch module. 
	 * The structure is created using templates defined earlier in the page.  
	 */ 
	function generateMerchStructure (){
		var $merchData = $("#merchData");
		if($merchData.length == 0){
			return;
		}
		var $merchItem = $merchData.children(".merchItems")
		var merchViewAllLink = $merchData.children(".merchViewAll").html();
		var merchHoverCardPresent = $merchData.children(".merchHoverCardPresent").html().trim();
		merchHoverCardPresent = !!merchHoverCardPresent;
		prepareMerchTemplate (merchHoverCardPresent);
		
		/* Code for the Merch Head */
		var merchHead = '<div class="merchHead"><div class="visitStore"><a href="'+ merchViewAllLink +'" class="visitStoreLink"  >ALL</a></div></div>'
		merchHead = getMerchHeader($("#merchInternational .country"),merchViewAllLink,"merchHead");
		var visitStorehead = $('#merchContainer').parent(".description").parent(".body").siblings(".head");
	        $(merchHead).appendTo(visitStorehead);
		$(visitStorehead).find("a").makeLinksExternal();
		/* End of Code for Merch Module */
		
		var merchBody='<ul class="merchItems">';
		$.each($merchItem.children(".merchItem"), function (i){
			var merchBuyNow = $(this).children(".merchBuyNow").html(); 			
			var omnitureLinks = getMerchOmnitureArray(merchBuyNow);
			var merchSizes = $(this).children(".merchSizes").html();
			if (merchSizes !="" && merchSizes !=null){merchSizes = '<h3>Sizes</h3><div>'+merchSizes+'</div>';}
			var merchDesc = $(this).children(".merchDesc").html();
			if (merchDesc != "" && merchDesc != null){merchDesc = '<h3>Description</h3><div>'+ merchDesc +'</div>';}
			var merchParsedData = {
				             index:(i+1),
							 merchImage:$(this).children(".merchImage").html(),
							 merchTitle:$(this).children(".merchTitle").html(),
							 merchDesc:merchDesc,
							 merchSizes:merchSizes,
							 merchPrice:$(this).children(".merchPrice").html(),
							 omnitureLinksPTitle:omnitureLinks["page-title"],
							 omnitureLinksPThumb:omnitureLinks["page-thumb"],
							 omnitureLinksPButton:omnitureLinks["page-button"],
							 omnitureLinksHTitle:omnitureLinks["hovercard-title"],
							 omnitureLinksHThumb:omnitureLinks["hovercard-thumb"],
							 omnitureLinksHButton:omnitureLinks["hovercard-button"]
							 }
			merchBody = merchBody + merchModuleTemplate.supplant(merchParsedData);
		});
		merchBody += '</ul><div class="clear"></div>';
	
		var merchFoot = '<div class="clear"></div><div class="merchFoot"><div class="visitStore"><a href="'+ merchViewAllLink +'" class="visitStoreLink" >View ALL</a></div></div>';
		merchFoot = '<div class="clear"></div>';
		merchFoot += getMerchHeader($("#merchInternational .country"),merchViewAllLink,"merchFoot");
		var visitStoreFoot = $('#merchContainer').parent(".description").parent(".body").siblings(".foot");
	        $(merchFoot).appendTo(visitStoreFoot);
		$(visitStoreFoot).find("a").makeLinksExternal();

		return merchBody;
	}
	
	
	
	/*These functions are used by the merch HC so that casual hovers less than 300 seconds
	 * are omitted. 
	 */
	function bringMerchHCOn(merchImg){
		merchImg.showTimer = window.setTimeout(function(){
			$(merchImg).siblings(".merchHC").fadeIn(300);
		},300);
	}
	function killMerchHC(merchImg){
		if (merchImg.showTimer){
			window.clearTimeout(merchImg.showTimer);
		}
	}
	
	/* Registereing the hover events */
	function registerMerchHoverEvents(){
		$(".merchImg").hover(function(){
			bringMerchHCOn(this);
		},function(){
			killMerchHC(this);
		});
		$(".merchHC").hover(function(){
		},function(){
			$(this).fadeOut(300);
		});
		
		$(".visitStore").hover (
			function() { $(".visitStoreFlyout", this).show(); },
			function() { $(".visitStoreFlyout", this).hide(); }
		);
	}
	
	/* The piece of code which generates the merch, adds the dom and registers the events. */
	
	$(document).ready(function(){
		$("#merchContainer").html(generateMerchStructure());
		$("#merchData").empty();
		$("#merchContainer a").makeLinksExternal();
		registerMerchHoverEvents();
	});
    /* End of Functions for New Merch */

