/* 
 * 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);

var privacyPolicyText   = 'By submitting my information above, I acknowledge that I have reviewed and agreed to the <a target="_new" href="/privacy-policy/" rel="external">Privacy Policy</a> and <a target="_new" href="/terms-of-use/" rel="external">Terms of Use</a>, and I agree to receive updates and marketing messages from time to time from Trey Songz, and his record label.';


/* 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>\
								</div>\
						   </div>';

var strBlog;
var strDiscussion;
var contentTitle;


$(document).ready(function(){
	
	$('.blog_listing .articles li.article').each(function(){
        $(this).find('.description a').each(function(){
            if ($(this).text() == "Read more") {
                $(this).addClass("read_more");
            }
        });
    });
	
	$('#video #overallCenterWrapper').addClass('grid_9_2');
	$('#photo #overallCenterWrapper').addClass('grid_9_2');

	
	/* duplication issue fix */
	$('#home .blog_listing .module .body .article').each(function(){
		var blogauthor=$(this).find('.author a').html();
		var blogposteddate=$(this).find('.date').html();
		var memberlink=$(this).find('.author a').attr("href");

		if($(this).hasClass('category_36491')){
			
			$(this).addClass("fanClub");
			$(this).find('.title').prepend("<a class='learnmore' " + "href = '/become-a-member/'></a>");				
			$(this).find('.title').prepend("<a class='treyangelsbloghead' " + "href = '/become-a-member/'>Treyangels</a>");	
			
			blogposteddate=blogposteddate.split('at');
			blogposteddate=blogposteddate[0];
		}
		
		if ($(this).find('.post_details').length == 0) {
			$(this).find('.title').append('<div class="post_details">Posted ' + blogposteddate + 'by <a href="' + memberlink + '">' + blogauthor + '</a></div>');
		}
		$(this).find('.gPlus').insertAfter($(this).find('.fb_like'));		
	});
	
	if (($('body').attr('id') == "home")) {	
		$('.articles li.article').each(function(){
			var tumblr_link_url = "http://www.treysongz.com" + $(this).find(".title h4 a").attr("href") + "?cmpid=treysongz/tumblr/share-on-tumblr/blog-detail/";
			var tumblr_link_name = $(this).find('.title h4').text();
			var tumblr_link_description = $(this).find('.description').clone();
tumblr_link_description.find('a.read_more').remove();
tumblr_link_description = $(tumblr_link_description).html();
			
			var plusone_link_url = "http://www.treysongz.com" + $(this).find(".title a").attr("href") + "?cmpid=treysongz/tumblr/share-on-tumblr/blog-detail/";
			var plusone = document.createElement("g:plusone");
			plusone.setAttribute("href", plusone_link_url);
			plusone.setAttribute("size", "medium");
			$(this).append('<div class="gPlus"></div>');
			$(this).append('<span id="tumblr_button_abc123"></span>');
			$(this).find('.gPlus').append(plusone);
			
			var tumblr_button = document.createElement("a");
			tumblr_button.setAttribute("href", "http://www.tumblr.com/share/link?url=" + encodeURIComponent(tumblr_link_url) + "&name=" + encodeURIComponent(tumblr_link_name) + "&description=" + encodeURIComponent(tumblr_link_description));
			tumblr_button.setAttribute("title", "Share on Tumblr");
			tumblr_button.setAttribute("style", "display:inline-block; text-indent:-9999px; overflow:hidden; width:63px; height:20px; background:url('http://platform.tumblr.com/v1/share_2.png') top left no-repeat transparent;");
			tumblr_button.setAttribute("target", "_blank");
			tumblr_button.innerHTML = "Share on Tumblr";
			$(this).find('#tumblr_button_abc123').append(tumblr_button);
		});
	}
	
	/*adding class to playlist buy anchor link */
	var buyanchor = $(".playlist .list ul li .buy a");
	buyanchor.each(function(){
                $(this).addClass($(this).text());
	});
	
	if($('body').hasClass('angelsphotocategories')){
		$('html').css('background','url("http://static.global.ciscoeos.com/1316411485/zipupload/693/f65/8b19768857266d504b41edf785/images/fc_photos_top.jpg") no-repeat scroll center top #081113');
	}
	
	var rating  = $('#album_info-390840 div.album .rating');
var playlist = $('#song_playlist-390843 .playlist .info .txt');
rating.insertAfter(playlist);  

	/*album title as module title*/
	$('#album_info-390840.album_info .module .head h3').html($('.module .content .body div.album h4').text());
	
	/*fix to remove paranthesis for duration in fanclub landing videos module*/
	var duration = $('.grid_5 .videos li .txt .duration');
	duration.each(function(){
		$(this).text($(this).text().replace('(', ''));
		$(this).text($(this).text().replace(')', ''));
	});
	
	/* Fix - To remove the ... in playlist */
	$('#song_playlist-2649571.song_playlist .playlist ul li').each(function(){
		var divBuy = $(this).find('.buy a');
		$(this).find('.buy').html(divBuy);
	});
	
	$("#song_playlist-390843.song_playlist .playlist .list ul li").each(function(){
		var divBuy1 = $(this).find('.buy a');
		$(this).find('.buy').html(divBuy1);
	});
	
	
	/*Add class to Featured Photo module in FC-Photo pages*/
	$('#photoOfWeek').parents('div.html').addClass('angelsFeaturedPhoto');
	
	function modifyMediaSize(cssSelector, thumbSize, avatarAncStyle, avatarImgStyle, isVideo){
		$(cssSelector).each(function(){
			var photoImageSrc = $(this).attr("src");
			var photoImageSrcNew = "";
			var anchorRef = "";
			if (null != photoImageSrc) {
				var slashpoint = photoImageSrc.lastIndexOf("/");
				var uspoint = photoImageSrc.lastIndexOf("_");
				var dotpoint = photoImageSrc.lastIndexOf(".");
				var srcLength = photoImageSrc.length;
				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).parent().attr("style", avatarAncStyle);
				anchorRef = $(this).parent().attr("href");
				$(this).attr("style", avatarImgStyle);
				var avatarDivStyle = "background:transparent url(" + photoImageSrcNew + ") no-repeat 0px 0px;";
				$(this).attr("src", photoImageSrcNew);
				$(this).parent().parent().attr("style", avatarDivStyle);
				if (isVideo) {
					$(this).parent().parent().append("<a class='preplayIcon' " + "href = '" + anchorRef + "'></a>");
				}
				
				
			}
		});
	}
	modifyMediaSize("#group_detail_4476 .content li.member.m .img a img", "_6", "display:block !important;width:100px !important;height: 100px !important;", "display:block !important;width:100px !important;height: 100px !important;cursor:pointer !important;", false);	
	modifyMediaSize("#group_detail_4476 .videos li.category_38129 .img a img", "_6", "display:block !important;width:148px !important;height: 100px !important;", "display:block !important;width:148px !important;height: 100px !important;cursor:pointer !important;", true);
	modifyMediaSize("#group_detail_4476 #photo_thumbnail-2944064.photo_thumbnail .photos li .img a img", "_6", "display:block !important;width:148px !important;height: auto !important;", "display:block !important;width:148px !important;height: auto !important;cursor:pointer !important;", false);
	modifyMediaSize(".fanclubpages #photo_thumbnail-2944064.photo_thumbnail .photos li.s .img a img", "_6", "display:block !important;width:148px !important;height: auto !important;", "display:block !important;width:148px !important;height: auto !important;cursor:pointer !important;", false);
	modifyMediaSize("#photo_thumbnail-5898970.photo_thumbnail .photos li .img a img", "_7", "display:block !important;width:572px !important;height: auto !important;", "display:block !important;width:572px !important;height: auto !important;cursor:pointer !important;", false);
	modifyMediaSize("#video_thumbnail-5898971.video_thumbnail .videos li .img a img", "_7", "display:block !important;width:572px !important;height: auto !important;", "display:block !important;width:572px !important;height: auto !important;cursor:pointer !important;", true);
	
	
	modifyMediaSize(".grid_5 .videos li .img a img", "_6", "display:block !important;width:148px !important;height: 100px !important;", "display:block !important;width:148px !important;height: 100px !important;cursor:pointer !important;", true);

	modifyMediaSize(".angelsphotocategories .grid_5 .photo_thumbnail .photos li .img a .photos li .img a img", "_6", "display:block !important;width:148px !important;height: 100px !important;", "display:block !important;width:148px !important;height: 100px !important;cursor:pointer !important;", false);
	
	modifyMediaSize(".grid_5 .topics li .img a img", "_6", "display:block !important;width:90px !important;height: 74px !important;", "display:block !important;width:90px !important;height: 74px !important;cursor:pointer !important;", false);
	
	//merc
	$('.carouselNavMerch').insertAfter($('#containerWrapper #html-400006.html .module .content .head h3'));
	
	//NewsTicker config
	$(function(){ 
	    $("ul#newsTicker").liScroll(); 
	});	
	
	$('#nav_main-350423.nav_main ul li.nav-tour_dates a').each(function(){
	var tourText=$(this).text();
	if (tourText == "Tour Dates") {
		$(this).attr("href", "/tour-dates/");
	}
	});
	
	//fix for bug-10638
	var buyLinkCell=$('body#event_detail #event-726801 .buyLink');
	if ((buyLinkCell.html())=="null"){
		buyLinkCell.css('display','none');
	}
			
	$("#angel_with_heart.angelsphotocategories .discussion_listing .module .content .foot .nav_meta ul li.more a").text("View all discussions >>");

	$("#angel_with_heart.angelsphotocategories #html-3664868.html .module .content .foot").append('<div class ="upload_story"><a class="upload_btn" href="/angels-with-heart-upload/">UPLOAD YOUR STORY</a></div>'); 

	
	 $("#accountQuestoins.settings li.input.annotation").each(function(){
        if (($(this).find('span.private')).length == 0) {
            $(this).append('<span class="private">Visible only to site administrators</span>');
        }
    });
	
	
	
	$('#nav_global > ul').prepend($('#headerWrapper h2'));
	
	$('a.learnmore').css('display','none');
	$('a.treyangelsbloghead').hover(function(){$(this).next().css("display","block");},function(){$(this).next().css("display","none");});
	$('a.learnmore').hover(function(){$(this).css("display","block");},function(){$(this).css("display","none");});

	
	$(".blog_listing .module .body .description a").has("img").addClass("full");
	
	$('.blog_listing .module .body .article.category_36491').each(function(){
		    $(this).find('.gPlus').insertAfter($(this).find('.fb_like'));
	});
	
	
	$('.blog_listing .module .body .article .title h4 a').each(function(){
		var title_height=$(this).height();
		if(title_height<27){
			$(this).addClass("single_line_title");
			$('.blog_listing .module .body .article .title').addClass("small_ttile_bg");
		}
	});

	var searchNav = '<ul class="flyoutMenu" id="searchNav" style="display:none">\
                	 <li style="display:none" class="sitesearchNav"><a href="javascript:void(0)">TREYSONGZ.COM</a></li>\
                	 <li class="membersNav"><a href="javascript:void(0)">MEMBERS</a></li></ul>';
					 
	var searchDown = $(".googleSearch a.searchDown"); 
	searchDown.addClass('dropdown');
    searchDown.append(searchNav);
	
$(".googleSearch .sitesearchNav").click(function(){
            $('#cse1').css("display", "block");
            $('#cse2').css("display", "none");
            $('.googleSearch .searchHead').css("display", "none");
            $('.googleSearch #search').css("display", "block");
            $('.googleSearch .sitesearchNav').css("display", "none");
            $('.googleSearch .membersNav').css("display", "block");
            $('.googleSearch #search1').css("display", "none");
            var txtBox1 = document.getElementById("cse_txtinput");
            if (txtBox1 != null) 
                txtBox1.focus();
});
$(".googleSearch .membersNav").click(function(){
            $('.googleSearch .sitesearchNav').css("display", "block");
            $('.googleSearch .membersNav').css("display", "none");
            $('.googleSearch #search1').css("display", "block");
            $('.googleSearch #search').css("display", "none");
            $('input.gsc-input').focus();
            $('#cse1').css("display", "none");
            $('#cse2').css("display", "block");
            $('#sitesearchDiv').css("display", "none");
            $('.googleSearch .searchHead').css("display", "none");              
});
		
	/* tour page functionality begins */
	
		
	/* config in event detail page */
	
	var clearDivEle='<div class="clear"></div>';
	var horzDivdr='<div class="hd"></div>';
	var currentPageShowUrl=$.urlParam("show");
  	
if ($('body').attr('id') == 'event_detail') {
	var eventdate = $(this).find('.head h3 .date').text();
	eventdateobj = new Date(eventdate);
	currentDate = new Date();
	offset = eventdateobj.getTime() - currentDate.getTime();
	offsetdays = offset / 86400000
	var maprequesthref = $('.cal_event div.txt .location .maplink a').attr("href");
	
	if (currentPageShowUrl == "archive" || offsetdays < -1) {
		var archiveTitle = "Archive";
		$('#event-726801.event').each(function(){
			$(this).find('.content').addClass('archive');
			$(this).find('.head h3').append(archiveTitle);
			var eventDate = $(this).find('.head h3 .date');
			var goingRnot = $(this).find('.cal_event .going.input');
			var txtDiv = $(this).find('.cal_event div.txt');
			var mapEle = $(this).find('.cal_event div.txt .location .maplink');
			var descEle = $(this).find('.cal_event div.txt .description');
			var stateVal = $(this).find('.cal_event div.txt .location .region').html();
			var buyLnk = "<div class='buyLink'>" + $(this).find('.foot .nav_meta ul li.buy').html() + "</div>";
			var toolsData = "<div class='tools'></div>";
			$(eventDate).insertBefore('#event-726801.event .cal_event div.txt .location');
			$(this).find('.nav_meta ul li.more a').html('Back to Tour Archive');
			$(this).find('.nav_meta ul li.more a').attr("href", "/tour-archive/");
			$(eventDate).insertBefore('#event-711067.event .cal_event div.txt .location');
			
			$(this).find('.cal_event').append(descEle);
			$(this).find('.cal_event').append(clearDivEle);
			$(clearDivEle).insertAfter('#event-711067.event .cal_event div.txt');
			if (maprequesthref != null) {
			
				maprequesthrefarry = maprequesthref.split("?q=");
				var maprequest = "<a href='" + maprequesthref + "' target='_blank'><img src='http://maps.google.com/maps/api/staticmap?center=" + maprequesthrefarry[1] + "&zoom=15&size=300x250&maptype=roadmap&markers=color:red|size:small|" + maprequesthrefarry[1] + "&sensor=false'/></a>";
				$(this).find('.cal_event').append(maprequest);
			}
			
			$(this).find('.cal_event div.txt .location .city').append(stateVal);
			$(this).find('.cal_event').append(clearDivEle);
			$(this).find('.cal_event').append(horzDivdr);
			$(this).find('.cal_event').append(toolsData);
			$(this).find('.cal_event .tools').append(goingRnot);
			$(this).find('.cal_event').append(clearDivEle);
			
			if ($(this).find('.cal_event .tools .input.going a').attr('onclick') != null) {
				$(this).find('.cal_event .tools .input.going .button.submit input').hide();
			}
			var eventsuccessmsg = $("#successMsg").text().toUpperCase();
			if (($(this).find('.cal_event .tools .input.going a').attr('onclick') != null && eventsuccessmsg == "I DIDN'T GO") || ($(this).find('.cal_event .tools .input.going a').attr('onclick') != null && eventsuccessmsg == "I AM NOT GOING")) {
				$(this).find('.cal_event .tools .input.going a').hide();
				$(this).find('.cal_event .tools .input.going .button.submit input').show();
			}
			
			$(this).find('.head h3 .date').remove();
			$(this).find('.head h3 .time').remove();
			$(this).find('.cal_event div.txt .location .maplink').remove();
			
			$(this).find('.cal_event div.txt .location .address').remove();
			$(this).find('.cal_event div.txt .location .country').remove();
			$(this).find('.cal_event div.txt .location .region').remove();
			;
			$(this).find('.cal_event div.txt .title').remove();
			$(this).find('.cal_event div.txt .availability').remove();
			//$(this).find('.foot .nav_meta ul li.buy').remove();
			$(this).find('.cal_event div.txt .description').remove();
		});
		
	}
	else {
		var upcomingTitle = "Upcoming";
		$('#event-726801.event').each(function(){
			$(this).find('.content').addClass('upcoming');
			$(this).find('.head h3').append(upcomingTitle);
			var eventDate = $(this).find('.head h3 .date');
			var goingRnot = $(this).find('.cal_event .going.input');
			var txtDiv = $(this).find('.cal_event div.txt');
			var mapEle = $(this).find('.cal_event div.txt .location .maplink');
			var stateVal = $(this).find('.cal_event div.txt .location .region').html();
			var buyLnk = "<div class='buyLink'>" + $(this).find('.foot .nav_meta ul li.buy ul li').html() + "</div>";
			var toolsData = "<div class='tools'></div>";
			
			$(this).find('.nav_meta ul li.more a').html('Back to upcoming SHOWS');
			$(eventDate).insertBefore('#event-726801.event .cal_event div.txt .location');
			
			$(this).find('.cal_event').append(mapEle);
			$(clearDivEle).insertAfter('#event-726801.event .cal_event div.txt');
			
			writeToConsole(buyLnk+"buyLnkbuyLnkbuyLnk");
			$(eventDate).insertBefore('#event-726801.event .cal_event div.txt .location');
			$(this).find('.cal_event div.txt .location .city').append(stateVal);
			$(this).find('.cal_event div.maplink a').html('VIEW MAP');
			$(this).find('.cal_event').append(clearDivEle);
			$(this).find('.cal_event').append(horzDivdr);
			$(this).find('.cal_event').append(toolsData);
			$(this).find('.cal_event .tools').append(goingRnot);
			$(this).find('.cal_event .tools').append(buyLnk);
			$(this).find('.cal_event').append(clearDivEle);
			
			if ($(this).find('.cal_event .tools .input.going a').attr('onclick') != null) {
				$(this).find('.cal_event .tools .input.going .button.submit input').hide();
			}
			var eventsuccessmsg = $("#successMsg").text();
			if (($(this).find('.cal_event .tools .input.going a').attr('onclick') != null && eventsuccessmsg == "I DIDN'T GO") || ($(this).find('.cal_event .tools .input.going a').attr('onclick') != null && eventsuccessmsg == "I AM NOT GOING")) {
				$(this).find('.cal_event .tools .input.going a').hide();
				$(this).find('.cal_event .tools .input.going .button.submit input').show();
			}
			
			
			$(this).find('.head h3 .date').remove();
			$(this).find('.head h3 .time').remove();
			$(this).find('.cal_event div.txt .location .maplink').remove();
			
			$(this).find('.cal_event div.txt .location .address').remove();
			$(this).find('.cal_event div.txt .location .country').remove();
			$(this).find('.cal_event div.txt .location .region').remove();
			$(this).find('.cal_event div.txt .rating').remove();
			$(this).find('.cal_event div.txt .title').remove();
			//$(this).find('.cal_event .buyLink').remove();
			$(this).find('.cal_event div.txt .availability').remove();
			//$(this).find('.foot .nav_meta ul li.buy').remove();
		});
	}
}
/* confuig enbds */
	
	/*page switching b/w upcomming and past */
	if($('body#event').length >0 || $('body#event_detail').length >0 ){	
		var currentpageshow=$.urlParam("show");
		
		if ($('body').attr('id') == 'event') {
			
				$('#event_listing-3202022 .nav_meta ul li.more a').attr('href', '/tour-archive/');
				
				
		}

		if ($('body').attr('id') == 'event_detail') {
			
			if (currentpageshow == "archive" || offsetdays < -1 ) {					
				$('#event_listing-3202026 .nav_meta ul li.more a').attr('href', '/tour-archive/');
				$('#event_listing-3202026').css("display", "block");
				$('#event_listing-3202025').css("display", "none");
				$('#photo_thumbnail-3205718').css("display","block");
					$('#video_thumbnail-3205719').css("display","block");
				if($('#event-726801.event .foot li.buy .last a').length >0){
			    $('#html-3273544').css("display","block");
				linkurl = $('#event-726801.event .foot li.buy .last a').attr("href");
				$('#html-3273544 .body a').attr("href",linkurl);
				}
			}
			else {
				if($('#event-726801.event .foot li.buy .last a').length >0){
					$('#html-3273544').css("display","block");
					
					linkurl = $('#event-726801.event .foot li.buy .last a').attr("href");
					$('#html-3273544 .body a').attr("href",linkurl);
				}
				
				$('#event_listing-3202026').css("display", "none");
				$('#event_listing-3202025').css("display", "block");
			}
			
		}
	}
	
	
	
	$('#event .grid_9 .module .content .body .cal_events li.cal_event').each(function(){
	
	var hiphen='<span class="hiphen"> - </span>';
	$(this).find('.txt .location').insertBefore($(this).find('.txt .venue'));	
	$(hiphen).insertAfter($(this).find('.txt .location'));
	});
	
	
	
$('#event_listing-3202022.event_listing ul.cal_events li.cal_event').each(function(){
		var eventPath=  $(this).find('.txt .date h4 a').attr('href');
		var viewEveMedia="<div class='viewMedia'><a class='viewpix' href='"+eventPath+"#photo_thumbnail-3205718"+"'>View Media</a></div>"
		$(this).append(viewEveMedia);	
		var eventlocation=$(this).find('.txt .event_location .venue').html();
		var locationpath="<a href='"+eventPath+"'>"+eventlocation+"</a>";	
		$(this).find('.txt .event_location .venue').html(locationpath);	
});
$('#event_listing-3202026.event_listing ul.cal_events li.cal_event').each(function(){
		var eventPath=  $(this).find('.txt .date h4 a').attr('href');
		var viewEveMedia="<div class='viewMedia'><a class='viewpix' href='"+eventPath+"#photo_thumbnail-3205718"+"'>View Media</a></div>"
		$(this).append(viewEveMedia);	
		var eventlocation=$(this).find('.txt .event_location .venue').html();
		var locationpath="<a href='"+eventPath+"'>"+eventlocation+"</a>";	
		$(this).find('.txt .event_location .venue').html(locationpath);	
});
$(".grid_5_1 .event_listing .module .content .body ul li.cal_event").last().addClass('last');	
	/*appending banner to landing page */
	var eventHead='<div class="uploadMedia"><a class="uploadLink" href="/tour-archive/">Been to a show? Upload your shows photos and videos.</a></div>';	
	$("#event_listing-726798.event_listing .module .content .head").append(eventHead);
	
	var upcomingHead='<div class="upcomingRedirect"><a class="upcomingLink" href="/tour-dates/" title="Upcoming show!">Want to see Trey Songz live? Check out upcoming dates.</a></div>';	
	$("#event_listing-3202020.event_listing .module .content .head").append(upcomingHead);
	
	/* Members who went for archives */
	$('#event_listing-3202022.event_listing ul.cal_events li.cal_event').each(function(){
		var memberGoing="Fans Went";
		var memberDate = $(this).find('.txt .date h4 a');
		var eventPath=  memberDate.attr('href');
		eventPath=eventPath+"?show=archive";
		memberDate.attr('href',eventPath);
		var attendeeCount= $(this).find('.attendee_count').html();
		$(this).find('.attendee_count').remove();
		if(attendeeCount!=null && attendeeCount!=""){
			attendeeCount=attendeeCount.substring((attendeeCount.lastIndexOf(":")+1),attendeeCount.length).trim();
			var member_det='<div class="member_details"><div class="membrGoing">'+ attendeeCount + " " + memberGoing +'</div></div>';
			$(this).find('.txt').append(member_det);
		}
	});
	
	var memGoing2="Fans Going ";
	$('#event_listing-3202021.event_listing ul.cal_events li.cal_event').each(function(){
		var attendeeCount= $(this).find('.attendee_count').html();
		var buyBtn= $(this).find('.buy');
		
		$(this).find('.buy').remove();
		$(this).find('.attendee_count').remove();
		if(attendeeCount!=null && attendeeCount!=""){
			attendeeCount=attendeeCount.substring((attendeeCount.lastIndexOf(":")+1),attendeeCount.length).trim();
			attendeeCount="("+ attendeeCount +")";
			var member_det='<div class="member_details"><div class="membrGoing">'+ memGoing2 + attendeeCount +'</div></div>';
			$(this).find('.txt').append(member_det);	
			 				
		}
		$(this).find('.txt').append(buyBtn);// Just changed the position		
	});
	
	$('#event_listing-3202025.event_listing ul.cal_events li.cal_event').each(function(){
		var attendeeCount= $(this).find('.attendee_count').html();
		var buyBtn= $(this).find('.buy');
		
		$(this).find('.buy').remove();
		$(this).find('.attendee_count').remove();
		if(attendeeCount!=null && attendeeCount!=""){
			attendeeCount=attendeeCount.substring((attendeeCount.lastIndexOf(":")+1),attendeeCount.length).trim();
			attendeeCount="("+ attendeeCount +")";
			var member_det='<div class="member_details"><div class="membrGoing">'+ memGoing2 + attendeeCount +'</div></div>';
			$(this).find('.txt').append(member_det);	
						
		}
		$(this).find('.txt').append(buyBtn);// Just changed the position	
					
	});

	$('#event_listing-3202021.event_listing .cal_events .cal_event .txt .buy ul li').each(function(){
		var tourText=$(this).find("a").text().toUpperCase();
		if (tourText == "BUY TICKETS") {
			$(this).addClass('buytickets');
		}
});

$('#event_listing-3202021.event_listing .cal_events .cal_event .txt .buy ul li').each(function(){
var tourText=$(this).find("a").text().toUpperCase();
if (tourText == "BUY TICKETS") {
	$(this).css("display","block");
}
else if(tourText == "SIGN IN TOUR GUESTBOOK"){
	$(this).css("display","block");
}
else{
	$(this).css("display","none");
}
});

	$('#event_listing-3202025.event_listing .cal_events .cal_event .txt .buy ul li').each(function(){
		var tourText=$(this).find("a").text().toUpperCase();
		if (tourText == "BUY TICKETS") {
			$(this).addClass('buytickets');
		}
});

$('#event_listing-3202025.event_listing .cal_events .cal_event .txt .buy ul li').each(function(){
var tourText=$(this).find("a").text().toUpperCase();
if (tourText == "BUY TICKETS") {
	$(this).css("display","block");
}
else if(tourText == "SIGN IN TOUR GUESTBOOK"){
	$(this).css("display","block");
}
else{
	$(this).css("display","none");
}
});


	
	//event_detail
	var detailPageUrl = window.location.href;
$.wmgfeature.facebookShare("#event-726801.event .body .cal_event", null, null, detailPageUrl, ".input.going", null); 


if ($('body').attr('id') == 'event_detail') {
	var memberCount = $('#member_listing-3223528.member_listing .module .content .head h3 span').text();
	var memberCount1 = $('#member_listing-3223528.member_listing .module .content .head h3 span').text();
	var openparanthesis = memberCount.indexOf("(");
	var closeparanthesis = memberCount.indexOf(")");
	memberCount = memberCount.substring(openparanthesis + 1, closeparanthesis);
	var eventdate = $('#event-726801.event .cal_event .date .val').text();
	eventdateobj = new Date(eventdate);
	currentDate = new Date();
	var offsetdata = eventdateobj.getTime() - currentDate.getTime();
	var offsetcount = offsetdata / 86400000;
	var currentpageshowtitle = $.urlParam("show");
	
	if (currentpageshowtitle == "archive" || offsetcount < -1) {
		//if(memberCount=='0' || memberCount=="1"){membersGoing="Fans Went"}
		var memberClass = '<div class="membersGoing">Fans Went : <span class="membercount"></span></div>';
		var memberTitleReplace = $('#member_listing-3162869.member_listing .module .content .head h3').text().trim().replace("Fans Going", "Fans Went");
		//$('#member_listing-3223528.member_listing .module .content .head h3').html(memberTitleReplace);
		//var memberClassListing ='Fans Went  <span class="membercount"></span>';
		$('#member_listing-3223528.member_listing .module .content .head h3').html("Fans Went"+'<span class=\"membercount\">'+ memberCount1 +'</span>');

	}
	else {
		//var membersGoing="Fans Going";
		var memberClass = '<div class="membersGoing">fans Going : <span class="membercount"></span></div>';
	//	var memberClassListing = 'Fans Going  <span class="membercount"></span>';
		$('#member_listing-3223528.member_listing .module .content .head h3').html("Fans Going"+'<span class=\"membercount\">'+memberCount1+"</span>");
	}
	//$(memberClass).insertAfter($('#event-726801.event .module .content .body .cal_event .tools .input.going'));
	

	$("#event-726801.event .module .content .body .cal_event .tools").append(memberClass);
	if (memberCount != null && memberCount != " ") 
		;
	{
		$("#event-726801.event .module .content .body .cal_event .tools .membersGoing span.membercount").text(memberCount);
		//$("#member_listing-3223528.member_listing .module .content .head h3 span.membercount").text(memberCount);
	}
	
}
	
var videocategory = $('#categories-350377.categories .module .content .head');
var postvid = "<div class='postbutton'><a href='/upload/' id='postvid'>Post a vid</a></div>";

videocategory.append(postvid);

var photocategory = $('#categories-350376.categories .module .content .head');
var postpic = "<div class='postbutton'><a href='/upload/' id='postpic'>Post a pic</a></div>";

photocategory.append(postpic);

var fanpagephotocategory = $('#categories-3042041.categories .module .content .body');
var postapic = "<div class='postbutton'><a href='/upload/' id='postpic'>Post a pic</a></div>";

fanpagephotocategory.prepend(postapic);
	
	$("#member_listing-5701946 .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');
	}
	
	});
	
	$("#member_listing-2973976 .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","264");
			//$(this).attr("height","318");
			var avatarAncStyle="display:block !important;width:264px !important;";
			var avatarImgStyle="display:block !important;width:264px !important;cursor:pointer !important;";
			$(this).parent().attr("style",avatarAncStyle);
			$(this).attr("style",avatarImgStyle);
			if(overrideDefaultImg == "true"||overrideDefaultImg == "TRUE"){
				writeToConsole(overrideImgSrc);				
				$(this).attr("src",overrideImgSrc);
	//"http://d2ceoshttpcontent.com.edgesuite.net/d2ceoscontent/photo/pro/thumbnails/20110104/cc1e290d-4157-4f4d-8146-546bf129e208/thumbnail_8.jpg"
			}
			var avatarDivStyle="background:transparent url("+photoImageSrcNew+") no-repeat 0px 0px;width:264px;";
			$(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","152");
			$(this).attr("height","144");
			var avatarAncStyle="display:block !important;width:152px !important;height: 144px !important;";
			var avatarImgStyle="display:block !important;width:152px !important;height: 144px !important;cursor:pointer !important;";
			$(this).children("a").attr("style",avatarAncStyle);		
			$(this).attr("style",avatarImgStyle);
	}
	});
/*	
	$('.module .content .body a.treyexpimglink img').each(function() {
	    var maxWidth = 264; 
	    var maxHeight = 264;    
	    var ratio = 0;  
	    var width = $(this).width();    
	    var height = $(this).height();  
	    
	    if(width > maxWidth){
	        ratio = maxWidth / width;   
	        $(this).css("width", maxWidth); 
	        $(this).css("height", height * ratio);  
	        height = height * ratio;    
	    }

	    var width = $(this).width();    
	    var height = $(this).height();  
	    
	    if(height > maxHeight){
	        ratio = maxHeight / height; 
	        $(this).css("height", maxHeight);   
	        $(this).css("width", width * ratio);    
	        width = width * ratio;    
	    }
	});
*/
	
	$('#member_listing-2973976.member_listing .members li.xl').unbind('mouseenter mouseleave');
	$(".fanclubpages #FooterLinks").children().wrapAll("<div id='FooterLinksInner'><div id='FooterLinks_inner'></div></div>");
	$(".fanclubpages #logoLinks").wrap('<div class="logoWrap"></div>');

	
/*START - Fix for truncating author name in the discussions page */

var discussionAuthorLen = "10";

			$('.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);
	$("body").addClass($.browser.name);
	
	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'); 
 		var $newblogReadMoreFix = $('#blog_listing-350370.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');
	$('#ustour #html-2566090.html .module .foot').removeClass('empty');
	
	var followlink = $('#ustour #html-2566090 .module .follow a');
	$('#ustour #html-2566090.html .module .foot').append(followlink);
    $('#ustour #html-2566090.html .module .foot a').addClass('follow');
	
	/* 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: TreysAngels drop-down for top nav */
		
		//var treysNavCell = $('.nav_main ul li.nav-angel');   //change this selector to target a different cell in the top nav
	//	treysNavCell.addClass('dropdown');
	//	treysNavCell.append(angelsSubNav);
	/* END: TreysAngels 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')
	  .addClass('dropdown')
	  .append(angelsSubNav);
	  
	
	  
	 $customNavs.filter(function(){
		  return (/^Store$/i).test($(this).text())
		}).attr("rel","external")
		  .parent()
    	  .addClass('nav-custom')
		  .addClass('dropdown')
		  .addClass('nav-store')
		  .append(storeSubNav);	

	
	var musicNavCell = $(".nav_main ul li.nav-custom.nav-music");   //change this selector to target a diffent cell in the top nav
	musicNavCell.addClass('dropdown');
	musicNavCell.append(musicSubNav);

	var videoNavCell = $(".nav_main ul li.nav-video");   //change this selector to target a diffent cell in the top nav
	videoNavCell.addClass('dropdown');
	videoNavCell.append(videoSubNav);

	var photoNavCell = $(".nav_main ul li.nav-photo");   //change this selector to target a diffent cell in the top nav
	photoNavCell.addClass('dropdown');
	photoNavCell.append(photoSubNav);
	
	
	$(".nav_main ul li.upload a").text("Share");
	
	/* 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(); }
	);
	
	/* Changing the url of upload to share!!*/ 
	$("#nav_main-350423 .upload a").unbind('click');
	$("#nav_main-350423 .upload a").attr("href","/share");
	
	/* 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) {
		$('.nav_main .nav-store').addClass("active");
		$("#ringtonesNav").addClass("active");
		}
	if (location.href.indexOf("/community-landing/") != -1) {
		$('.nav_main .nav-community_landing').addClass("active");
		$("#communityHomeNav").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");
    }	
	
	var treysangelsNavCell = $('.nav_main ul li.nav-angel');
	

	/*tour sub nav drop downs */
	
	if (location.href.indexOf("/tour-dates/") !=-1){
		tourNavCell.addClass("active");
		$("#upcoming").addClass("active");
	}
	
	else if (location.href.indexOf("/tour-archive/") !=-1){
		tourNavCell.addClass("active");
		$("#active").addClass("active");
	}
	
	/*Treys angels ddrop downs */
	if (location.href.indexOf("/chat/") !=-1){
		$(".nav-custom.nav-angel.dropdown").addClass("active");
		$("#angelchat").addClass("active");
	}
	
	if (location.href.indexOf("/group/treys-angels/") !=-1){
		$(".nav-custom.nav-angel.dropdown").addClass("active");
		$("#angelhome").addClass("active");
	}

	if (location.href.indexOf("/news/category/treys-angels/") != -1) {
			$("#angelsupdatesNav").addClass("active");
		}
	if (location.href.indexOf("/video/category/treys-angels/") != -1) {
			
			$("#angelsvideosNav").addClass("active");
		}
	if (location.href.indexOf("/treysangelsphotos/") != -1) {
			treysangelsNavCell.addClass("active");
			$("#angelsphotosNav").addClass("active");
			$("#categories-3042041.categories .content .division li.category.category_38130").addClass("selected");
		}
	if (location.href.indexOf("/treysangelsdtlr/") != -1) {
			treysangelsNavCell.addClass("active");
			$("#angelsphotosNav").addClass("active");
			$("#categories-3042041.categories .content .division li.category.category_39290").addClass("selected");
		}
	if (location.href.indexOf("/treysangelswalmart/") != -1) {
			treysangelsNavCell.addClass("active");
			$("#angelsphotosNav").addClass("active");
			$("#categories-3042041.categories .content .division li.category.category_39291").addClass("selected");
		}
	if (location.href.indexOf("/shadowtreyfortheday/") != -1) {
			treysangelsNavCell.addClass("active");
			$("#angelsphotosNav").addClass("active");
			$("#categories-3042041.categories .content .division li.category.category_39821").addClass("selected");
		}
	if (location.href.indexOf("/macysrocawearinstore/") != -1) {
			treysangelsNavCell.addClass("active");
			$("#angelsphotosNav").addClass("active");
			$("#categories-3042041.categories .content .division li.category.category_40073").addClass("selected");
		}
	if (location.href.indexOf("/sokodakevent/") != -1) {
			treysangelsNavCell.addClass("active");
			$("#angelsphotosNav").addClass("active");
			$("#categories-3042041.categories .content .division li.category.category_40148").addClass("selected");
		}
	if (location.href.indexOf("/treysangelsomgtour/") != -1) {
			treysangelsNavCell.addClass("active");
			$("#angelsphotosNav").addClass("active");
			$("#categories-3042041.categories .content .division li.category.category_44499").addClass("selected");
		}
	if (location.href.indexOf("/treysangelsultimateangelcontest/") != -1) {
			treysangelsNavCell.addClass("active");
			$("#angelsphotosNav").addClass("active");
			$("#categories-3042041.categories .content .division li.category.category_44500").addClass("selected");
		}
	if (location.href.indexOf("/treysangelsangelmissions/") != -1) {
			treysangelsNavCell.addClass("active");
			$("#angelsphotosNav").addClass("active");
			$("#categories-3042041.categories .content .division li.category.category_44501").addClass("selected");
		}
	if (location.href.indexOf("/treysangelsinstores/") != -1) {
			treysangelsNavCell.addClass("active");
			$("#angelsphotosNav").addClass("active");
			$("#categories-3042041.categories .content .division li.category.category_44502").addClass("selected");
		}
		if (location.href.indexOf("/angelswithheart-photo/") != -1) {
			treysangelsNavCell.addClass("active");
			$("#angelsphotosNav").addClass("active");
			$("#categories-3042041.categories .content .division li.category.category_46166").addClass("selected");
		}
	
	if (location.href.indexOf("/angelswithheart-photo/") != -1) {
			treysangelsNavCell.addClass("active");
			$("#angelsphotosNav").addClass("active");
			$("#categories-3042041.categories .content .division li.category.category_46166").addClass("selected");
		}
	
		if (location.href.indexOf("/justtrey/") != -1) {
			treysangelsNavCell.addClass("active");
			$("#angelsphotosNav").addClass("active");
			$("#categories-3042041.categories .content .division li.category.category_47708").addClass("selected");
		}
	
	if (location.href.indexOf("/talk/category/treys-angels/") != -1) {
			
			$("#angelsdiscussionsNav").addClass("active");
		}
	
	$('#categories-350380.categories .module .content .body').append('<div class="postbutton" href="/upload">Post a Pic</div>');
	

	/* 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 */
	
	
	 //Badges implementation
	$(".badges ul").each(function(){
		if ($(this).find("li").length > 0) {
		$(this).html('<li class="badge"><a class="badgeImageReplace" href="/group/treys-angels/"></a></li>');
		}
	}); 
	
	
	/* category restriction functionality for treysangesla fan club photo pages */	
	
	/*category restriction logic in treys angels photo landing page */
	$("#categories-3042041.categories .module ul#category-list li.division ul li").each(function(){
		var lookupclass=$(this).attr('class');
		var arrayValues=lookupclass.split(" ");
		
		var flag = false;
		for(arraycount=0;arraycount<=arrayValues.length;arraycount++){
			if(categoryArray.hasOwnProperty(arrayValues[arraycount])){
				($(this).find("a")).attr("href",categoryArray[arrayValues[arraycount]]);
				$(this).css("display","block");
				flag = true;
				break;
			}else{
				$(this).css("display","none");
			}
		
		}
		if(flag){
			return true;
		}
		
	
	});
	
	$("#categories-3042041.categories").css("display","block");
	
	
	
	$("#categories-350376.categories .module ul#category-list li.division ul li").each(function(){
		
		var lookupclass=$(this).attr('class');
		var arrayValues=lookupclass.split(" ");
		
		var flag = false;
		for(arraycount=0;arraycount<=arrayValues.length;arraycount++){
			if(categoryArray.hasOwnProperty(arrayValues[arraycount])){
				$(this).css("display","none");
				flag = true;
				break;
			}else{
				$(this).css("display","block");
			}
		
		}
		if(flag){
			return true;
		}
		
	
	});
	
	$("#categories-350376.categories").css("display","block");
	
	if($('body#ustour').length != 0){
		$('#FooterLinks1 h4').addClass("removeSifr");
		$('#FooterLinks2 h4').addClass("removeSifr");
	}
	
	/* Music player - User signup request */
	if ($('body#album_detail').length > 0 || $('body#audio_detail').length > 0) {
		var signupMsg="Register for unlimited streaming of treysongz's music."
		var usedLoginInState = $("#userLoggedIn").val();
		var memberStatus = $("#isMember").val();	
		if ( usedLoginInState == 'true' && memberStatus == 1) {
				$.cookie("showMusicRstError1","No",{path: '/'});									 															
			}else{
				if (restrictedAlbumTrack()){
					$('#song_playlist-390843.song_playlist .playlist.s .info').after('<div id="dummyPlayer" style="cursor:pointer;height:35px;background:url(http://origin-static.ciscoeos.com/1285931098/zipupload/6b8/b6a/559e542e43256d52e5e455e3de/images/grid_9_player_new.jpg) no-repeat scroll left center #DEDEDE;"></div>');	
					$('#song_playlist-390843.song_playlist .playlist.s .player').remove();					
					$('#audio_player-350365.audio_player .body .player').remove();
					$('#audio_player-350365.audio_player .body .title').after('<div id="dummyPlayer" style="cursor:pointer;height:35px;background:url(http://origin-static.ciscoeos.com/1285931098/zipupload/6b8/b6a/559e542e43256d52e5e455e3de/images/grid_6_player_new.jpg) no-repeat scroll left center #DEDEDE;"></div>');	
					
					$('.song_playlist .playlist.s #dummyPlayer').bind( 'click',function(event){					
						$.cookie("showMusicRstError1","Yes",{path: '/'});
						var albumVal= $(this).parent().find('.info .txt .album h2').html().trim();					
						$('#html-373085.html .commLinks a').attr('href','/sign-up/?intcmp=join_restrictedaudio-'+albumVal);
						$('#html-373085.html .commLinks a').trigger('click');															
					});  
					$('#song_playlist-390843.song_playlist .playlist .list ul li .title').bind( 'click',function(event){					
						$.cookie("showMusicRstError1","Yes",{path: '/'}); 
						var parentLiId= $(this).parent().attr("id");
						$('#html-373085.html .commLinks a').attr('href','/sign-up/?intcmp=join_restrictedaudio-'+parentLiId);
						$('#html-373085.html .commLinks a').trigger('click');		
					});						
					$('.audio_player .body #dummyPlayer').bind( 'click',function(event){					
						$.cookie("showMusicRstError1","Yes",{path: '/'});
						var trackVal= $(this).parent().find('.title h3').html().trim();
						$('#html-373085.html .commLinks a').attr('href','/sign-up/?intcmp=join_restrictedaudio-'+trackVal);
						$('#html-373085.html .commLinks a').trigger('click');									
					});
				}
				 
			}
	}
	
	/* Music player - User signup request */
	
		
/*To open Buy Tickets in a new Tab*/
	$('.event_listing .cal_events .cal_event .txt .buy ul li a').attr("rel","external");

/* To get the discussion category for omniture */
	$('#add_new_discussion .add_new_article .content .body .input.select select').change(function(){
		$("#add_new_discussion .add_new_article select option:selected").each(function () {
        	strDiscussion = $(this).text() + " ";
			
        });		
	});
/* To get the discussion category for omniture - End */
	
/* To get the blog category for omniture */
	var category = ($('#add_new_blog .add_new_article .content .body .input.select label').html());
	$("#add_new_blog .add_new_article .content .body .input.select label").each(function () {
		if ($(this).html() == "Blog Category") {
			$(this).parent().addClass('blogCategory')
		}
	});
	
	$('#add_new_blog .add_new_article .content .body .input.select.blogCategory select').change(function(){
		$("#add_new_blog .add_new_article .input.select.blogCategory select option:selected").each(function () {
       		strBlog = $(this).text() + " ";			
       	});		
	});	
/* To get the blog category for omniture - End */

if ($('body#sign_up').length != -1) {		
		var paramEmailId = $.urlParam("email");
		var paramDisplayname= $.urlParam("displayname");
		if (paramEmailId != null) {
			if (paramEmailId.length != -1  && paramEmailId != 0) {
				$("input#cmsgData\\[emailAddress\\]").val(paramEmailId);
			}
		}	
		
		if (paramDisplayname != null) {
			if (paramDisplayname.length != -1 && paramDisplayname != 0) {
				$("input#cmsgData\\[userName\\]").val(paramDisplayname);
			}
		}	
		$("input#cmsgData\\[userName\\]").removeClass("focused");
		$("input#cmsgData\\[emailAddress\\]").removeClass("focused");
		$("input#cmsgData\\[password\\]").removeClass("focused");
		if($("input#cmsgData\\[userName\\]").val() == null || $("input#cmsgData\\[userName\\]").val().length==0){
			$("input#cmsgData\\[userName\\]").focus();
			$("input#cmsgData\\[userName\\]").addClass("focused");
		}
		else if($("input#cmsgData\\[emailAddress\\]").val() == null || $("input#cmsgData\\[emailAddress\\]").val().length==0){
			$("input#cmsgData\\[emailAddress\\]").focus();
			$("input#cmsgData\\[emailAddress\\]").addClass("focused");
		}else if($("input#cmsgData\\[password\\]").val() == null || $("input#cmsgData\\[password\\]").val().length==0){
			$("input#cmsgData\\[password\\]").focus();
			$("input#cmsgData\\[password\\]").addClass("focused");
		}		
	}
	
	$("#group_detail_4476.msie8 div.ad.medium").parent("div.ad").parent("form").attr("style","display:none");
	$("#group_detail_4476.msie8 div.ad.leaderboard").parent("div.ad").parent("form").attr("style","display:none");
	$("#group_detail_4476.msie8 div.ad.leaderboard .body").attr("style","border:none");
	
		modifyMediaSize(".grid_5 .photos li .img a img", "_6", "display:block !important;width:148px !important;height: auto !important;", "display:block !important;width:148px !important;height: auto !important;cursor:pointer !important;", false);
		

});

function eoscInit(){
	
	$('.blog_listing .articles li.article').each(function(){
        $(this).find('.description a').each(function(){
            if ($(this).text() == "Read more") {
                $(this).addClass("read_more");
            }
        });
    });
	
	//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();
	
	$('#group_detail_4476 .blog_listing .module .body .article .title h4 a').each(function(){
		var title_height=$(this).height();
		if(title_height<27){
			$(this).addClass("single_line_title");
			$('.blog_listing .module .body .article .title').addClass("small_ttile_bg");
		}
	});	
	
	fanclubPhotoThumbnail();
	truncateContent('.angelsphotocategories .photo_thumbnail .photos li.compact .txt .title h4 a',25);

	/* Official Twitter and fLike buttons implementation - pagination */
	var listing='moduleListing';
	if (($('body').attr('id') == "home_tumbler")||($('body').attr('id') == "group_detail_4476")) {
		
		var twitterObj = {
			blockSelector: '.articles li.article',
			insertionSelector: '.activity',
			siteUrl: 'http://treysongz.wmg.ciscoeos.com',
			urlSelector:'.title h4 a',
			viaParam: '&amp;via=surferbloods',
			relatedParam: '&amp;related=surferbloods'		
		}
		var fbLikeObj = {
			blockSelector: '.articles li.article',
			insertionSelector: '.activity',
			urlSelector:'.title h4 a',
			siteUrl: 'http://treysongz.wmg.ciscoeos.com'
		}
		if ($('.twitter-share-button').length == 0) {
			$.wmgfeature.twttrButton(twitterObj, listing);
			var twtrScript=document.createElement('script');
			twtrScript.type = 'text/javascript';
			twtrScript.src = "http://platform.twitter.com/widgets.js";
		$(".blog_listing").append(twtrScript);
		}
		$.wmgfeature.fbLike(fbLikeObj, listing);
		FB.Share.renderPass();
	}
	
	/* Blog learnmore - start*/
	
	$('a.learnmore').css('display','none');
	$('a.treyangelsbloghead').hover(function(){$(this).next().css("display","block");},function(){$(this).next().css("display","none");});
	$('a.learnmore').hover(function(){$(this).css("display","block");},function(){$(this).css("display","none");});
		
	$('#blog .blog_listing .module .body .article').each(function(){
		var blogauthor=$(this).find('.author a').html();
		var blogposteddate=$(this).find('.date').html();
		var memberlink=$(this).find('.author a').attr("href");

		if($(this).hasClass('category_36491')){
			
			$(this).addClass("fanClub");
			$(this).find('.title').prepend("<a class='learnmore' " + "href = '/become-a-member/'></a>");				
			$(this).find('.title').prepend("<a class='treyangelsbloghead' " + "href = '/become-a-member/'>Treyangels</a>");	
			
			blogposteddate=blogposteddate.split('at');
			blogposteddate=blogposteddate[0];
		}
		
		if ($(this).find('.post_details').length == 0) {
			$(this).find('.title').append('<div class="post_details">Posted ' + blogposteddate + 'by <a href="' + memberlink + '">' + blogauthor + '</a></div>');
		}
		$(this).find('.gPlus').insertAfter($(this).find('.fb_like'));		
	});
	
	$('#group_detail_4476 .blog_listing .module .body .article').each(function(){
		var blogauthor=$(this).find('.author a').html();
		var blogposteddate=$(this).find('.date').html();
		var memberlink=$(this).find('.author a').attr("href");

		if($(this).hasClass('category_36491')){
			
			$(this).addClass("fanClub");
			$(this).find('.title').prepend("<a class='learnmore' " + "href = '/become-a-member/'></a>");				
			$(this).find('.title').prepend("<a class='treyangelsbloghead' " + "href = '/become-a-member/'>Treyangels</a>");	
			
			blogposteddate=blogposteddate.split('at');
			blogposteddate=blogposteddate[0];
		}
		
		if ($(this).find('.post_details').length == 0) {
			$(this).find('.title').append('<div class="post_details">Posted ' + blogposteddate + 'by <a href="' + memberlink + '">' + blogauthor + '</a></div>');
		}
		$(this).find('.gPlus').insertAfter($(this).find('.fb_like'));		
	});
	/* Blog learnmore - end*/
	//comments
	

$('.comments .module li.comment').each(function(){
	var check = $(this).find('.comment-content')
	if (check.length == 0 ) {
		
		$(this).prepend('<div class="comment-content"></div>')
		var cont = $(this).find('.comment-content');
		var txt = $(this).find('.txt');
		var member = $(this).find('.member');
		cont.append(member);
		cont.append(txt);
		var date = $(this).find('.date');
		var author = $(this).find('.author');
		author.insertAfter(date)
		
		$(this).append('<div class="foot"></div>');
	}
});
	
	/*g+ button implementation	- starts */
	if (($('body').attr('id') == "blog") || ($('body').attr('id') == "group_detail_4476")) {	
		$('.articles li.article').each(function(){
			var tumblr_link_url = "http://www.treysongz.com" + $(this).find(".title h4 a").attr("href") + "?cmpid=treysongz/tumblr/share-on-tumblr/blog-detail/";
			var tumblr_link_name = $(this).find('.title h4').text();
			var tumblr_link_description = $(this).find('.description').clone();
tumblr_link_description.find('a.read_more').remove();
tumblr_link_description = $(tumblr_link_description).html();
			
			var plusone_link_url = "http://www.treysongz.com" + $(this).find(".title a").attr("href") + "?cmpid=treysongz/tumblr/share-on-tumblr/blog-detail/";
			var plusone = document.createElement("g:plusone");
			plusone.setAttribute("href", plusone_link_url);
			plusone.setAttribute("size", "medium");
			$(this).append('<div class="gPlus"></div>');
			$(this).append('<span id="tumblr_button_abc123"></span>');
			$(this).find('.gPlus').append(plusone);
			
			var tumblr_button = document.createElement("a");
			tumblr_button.setAttribute("href", "http://www.tumblr.com/share/link?url=" + encodeURIComponent(tumblr_link_url) + "&name=" + encodeURIComponent(tumblr_link_name) + "&description=" + encodeURIComponent(tumblr_link_description));
			tumblr_button.setAttribute("title", "Share on Tumblr");
			tumblr_button.setAttribute("style", "display:inline-block; text-indent:-9999px; overflow:hidden; width:63px; height:20px; background:url('http://platform.tumblr.com/v1/share_2.png') top left no-repeat transparent;");
			tumblr_button.setAttribute("target", "_blank");
			tumblr_button.innerHTML = "Share on Tumblr";
			$(this).find('#tumblr_button_abc123').append(tumblr_button);
		});
	}		
	if (($('body').attr('id') == "blog_detail")||($('body').attr('id') == "photo_detail")||($('body').attr('id') == "video_detail")) {
			if ($('#tumblr_button_abc123').length == 0) {
				$('.twitter-share-button').after('<span id="tumblr_button_abc123"></span>');
				//gplus button
                var plusone_link_url = "http://www.treysongz.com" + $(this).find(".title a").attr("href") + "?cmpid=treysongz/tumblr/share-on-tumblr/blog-detail/";
                var plusone = document.createElement("g:plusone");
                plusone.setAttribute("href", plusone_link_url);
                plusone.setAttribute("size", "medium");
                $(this).append('<div class="gPlus"></div>');
                $(this).append('<span id="tumblr_button_abc123"></span>');
                $(this).find('.gPlus').append(plusone);
				
				var tumblr_link_url = "http://www.treysongz.com" + window.location.pathname + "?cmpid=treysongz/tumblr/share-on-tumblr/blog-detail/";
				var tumblr_link_name = $('.content div.article .title h4').text();
				var tumblr_link_description = $('.blog_entry .description').html();
				
				var tumblr_button = document.createElement("a");
				tumblr_button.setAttribute("href", "http://www.tumblr.com/share/link?url=" + encodeURIComponent(tumblr_link_url) + "&name=" + encodeURIComponent(tumblr_link_name) + "&description=" + encodeURIComponent(tumblr_link_description));
				tumblr_button.setAttribute("title", "Share on Tumblr");
				tumblr_button.setAttribute("style", "display:inline-block; text-indent:-9999px; overflow:hidden; width:63px; height:20px; background:url('http://platform.tumblr.com/v1/share_2.png') top left no-repeat transparent;");
				tumblr_button.setAttribute("target", "_blank");
				tumblr_button.innerHTML = "Share on Tumblr";
				$('#tumblr_button_abc123').append(tumblr_button);
			}
		}
	
		/*g+ button implementation	- ends */
	
	$('.event_listing .cal_events .cal_event .txt .buy ul li a').attr("rel","external");
	$('.event_listing .cal_events .cal_event .txt .buy ul li').each(function(){
		var tourText=$(this).find("a").text().toUpperCase();
		if (tourText == "BUY TICKETS") {
			$(this).addClass('buytickets');
		}		
});
	
	/* upload photos and videos button injection */
	$('#event_listing-3202020.event_listing ul.cal_events li.cal_event').each(function(){
		var eventPath=  $(this).find('.txt .date h4 a').attr('href');
		var viewEveMedia="<div class='viewMedia'><a class='viewpix' href='"+eventPath+"#photo_thumbnail-3205718"+"'>View Media</a></div>"
		$(this).append(viewEveMedia);			 
		var eventlocation=$(this).find('.txt .event_location .venue').html();
		var locationpath="<a href='"+eventPath+"'>"+eventlocation+"</a>";	
		$(this).find('.txt .event_location .venue').html(locationpath);				
	});
	
	$('#event_listing-726798.event_listing .cal_events .cal_event .txt .buy ul li').each(function(){
		var tourText=$(this).find("a").text().toUpperCase();
		if (tourText == "BUY TICKETS") {
			$(this).css("display","block");
		}
		else if(tourText == "SIGN IN TOUR GUESTBOOK"){
			$(this).css("display","block");
		}
		else{
			$(this).css("display","none");
		}
		});
	
		
	var memGoingArcDetail="Fans Went ";
	$('#event_listing-3202026.event_listing ul.cal_events li.cal_event').each(function(){
		var attendeeCount= $(this).find('.attendee_count').html();

		$(this).find('.attendee_count').remove();
		if(attendeeCount!=null && attendeeCount!=""){
			attendeeCount=attendeeCount.substring((attendeeCount.lastIndexOf(":")+1),attendeeCount.length).trim();
			attendeeCount="("+ attendeeCount +")";
			var member_det='<div class="member_details"><div class="membrGoing">'+ memGoingArcDetail + attendeeCount +'</div></div>';
			$(this).find('.txt').append(member_det);
		}		
	});
	
	var memGoingArc="Fans Went ";
	$('#event_listing-3202022.event_listing ul.cal_events li.cal_event').each(function(){
		var attendeeCount= $(this).find('.attendee_count').html();

		$(this).find('.attendee_count').remove();
		if(attendeeCount!=null && attendeeCount!=""){
			attendeeCount=attendeeCount.substring((attendeeCount.lastIndexOf(":")+1),attendeeCount.length).trim();
			attendeeCount="("+ attendeeCount +")";
			var member_det='<div class="member_details"><div class="membrGoing">'+ memGoingArc + attendeeCount +'</div></div>';
			$(this).find('.txt').append(member_det);
		}		
	});
	
	$('#event_listing-3202020.event_listing ul.cal_events li.cal_event').each(function(){
		var memberGoing="Fans Went";
		var eventPath=  $(this).find('.txt .date h4 a').attr('href');
		eventPath=eventPath+"?show=archive";
		$(this).find('.txt .date h4 a').attr('href',eventPath);
		var attendeeCount= $(this).find('.attendee_count').html();
		$(this).find('.attendee_count').remove();
		if(attendeeCount!=null && attendeeCount!=""){
			attendeeCount=attendeeCount.substring((attendeeCount.lastIndexOf(":")+1),attendeeCount.length).trim();
			attendeeCount="("+ attendeeCount +")";
			var member_det='<div class="member_details"><div class="membrGoing"><a href="'+eventPath+'">'+ memberGoing + attendeeCount +'</a></div></div><div class="moreinfo" style="float:left;"><a class="viewmoreinfo" href="'+eventPath+'">More info</a></div>';
			$(this).find('.txt').append(member_det);
			 		
			
		}else{
			var member_det='<div class="moreinfo" style="clear:both;"><a class="viewmoreinfo" href="'+eventPath+'">More info</a></div>';
			$(this).find('.txt').append(member_det);
			 
		}				
	});

	
	/* members going and members went code injection */
	var memberGoing="Fans Going ";
	$('#event_listing-726798.event_listing ul.cal_events li.cal_event').each(function(){
		var attendeeCount= $(this).find('.attendee_count').html();
		var eventPath=  $(this).find('.txt .date h4 a').attr('href');
		
		$(this).find('.attendee_count').remove()
		if(attendeeCount!=null && attendeeCount!=""){
			attendeeCount=attendeeCount.substring((attendeeCount.lastIndexOf(":")+1),attendeeCount.length).trim();
			attendeeCount="("+ attendeeCount +")";
			var member_det='<div class="member_details"><div class="membrGoing"><a href="'+eventPath+'">'+ memberGoing + attendeeCount +'</a></div></div><div class="moreinfo" style="float:left;"><a class="viewmoreinfo" href="'+eventPath+'">More info</a></div>';
			$(this).find('.txt').append(member_det);
				
			
		}else{
			//var member_det='<div class="moreinfo" style="clear:both;float:left;"><a class="viewmoreinfo" href="'+eventPath+'">More info</a></div>';
			$(this).find('.txt').append(member_det);
			 	
		}
			
	});
	/* fix in event detail page */
 	/*if ($('body').attr('id') == 'event_detail') {
	var memberCount = $('#member_listing-3223528.member_listing .module .content .head h3 span').text();
	var memberCount1 = $('#member_listing-3223528.member_listing .module .content .head h3 span').text();
	var openparanthesis = memberCount.indexOf("(");
	var closeparanthesis = memberCount.indexOf(")");
	memberCount = memberCount.substring(openparanthesis + 1, closeparanthesis);
	var eventdate = $('#event-726801.event .cal_event .date .val').text();
	eventdateobj = new Date(eventdate);
	currentDate = new Date();
	var offsetdata = eventdateobj.getTime() - currentDate.getTime();
	var offsetcount = offsetdata / 86400000;
	var currentpageshowtitle = $.urlParam("show");
	
	if (currentpageshowtitle == "archive" || offsetcount < -1) {
		//if(memberCount=='0' || memberCount=="1"){membersGoing="Fans Went"}
		var memberClass = '<div class="membersGoing">Fans Went : <span class="membercount"></span></div>';
		var memberTitleReplace = $('#member_listing-3162869.member_listing .module .content .head h3').text().trim().replace("Fans Going", "Fans Went");
		//$('#member_listing-3223528.member_listing .module .content .head h3').html(memberTitleReplace);
		//var memberClassListing ='Fans Went  <span class="membercount"></span>';
		$('#member_listing-3223528.member_listing .module .content .head h3').html("Fans Went"+'<span class=\"membercount\">'+ memberCount1 +'</span>');

	}
	else {
		//var membersGoing="Fans Going";
		var memberClass = '<div class="membersGoing">fans Going : <span class="membercount"></span></div>';
	//	var memberClassListing = 'Fans Going  <span class="membercount"></span>';
		$('#member_listing-3223528.member_listing .module .content .head h3').html("Fans Going"+'<span class=\"membercount\">'+memberCount1+"</span>");
	}
	//$(memberClass).insertAfter($('#event-726801.event .module .content .body .cal_event .tools .input.going'));
	

	$("#event-726801.event .module .content .body .cal_event .tools").append(memberClass);
	if (memberCount != null && memberCount != " ") 
		;
	{
		$("#event-726801.event .module .content .body .cal_event .tools .membersGoing span.membercount").text(memberCount);
		//$("#member_listing-3223528.member_listing .module .content .head h3 span.membercount").text(memberCount);
	}
	
}
*/
	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","247");
			$(this).attr("height","144");
			var avatarAncStyle="display:block !important;width:247px !important;height: 144px !important;";
			var avatarImgStyle="display:block !important;width:247px !important;height: 144px !important;cursor:pointer !important;";
			$(this).children("a").attr("style",avatarAncStyle);		
			$(this).attr("style",avatarImgStyle);							
	}
	});
}

function photoimageResize(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","270");
			$(this).attr("height","270");
			var avatarAncStyle="display:block !important;width:270px !important;height: 270px !important;";
			var avatarImgStyle="display:block !important;width:270px !important;height: 270px !important;cursor:pointer !important;";
			$(this).children("a").attr("style",avatarAncStyle);		
			$(this).attr("style",avatarImgStyle);
			var avatarDivStyle="background:transparent url("+photoImageSrcNew+") no-repeat 0px 0px;width:270px;height:270px;";
			$(this).parent().parent().attr("style",avatarDivStyle);
			$(this).parent().parent().css('background','none');							
	}
	});
}
/***** Don't use this function - This is temporary fix ***/
function photoimageResizeTweak(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="_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;			
			$(this).attr("src",photoImageSrcNew);
			$(this).attr("width","270");
			$(this).attr("height","270");
			var avatarAncStyle="display:block !important;width:270px !important;height: 270px !important;border:none";
			var avatarImgStyle="display:block !important;width:270px !important;height: 390px !important;cursor:pointer !important;";
			$(this).children("a").attr("style",avatarAncStyle);		
			$(this).attr("style",avatarImgStyle);
			var avatarDivStyle="background:transparent url("+photoImageSrcNew+") no-repeat 0px 0px;width:270px;height:270px;border:4px solid #D1AE46;overflow:hidden";
			$(this).parent().parent().attr("style",avatarDivStyle);
			$(this).parent().parent().css('background','none');							
	}
	});
}

function newphotoimageResize(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","155");
			$(this).attr("height","155");
			var avatarAncStyle="display:block !important;width155px !important;height: 155px !important;";
			var avatarImgStyle="display:block !important;width:155px !important;height: 155px !important;cursor:pointer !important;";
			$(this).children("a").attr("style",avatarAncStyle);		
			$(this).attr("style",avatarImgStyle);
			var avatarDivStyle="background:transparent url("+photoImageSrcNew+") no-repeat 0px 0px;width:155px;height:155px;";
			$(this).parent().parent().attr("style",avatarDivStyle);
			$(this).parent().parent().css('background','none');							
	}
	});
}
	
	
	imageResize("#video_thumbnail-399818.video_thumbnail .videos li .img a img");
	//photoimageResize("body#group_detail_4476 #photo_thumbnail-2944064.photo_thumbnail .photos li .img a img");
	photoimageResize("body#group_detail_4476 #photo_thumbnail-2944065.photo_thumbnail .photos li .img a img");
	photoimageResize("body#group_detail_4476 #photo_thumbnail-2944063.photo_thumbnail .photos li .img a img");
	photoimageResize("body#group_detail_4476 #photo_thumbnail-2752818.photo_thumbnail .photos li .img a img");
	newphotoimageResize("body.angelsphotocategories .photo_thumbnail .photos li .img a img ");
	
	var thumbLength = $('.angelsphotocategories .photo_thumbnail .photos li').length;		
	for(var j=0; j<= thumbLength; j++){
		var homeblogcomment = $('.angelsphotocategories .photo_thumbnail .photos li:nth-child('+j+') .img a');		
		$('.angelsphotocategories .photo_thumbnail .photos li:nth-child('+j+') .img a img').insertBefore(homeblogcomment);
	}
	
	if ($("body#community_landing").length == 0) {
		$('.photo_thumbnail li.photo').each(function(){
			for (count = 0; count < PhotoFCCategories.length; count++) {
				$(".photo_thumbnail li." + PhotoFCCategories[count] + ".photo").addClass("fanClub");
			}
		});
		$('.photo_thumnail li.photo').each(function(){
			for (count = 0; count < PhotoFCCategories.length; count++) {
				$(".photo_thumnail li." + PhotoFCCategories[count] + ".photo").addClass("fanClub");
			}
		});
	}
	
	
	//Badges implementation in pagination	
	$(".badges ul").each(function(){	
		if ($(this).find("li").length > 0) {	
			$(this).html('<li class="badge"><a class="badgeImageReplace" href="/group/treys-angels/"></a></li>');
		}
	});

	/* --------------------- 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);
	}
	
	/*Trey's Angels - Blog styling - starts*/
	
	/* Home page */
	/*
	var blogLength = $('#blog_listing-350371.blog_listing .module ul.articles li.article').length;		
	for(var j=0; j<= blogLength; j++)
	{			
			
			var blogContent = $('#blog_listing-350371.blog_listing .module ul.articles li.article.category_36491:nth-child('+j+')');
			
			if (blogContent && blogContent.length != 0) {
				
				var blogimg = $('#blog_listing-350371.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .img');
				var blogtitle1 = $('#blog_listing-350371.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .title');
				var blogauthor = $('#blog_listing-350371.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .author');
				var blogdate = $('#blog_listing-350371.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .date');
				var blogdesc = $('#blog_listing-350371.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .description');
				var blogactivity = $('#blog_listing-350371.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .activity');
				var blogretweet = $('#blog_listing-350371.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .retweet_me');
				var blogfb = $('#blog_listing-350371.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .fb_like');
				var bloggplus = $('#blog_listing-350371.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .gPlus');
				var blogtumblr = $('#blog_listing-350371.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') #tumblr_button_abc123');
				var blogtools = $('#blog_listing-350371.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .tools');
				var blogcategory1 = $('#blog_listing-350371.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .category');
					
				var blogwrapper = $('<div class="treyangelsblog"></div>');
				var blogLength = blogdesc.text().trim().length > 200 ? 200 : blogdesc.text().trim().length; 
				var blogheadwrapper = $('<div class="treyangelsbloghead"></div>');
				blogheadwrapper.append(blogimg);
				blogheadwrapper.append(blogtitle1);
				blogheadwrapper.append(blogauthor);
				blogheadwrapper.append(blogdate); 
				blogwrapper.append(blogheadwrapper);
				blogdesc.html(blogdesc.text().trim().substring(0, blogLength) + "... " + '<a class="readmore" href="'+ blogtitle1.find("a").attr("href") +'">Read More</a>');
				
				blogwrapper.append(blogdesc);
				blogwrapper.append(blogactivity);
				blogwrapper.append(blogfb);
				blogwrapper.append(bloggplus);
				
				blogContent.append(blogwrapper);
			}
			
		$('#home .blog_listing .module .body .article.category_36491').css('display','block');
		
	}
	*/

	
	
	
	/* Blog page */
	/*
	var blogLength1 = $('#blog_listing-350370.blog_listing .module ul.articles li.article').length;		
	for(var j=0; j<= blogLength1; j++)
	{			
			
			var blogContent = $('#blog_listing-350370.blog_listing .module ul.articles li.article.category_36491:nth-child('+j+')');
			
			if (blogContent && blogContent.length != 0) {
				var blogimg = $('#blog_listing-350370.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .img');
				var blogtitle1 = $('#blog_listing-350370.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .title');
				var blogauthor = $('#blog_listing-350370.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .author');
				var blogdate = $('#blog_listing-350370.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .date');
				var blogdesc = $('#blog_listing-350370.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .description');
				var blogactivity = $('#blog_listing-350370.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .activity');
				var blogretweet = $('#blog_listing-350370.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .retweet_me');
				var blogfb = $('#blog_listing-350370.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .fb_like');
				var bloggplus = $('#blog_listing-350370.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .gPlus');
				var blogtumblr = $('#blog_listing-350370.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') #tumblr_button_abc123');
				var blogtools = $('#blog_listing-350370.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .tools');
				var blogcategory1 = $('#blog_listing-350370.blog_listing .module ul.articles li.article.category_36491:nth-child(' + j + ') .category');
				
			var blogwrapper = $('<div class="treyangelsblog"></div>');
				var blogLength = blogdesc.text().trim().length > 200 ? 200 : blogdesc.text().trim().length; 
				var blogheadwrapper = $('<div class="treyangelsbloghead"></div>');
				blogheadwrapper.append(blogimg);
				blogheadwrapper.append(blogtitle1);
				blogheadwrapper.append(blogauthor);
				blogheadwrapper.append(blogdate);
				blogwrapper.append(blogheadwrapper);
				blogdesc.html(blogdesc.text().trim().substring(0, blogLength) + "... " + '<a class="readmore" href="'+ blogtitle1.find("a").attr("href") +'">Read More</a>');
				blogwrapper.append(blogdesc);
				blogwrapper.append(blogactivity);
				blogwrapper.append(blogretweet);
				blogwrapper.append(blogfb);
				blogwrapper.append(bloggplus);
				blogwrapper.append(blogtumblr);
				blogwrapper.append(blogtools);
				blogwrapper.append(blogcategory1);
				
				blogContent.append(blogwrapper);
			}
			
		$('#blog .blog_listing .module .body .article.category_36491').css('display','block');
		
	}
			*/
	/*Trey's Angels - Blog styling - ends*/


	$("ul.articles li.article").each(function(){
		if($(this).find(".activity .comment").html()!=null){
			var blogComment = $(this).find(".activity .comment").html().replace("Comments", "").replace("Comment", "").replace(")", "").replace("(", "").trim();
			if(blogComment == "1"){
				$(this).find(".activity .comment").html(blogComment + " Comment");
			}
			else{
				$(this).find(".activity .comment").html(blogComment + " Comments");
			}
		}	
	});

	
	$(".blog_listing .module .content li.article a.comment").css('display','block');
	
	$("#community_landing .discussion_listing .module .content .topics li.topic").each(function(){  		
		if($(this).hasClass("category_38131")){			
				var discavatar=$(this).html();
				var discussiontweak = '<div class="disctreyAngel clearfix" >'+discavatar+'</div>';			
			($(this)).html(discussiontweak);
		}
	});
	$("#discussion .discussion_listing .module .content .topics li.topic").each(function(){  		
		if($(this).hasClass("category_38131")){			
				var discavatar=$(this).html();
				var discussiontweak = '<div class="disctreyAngel clearfix" >'+discavatar+'</div>';			
			($(this)).html(discussiontweak);
		}
	});
	
	$(".discussion_listing .module .content").css("display","block");
	eoscInitCallback();
	
	// plus one button generation code 
	window.___gcfg = {
			lang: 'en-US'
		};
		(function(){
			var po = document.createElement('script');
			po.type = 'text/javascript';
			po.async = true;
			po.src = 'https://apis.google.com/js/plusone.js';
			var s = document.getElementsByTagName('script')[0];
			s.parentNode.insertBefore(po, s);
		})();
		
		
		$('#group_detail_4476 .articles li.article').each(function(){
var tweet = $(this).find('.twitter-share-button');
var fb = $(this).find('.fb_like');
tweet.insertBefore(fb);
});
}

// 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 */

	/* Start - Changes for Twitter Opt In Functionality */
	
	/* Convert the value from true to Y and false to N */
	function setTwitterOptIn(elem){
        if (elem.checked == true){
           document.getElementById("BirthdayOffersOptin").value = 'Y';
        }else {
           document.getElementById("BirthdayOffersOptin").value = 'N';
        }
	}

	$(document).ready(function(){
	    /* Convert OptIn Check box values to required format. - true/false ==> Y/N */		
		var twitterCheckElement = document.getElementById('cmsgData[IdList][1520]');
		if (twitterCheckElement !== null){
			setTwitterOptIn(twitterCheckElement);
			$('#cmsgData\\[IdList\\]\\[1520\\]').click(function(){
			   setTwitterOptIn(this);
			})
		}
		
		/* Setting up the DOB cookie in the sign-up page.*/
		if ($("body#sign_up").length > 0) {
			$("#submit").click(function(){
				var birthDateStamp = $("#cmsgData\\[month\\]").val()+"/"+$("#cmsgData\\[day\\]").val()+"/"+$("#cmsgData\\[year\\]").val();
				var date = new Date();
				date = date.setTime(date.getTime() + (2 * 24 * 60 * 60 * 1000));
				$.cookie("dob",birthDateStamp,{expires:date,path:'/'});
			})
		}
		
		/*Reading the DOB cookie and setting it in an input element in footer.*/
		if ($("body#join").length > 0){
			var dateOfBirth = $.cookie("dob") ;
			if (dateOfBirth != null){
				$("#dateOfBirth").val(dateOfBirth);
				//$.cookie("dob",null);
			}
		}
		
		/* Edit Profile page, set up twitter heading */	
		if ($("#edit_profile").length > 0) {
		var tweetbdaytxt='<li class="input text" id="bdayremndr" style="overflow:visible"><h2 id="birthday-tweet-settings">Birthday Tweet Settings</h2><div id="tweetdaytxt">Check off the box below and fill in your Twitter screen name, and Trey will send you a tweet on your birthday. Only available to members of Trey\'s Angels. (Not a member? <a href="/become-a-member/">Join now</a>)</div></li>';
		$("#cmsgData\\[IdList\\]\\[1520\\]").parent().before(tweetbdaytxt);
		}
		
	
	});
	
function truncateContent(selector,truncLength) {
	$(selector).each(function(){
		var trunc = (this).innerHTML;	
		if (trunc.length > truncLength) {
			trunc = trunc.substring(0, truncLength);
			trunc += '<span>' + '...</span>';
			(this).innerHTML = trunc;
		}	
	})	
}

