/* 
 * 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 prvteCont="<i class='prText'>&nbsp;&nbsp;</i>";

/*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">{merchPrice}</a></div>\
				</div>\
				<!-- HOVERCARD -->\
		</li>';

/* Templates for the Hovercard module.*/
var	merchHCTemplate ='<div class="merchHC merchHC{index}">\
							<div class="merchHCWrapper">\
								<div class="merchHCInnerWrapper">\
									<div class="merchHCHead"><a href="{omnitureLinksHTitle}">{merchTitle}</a></div>\
									<div class="merchHCBody">\
										<div class="merchHCLeftCon"><a href="{omnitureLinksHThumb}"><img src="{merchImage}" width="230px"/></a></div>\
										<div class="merchHCRightCon">\
											<h3 class="merchHCPrice">{merchPrice}</h3>\
											{merchDesc}\
											{merchSizes}\
											<div class="merchHCBuyNowCon"><a class="merchHCBuyNow" href="{omnitureLinksHButton}">Buy Now &raquo;</a></div>\
										</div>\
										<div class="clear"></div>\
									</div>\
									<div class="merchHCFoot"></div>\
								</div>\
							</div>\
						</div>';
			
var merchCountryTemplate = '<li><a class="flag {countryName}" href="{countryLink}" target="_new">{countryText}</a></li>';
var merchHeaderTemplate = '<div class="{positionClass}">\
						   		<div class="visitStore">\
									<a class="visitStoreLink" href="{merchViewAllLink}" rel="external" target="_new">Visit Artist Store</a>\
									<ul style="display: none;" class="visitStoreFlyout">\
										<!-- MERCH COUNTRIES -->\
									</ul>\
								</div>\
						   </div>';
						   
$(document).ready(function(){
	
	$("html").addClass($.os.name);
	$("body").addClass($.browser.className);
    $("body").addClass($.browser.name);
	
	/* ******************** Tour page modifications starts ******************** */
 
		var clearDivEle='<div class="clear"></div>';
	var horzDivdr='<div class="hd"></div>';
	var currentPageShowUrl=$.urlParam("show");
	var prvteCont="<i class='prText'>&nbsp;&nbsp;</i>";
var prvtLegend='<span class="private">Visible only to site adminstrators</span>';
$('.edit_account li.input.annotation').append(prvtLegend);
  
 
/* Homepage read more button in blog fix */
$('#home .blog_listing .articles li.article').each(function(){
	$(this).find('.description a').each(function(){
		if($(this).text().trim().toUpperCase() == "READ MORE"){
			$(this).addClass('blogreadmore');
			}
	})		
});



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="Past shows";
						
		$('#event-707479.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 .input.going');
			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>";
			var backtoupcoming="<div class='nav_meta'><ul><li class='more'><a></a></li></ul></div>"; 
			var viewarchive="<div class='viewevents'><a class='viewpix' href='/past-shows/'>View past shows</a></div>";
				$('#event_listing-3995366 .foot').append(viewarchive);
			
			$(this).find('.head .title').append(backtoupcoming);
			$(this).find('.nav_meta ul li.more a').html('All past shows');
			$(this).find('.nav_meta ul li.more a').attr("href","/past-shows/");
			$(eventDate).insertBefore('#event-707479.event .cal_event div.txt .location .city');	
			
			$(this).find('.cal_event').append(descEle);
			$(this).find('.cal_event').append(clearDivEle);	
			$(clearDivEle).insertAfter('#event-707479.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().trim();
			if(($(this).find('.cal_event .tools .input.going a').attr('onclick')!=null && eventsuccessmsg.toUpperCase()=="I DIDN'T GO")||($(this).find('.cal_event .tools .input.going a').attr('onclick')!=null && eventsuccessmsg.toUpperCase()=="I'M 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 Shows";
		$('#event-707479.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 .input.going');
			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').html()+"</div>";
			var toolsData="<div class='tools'></div>";
			var backtoarchive="<div class='nav_meta'><ul><li class='more'><a></a></li></ul></div>"; 
			var viewupcoming="<div class='viewevents'><a class='viewpix' href='/shows/'>View upcoming shows</a></div>";
			$('#event_listing-3301618 .foot').append(viewupcoming);
			$(this).find('.head .title').append(backtoarchive);
			$(this).find('.nav_meta ul li.more a').html('All upcoming shows');
			$(this).find('.nav_meta ul li.more a').attr("href","/shows/");
			$(eventDate).insertBefore('#event-707479.event .cal_event div.txt .location .city');	
					
			$(this).find('.cal_event').append(mapEle);
			$(clearDivEle).insertAfter('#event-707479.event .cal_event div.txt');
			$(buyLnk).insertAfter('#event-707479.event .cal_event div.clear');
			
			$(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').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'M 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('.foot .nav_meta ul li.buy').remove();
			$(this).find('.cal_event div.txt .availability').remove();
			//$(this).find('.foot .nav_meta ul li.buy').remove();
		});		
	}
}  	


/*
 var venuelocationupload=$('#event-707479.event .module .upcoming .body .cal_event div.txt .venue .val').text();
 if (venuelocationupload != null && venuelocationupload.length > 0) {
 	var uploadhref = $('#photo_thumbnail-4030005 .head .nav_meta ul li.new a').attr("href");
 	uploadhref = uploadhref + "&venuenameinfo=" + venuelocationupload;
 	$('##photo_thumbnail-4030005 .head .nav_meta ul li.new a').attr("href", uploadhref);
 	var uploadhref = $('#video_thumbnail-4030006 .head .nav_meta ul li.new a').attr("href");
 	uploadhref = uploadhref + "&venuenameinfo=" + venuelocationupload;
 	$('#video_thumbnail-4030006 .head .nav_meta ul li.new a').attr("href", uploadhref);
 }
*/
/*
 if($('body#upload').length >0){
 	var venuenameinfo=$.urlParam("venuenameinfo");
	if(venuenameinfo.length >0){
		writeToConsole("venuenameinfo"+venuenameinfo);
		$('.media_upload .module .content .head h3 span').text(" - "+decodeURI(venuenameinfo));
	}
 }
*/

	var memGoing2="Fans Going ";
	$('#event_listing-3301618.event_listing ul.cal_events li.cal_event').each(function(){
		var attendeeCount= $(this).find('.attendee_count').html();
		var buyBtn= $(this).find('.buy');
		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();
			
			if(attendeeCount=='0' || attendeeCount=="1"){memGoing2="Fan Going";}
			var member_det='<div class="member_details"><div class="membrGoing"><a href="'+eventPath+'">'+ attendeeCount +" "+ memGoing2 +'</a></div></div><div class="moreinfo"><a class="viewmoreinfo" href="'+eventPath+'">More info</a></div>';
			
			$(this).find('.txt').append(member_det);			
		}else{
			var member_det='<div class="moreinfo"><a class="viewmoreinfo" href="'+eventPath+'">More info</a></div>';
			$(this).find('.txt').append(member_det);
		}
			
	});
	
				
	if($('body#event').length >0 || $('body#event_detail').length >0 ){	
		var currentpageshow=$.urlParam("show");
		
		if ($('body').attr('id') == 'event_detail') {
			if (currentpageshow == "archive" || offsetdays < -1 ) {
				
				if($('#event-707479 .tools .input.going a').length >0){
				$('#event-707479 .tools .input.going a').text("I Went");
				}
				$('#photo_thumbnail-4030005').css("display", "block");
				$('#video_thumbnail-4030006').css("display", "block");
				$('#event_listing-3995366').css("display", "block");
				$('#event_listing-3301618').css("display", "none");
				}
			else {
				if($('#event-707479 .tools .input.going a').length >0){
				$('#event-707479 .tools .input.going a').text("I am Going");
				}
				$('#photo_thumbnail-4030005').css("display", "none");
				$('#video_thumbnail-4030006').css("display", "none");
				$("#event-707479 .module .body .cal_event .rating").css("display","none");
				$('#event_listing-3995366').css("display", "none");
				$('#event_listing-3301618').css("display", "block");
				 }
		}
	}
	
		
	$('.event_listing ul.cal_events li.cal_event .buy ul li' ).each(function(){
		var viplink= $(this).find('a').text();
			if(viplink.indexOf("VIP")!= -1 || viplink.indexOf("VIP Access")!= -1){
				$(this).addClass("vipLink");
			}
	});
	
	var fansWent=" Fans Went";
		$('#event_listing-3995366.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');
			eventPath=eventPath+"?show=archive";
			$(this).find('.txt .date h4 a').attr('href',eventPath);
			$(this).find('.attendee_count').remove();
			$(this).find('.buy').remove();
			var viewEveMedia="<div class='viewMedia'><a class='viewpix'>View Photos and videos</a></div>";
             $(viewEveMedia).insertBefore($(this).find('.txt .date'));
			$(this).find('.viewMedia a').attr('href',eventPath);

			var venueact=$(this).children('.txt').children('.venue');
			$(this).children('.txt').append(venueact);
			if(attendeeCount!=null && attendeeCount!=""){
				attendeeCount=attendeeCount.substring((attendeeCount.lastIndexOf(":")+1),attendeeCount.length).trim();
				if(attendeeCount=='0' || attendeeCount=="1"){fansWent="Fan Went";}
				var member_det='<div class="fan_details"><div class="fanWent"><a href="'+eventPath+'">'+ attendeeCount +" "+ fansWent +'</a></div></div><div class="moreinfo"><a class="viewmoreinfo" href="'+eventPath+'">More info</a></div>';
				$(this).find('.txt').append(member_det);			
			}else{
			var member_det='<div class="moreinfo"><a class="viewmoreinfo" href="'+eventPath+'">More info</a></div>';
			$(this).find('.txt').append(member_det);
		}
			
			var eventPath=  $(this).find('.txt .date h4 a').attr('href');
			var venuename= $(this).find('.venue').text();
 var venueDiv='<div class="venue"><a class="venueLink">'+venuename+'</a></div>';
 				
	});
	
	$('#event-707479.event .module .upcoming .body .cal_event div.buyLink ul li' ).each(function(){
		var viplink= $(this).find('a').text();
			if(viplink.indexOf("VIP")!= -1){
				$(this).addClass("vipLink");
			}
	});
			
			
var memberGoing="Fans Went";
	var memberCount= $('#member_listing-4006500.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-707479.event .module .cal_event div.txt div.date').text();
	var eventdateobj = new Date(eventdate);
	currentDate = new Date();
	offset = eventdateobj.getTime() - currentDate.getTime();		
	offsetdays=offset/ 86400000;  
	var currentpageshowtitle=$.urlParam("show");
	if(currentpageshowtitle=="archive" || offsetdays < -1){
		if(memberCount=='0' || memberCount=="1"){memberGoing="Fan Went";}
	var memberClass='<div class="membersGoing">'+memberGoing+":" + " " +'<span class="membercount"></span></div>';	
	$('#member_listing-4006500.member_listing .module .content .head h3').html(memberGoing+'<span class=\"total\">('+memberCount+")</span>");
	}
	else{
		var memberGoing="Fans Going";
		
		if(memberCount=='0' || memberCount=="1"){memberGoing="Fan Going";}
	var memberClass='<div class="membersGoing">'+memberGoing + ":" + " " +'<span class="membercount"></span></div>';
	$('#member_listing-4006500.member_listing .module .content .head h3').html(memberGoing+'<span class=\"total\">('+memberCount+")</span>");
	}	
	$(memberClass).insertAfter($('#event-707479.event .module .content .body .cal_event .tools .input.going'));
	if(memberCount !=null && memberCount !=" ");{
		
		$("#event-707479.event .module .content .body .cal_event .tools .membersGoing span.membercount").text(memberCount);
	}
	
		if ($('body').attr('id') == 'event_detail') {
			if (currentpageshow == "archive" || offsetdays < -1) {
				$('#member_listing-4006500.member_listing .module .content .head h3 .total').css("margin-left", "10px");
				
			}
		}
	
	var detailPageUrl = window.location.href;
//event_detail
 
//$.wmgfeature.tweetmeme("#event-707479.event .body .cal_event", null, null, detailPageUrl, ".input.going", null);
//$.wmgfeature.facebookLike("#event-707479.event .body .cal_event", null, null, detailPageUrl, ".input.going", null);
	
	
	//event detail page
	
/*
var uploadphotos='<div class="nav_meta"><ul><li class="new"><a href="/upload">UPLOAD PHOTOS</a></li></ul></div>';
$('#photo_thumbnail-3783998 .module .content .head .title').append(uploadphotos);
var uploadvideos='<div class="nav_meta"><ul><li class="new"><a href="/upload">UPLOAD VIDEOS</a></li></ul></div>';
$('#video_thumbnail-3783999 .module .content .head .title').append(uploadvideos);	

*/
/*
var venuelocationupload=$('#event-707479.event .module .archive .body .cal_event .description').html();
 if (venuelocationupload != null) {
 	if (venuelocationupload.length > 0) {
 		uploadhref = "/upload/" + "&venuenameinfo=" + venuelocationupload;
 		$('#photo_thumbnail-4030005 .head .nav_meta ul li.new a').attr("href", uploadhref);
 		var uploadhref = $('#video_thumbnail-4030006 .head .nav_meta ul li.new a').attr("href");
 		uploadhref = "/upload/" + "&venuenameinfo=" + venuelocationupload;
 		$('#video_thumbnail-4030006 .head .nav_meta ul li.new a').attr("href", uploadhref);
 	}
 }
 if($('body#upload').length >0){
 	var venuenameinfo=$.urlParam("venuenameinfo");
	if(venuenameinfo.length >0){
		writeToConsole("venuenameinfo"+venuenameinfo);
		$('.media_upload .module .content .head h3 span').text(" - "+decodeURI(venuenameinfo));
	}
 }
*/


$('#event-707479.event .upcoming .body div.cal_event').each(function(){
	var inputLink= $(this).find('div.input.going');
	$(this).find('div.input.going').remove();
		
	if(inputLink!=null && inputLink!=""){
		$(this).find('.tools').append(inputLink);
		$(inputLink).insertBefore($(this).find('.tools .membersGoing'));
	}
});
if ($('body').attr('id') == 'tour_dates' || $('body').attr('id') == 'home') {
				var viewupcoming="<div class='viewevents'><a class='viewpix' href='/shows/'>View upcoming shows</a></div>";
				$('#event_listing-3301618 .foot').append(viewupcoming);
			}
if ($('body').attr('id') == 'event') {
				var viewarchive="<div class='viewevents'><a class='viewpix' href='/past-shows/'>View past shows</a></div>";
				$('#event_listing-3995366 .foot').append(viewarchive);
			}
				
$('#event-707479.event .body div.cal_event').each(function(){
	var buyBtnLink= $(this).find('.buyLink');
	$(this).find('.buyLink').remove();
		
	if(buyBtnLink != null && buyBtnLink!="" && ($(buyBtnLink).text())!="null"){		
			$(this).find('.txt').append(buyBtnLink);
			$(buyBtnLink).insertAfter($(this).find('.txt'));		
	}
});
		
	/* ******************** Tour page modifications ends ******************** */

	
var maxCount =15;
  
	$('#rss_content-2477091 .csCell').each(function(){
		var cellstreamTitle=$(this).find(".text").text();
		var actCount=cellstreamTitle.length;
		var newCSTitle="";
		if(actCount>maxCount){
			newCSTitle=(cellstreamTitle.substring(0,14))[0] + "...";
			$(this).find(".text").append(newCSTitle);
			$(this).find(".text").attr('title',cellstreamTitle);
		}	
	});


// Add the word 'on' to the author;
//$('.articles li .author, div.article .author').append(' on');

if( $("#TB_window", window.parent.document).length == 0 ) {
	$("body.m32 #container").css("margin-top","20px", "!important" );
}
	
$("#member_listing-2517019.member_listing .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","320");
			$(this).attr("height","320");
			var avatarAncStyle="display:block !important;width:320px !important;height: 320px !important;";
			var avatarImgStyle="display:block !important;width:320px !important;height: 320px !important;cursor:pointer !important;";
			$(this).parent().attr("style",avatarAncStyle);
			$(this).attr("style",avatarImgStyle);
			var avatarDivStyle="background:transparent url("+photoImageSrcNew+") no-repeat 0px 0px;width:320px;height:320px;";
			$(this).parent().parent().attr("style",avatarDivStyle);
	}
	
});

    /* Suppresses display of empty footers on IE */
    $('.module .foot:empty').addClass('empty');
	$('#rss_in-327532 .module .content .foot').removeClass('empty');
	$('#html-683925.html .module .content .foot').removeClass('empty');
	$('#rss_in-2477091.rss_in .module .content .foot').removeClass('empty');
	
	$("#song_playlist-348671.song_playlist .playlist .info li.xs .img a").each(function(){    	
		
			/* Disabling anchor tag  - Start*/
			$(this).attr("href","javascript:void(0)");
			/* Disabling anchor tag  - End*/						

	});

	
	
	$('#join-294550.join .annotation span.private').each(function(){
		var cont = (this).innerHTML;		
		(this).innerHTML= prvteCont+cont;
	})
	
	$('#join-294550.join li.input.private').each(function(){
		var liCont = (this).innerHTML;		
		(this).innerHTML= liCont+prvteCont;
	})		
	/*
	$( 'div.article div.meta div.category ul li a').each(function(){
		$(this).attr({
	  href: 'javascript:void(0);',
	  style: 'cursor:default'});
	});		
	
	$( 'ul.articles li.article div.category ul li a').each(function(){	   		
		$(this).attr({
	  href: 'javascript:void(0);',
	  style: 'cursor:default'});
	});
	*/
		

    /* 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=368,height=270,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*=amazon.com]').attr("rel", "external");
    
    if (location.href.indexOf("/music/") != -1) {
        $("a[href^=/album/]").parent(".nav-custom").addClass("active");
        
    }
    
    if (location.href.indexOf("/album/") != -1) {
        $("a[href^=/album/]").parent(".nav-custom").addClass("active");
    }	
	var $customNavs = $('.nav_main ul li.nav-custom a');

	$customNavs.filter(function(){
		  return (/^Store$/i).test($(this).text())
		}).parent()
    	  .addClass('nav-custom')		 
		  .addClass('nav-store')
		  .addClass('dropdown')
		  .append(storeSubNav);
		  
		  $customNavs.filter(function(){
	  return (/^Music/i).test($(this).text())
	}).parent()
  	  .addClass('nav-custom')
	  .addClass('nav-music');

      var communityNavCell = $(".nav_main ul li.nav-community_landing"); //change this selector to target a diffent cell in the top nav
  	  communityNavCell.addClass('dropdown');
	  
	  if (typeof(communitySubNav)!="undefined") {
	  	communityNavCell.append(communitySubNav);
		
	  }
	  
	  
	  if (location.href.indexOf("/forums/") != -1) {
        communityNavCell.addClass("active");
        $("#discussionsNav").addClass("active");
    }
    if (location.href.indexOf("/ringtones/") != -1) {
        storeNavCell.addClass("active");
        $("#ringtonesNav").addClass("active");
    }
		
	 if (location.href.indexOf("/community_landing/") != -1) {
        communityNavCell.addClass("active");
        $("#communityHomeNav").addClass("active");
    }
	if (location.href.indexOf("/member/") != -1) {
	if(!(location.href.indexOf("/category/member/")!=-1)){
		communityNavCell.addClass("active");
         	$("#memberNav").addClass("active");
	}         
    }
	
	var tourSubNav = '<ul class="flyoutMenu" id="tourSubNav" style="display:none">\
		<li id="upcomingNav"><a href="/shows/">Upcoming Shows</a></li>\
		<li id="archiveNav"><a href="/past-shows/">Past Shows</a></li></ul>';
		
		
   	  var tourNavCell = $(".nav_main ul li.nav-event");
	  tourNavCell.addClass('dropdown');
	   if (typeof(tourSubNav)!="undefined") {
	  	tourNavCell.append(tourSubNav);
		  }
 	  
	  
	  if (location.href.indexOf("/shows/") != -1) {
        tourNavCell.addClass("active");
        $("#upcomingNav").addClass("active");
    }
	
	if (location.href.indexOf("/past-shows/") != -1) {
        tourNavCell.addClass("active");
        $("#archiveNav").addClass("active");
    }
	
	
    /* ********** Merch module code ********* */
	$('#merchContainer').parent(".description").parent(".body").siblings(".head").addClass("clearfix");				
		$('#merchContainer').parent(".description").parent(".body").siblings(".head").children("h3").css({'border':'none','font-size':'25px'});				
	$('#merchContainer').parent(".description").parent(".body").siblings(".head").css({'position': 'relative','z-index': '100'});
	$('#merchContainer').parent(".description").parent(".body").siblings(".foot").css({'z-index': '98','overflow': 'visible'});
	$('#merchContainer').parent(".description").parent(".body").css({'position': 'relative','clear': 'both','z-index': '99'});

	var	visitStorehead = $('#merchContainer').parent(".description").parent(".body").siblings(".head");
	$('#merchContainer .merchHead').appendTo(visitStorehead);

	var	visitStoreFoot = $('#merchContainer').parent(".description").parent(".body").siblings(".foot");
	$('#merchContainer .merchFoot').appendTo(visitStoreFoot);
	
	var	twitterhead = $('#html-683925.html .module .content .foot');
	$('#html-683925.html .module .content .body .follow a').appendTo(twitterhead);
    
	$(".nav_main ul li.nav-community_landing").hover (
		function() { $(".flyoutMenu", this).show(); },
		function() { $(".flyoutMenu", this).hide(); }		
	);
	
	$(".nav_main ul li.nav-store").hover (
		function() { $(".flyoutMenu", this).show(); },
		function() { $(".flyoutMenu", this).hide(); }		
	);

	$('#merchContainer').parent(".description").parent(".body").siblings(".foot.empty").addClass("emptyfix");
    
    /* START: Merch module drop-downs */
	$(".merchHead .visitStore").hover (
			function() { $(".visitStoreFlyout", this).show(); },
			function() { $(".visitStoreFlyout", this).hide(); }
		);
	$(".merchFoot .visitStore").hover (
		function() { $(".visitStoreFlyout", this).show(); },
		function() { $(".visitStoreFlyout", this).hide(); }		
	);
	$(".firstitem .merchBuy").hover (
		function() { $(".merchBuyFlyout", this).show(); },
		function() { $(".merchBuyFlyout", this).hide(); }		
	);
	$(".seconditem .merchBuy").hover (
		function() { $(".merchBuyFlyout", this).show(); },
		function() { $(".merchBuyFlyout", this).hide(); }		
	);
	$(".thirditem .merchBuy").hover (
		function() { $(".merchBuyFlyout", this).show(); },
		function() { $(".merchBuyFlyout", this).hide(); }		
	);
    /* END: Merch module drop-downs */
    
	
	if($("#sign_up-294578 li.input input").attr('class')== "focused"){		
		$descriptionDisplay = $("#sign_up-294578 li.input input.focused").parent().contents().filter(".message").children();
		if ($descriptionDisplay.css("display") == "inline" ||$descriptionDisplay.css("display") == "none"  ){
			$descriptionDisplay.css("display","block");
		}
	} 
	
	$("#sign_up-294578 li.input input").click( function() {
		// In this check for the corresponding description div. 		
		 $descriptionDisplay = $(this).next().filter(".message").children();
		if ($descriptionDisplay.css("display") == "inline"){
			$descriptionDisplay.css("display","block");
		}
	});
	
	$("#sign_up-294578 li.select input").click( function() {
		// In this check for the corresponding description div. 
		$descriptionDisplay = $(this).parent().contents().filter(".message").children();
		if ($descriptionDisplay.css("display") == "inline"){
			$descriptionDisplay.css("display","block");
		}
	});
	
	//adding upload button
	
	/*
	$uploadlink = $('#nav_main-294563.nav_main ul li.upload');
	$uploadlink.insertBefore('#html-327535 .description .commLinks');
    $('#nav_main-294563.nav_main ul li.upload').css("display", "block");
    */
	
	/* Fixing the target for the myspace link */
    $(".nav_main ul li a[href^=http://www.myspace.com/]").attr("target", "_new");

   /* Make rel="external" links open in a new window */
    $("a[rel=external]").attr("target", "_new");
	
		
	/* Fixing the target for the Street Team link */
    $("#FooterLinks1 ul li a.streetteam").attr("target", "_new");
	
    /* Fixing the target for the digg link */
    $(".shareweb .digg a").attr("target", "_new");
    
    /* 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");
    
    // Functionality for add new blogs.
    $(".blog_listing .nav_meta .more a").bind("click", function(e){
		$.cookie("blog_body", blogTwitterBlurbText, {
            path: "/"
        });
    });
	if ($("body").attr("id") == "add_new_blog") {        
        $.cookie("blog_body", blogTwitterBlurbText, {
            path: "/"
        });
    }

	/*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>');
				}
			}					
		});	
		
	/*End - code which obfuscates email addresses #2420*/	
	
    //Album detail stuff 
    $buylinks = $('#album_info-383751 .foot .nav_meta ul');
    $buylinks.insertBefore('#album_info-383751 .album .txt div.description');
    $('#album_info-383751.album_info .module .content .foot .nav_meta ul').css("display", "block");
	
	
	$("#video_thumbnail-2495090.video_thumbnail .videos 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","265");
			$(this).attr("height","180");
			var avatarAncStyle="display:block !important;width:265px !important;height: 180px !important;";
			var avatarImgStyle="display:block !important;width:265px !important;height: 180px !important;cursor:pointer !important;";
			$(this).children("a").attr("style",avatarAncStyle);		
			$(this).attr("style",avatarImgStyle);							
	}
	});
	
	$("#photo_thumbnail-2495091.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","175");
			$(this).attr("height","175");
			var avatarAncStyle="display:block !important;width:175px !important;height: 175px !important;";
			var avatarImgStyle="display:block !important;width:175px !important;height: 175px !important;cursor:pointer !important;";
			$(this).children("a").attr("style",avatarAncStyle);		
			$(this).attr("style",avatarImgStyle);
	
								
	}
	});

    
    //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(); 	
	
    
	/* Fix for 9256 */
var childCell=$('.msie8#edit_profile .edit_profile .title .nav_meta');
var parentCell=$('.msie8#edit_profile .edit_profile .body');
  if (typeof(childCell)!= 'undefined'){
  	parentCell.prepend(childCell);
  }
  /* End Fix for 92568 */ 
  
});

function eoscInit(){
$('.csCell').each(function(){
if($(this).find('.text').attr('title').length != 0){
var insto = $(this).find('.text').attr('title');
$(this).find('.image a').attr('title',insto);
}
else{
var insto = $(this).find('.text').text();
$(this).find('.image a').attr('title',insto);
}
});
	
	$('#lovestrong #photo_thumbnail-4950340 li.photo').each(function(){	
	  var comment=$(this).find('.txt .comments').text().trim();
	  if (comment.indexOf("(") == -1) {
	  	comment = "(" + comment + ")";
	  	$(this).find('.txt .comments').text(comment);
	  }
	   	var viewcount="Views"
		var view= $(this).find('.txt .views').text();
		var viewno= $(this).find('.txt .views span.val').text();
		if(viewno=='1'){viewcount="view";}
		$(this).find('.txt .views').remove();
		var views='<div class="views"><span class="val">'+viewno+'</span>'+" "+viewcount+'</div>';
		$(views).insertAfter($(this).find('.txt .author'));
	});
	$('#lovestrong #video_thumbnail-4950341 li.video').each(function(){	
	 var comment=$(this).find('.txt .comments').text().trim();
		if (comment.indexOf("(") == -1) {
	  	comment = "(" + comment + ")";
	  	$(this).find('.txt .comments').text(comment);
	  }
	    var viewcount="Views"
		var view= $(this).find('.txt .views').text();
		var viewno= $(this).find('.txt .views span.val').text();
		if(viewno=='1'){viewcount="view";}
		$(this).find('.txt .views').remove();
		var views='<div class="views"><span class="val">'+viewno+'</span>'+" "+viewcount+'</div>';
		$(views).insertAfter($(this).find('.txt .author'));
	});
	


/* adding home page social buttons on pagination - Starts */	
		var listing='moduleListing';	
		if ($('body').attr('id') == "home") {
		var twtrScript=document.createElement('script');
		twtrScript.type = 'text/javascript';
		twtrScript.src = "http://platform.twitter.com/widgets.js";
		$(".blog_listing").append(twtrScript);
		
		var twitterObj = {
			blockSelector: '#home .articles li.article',
			insertionSelector: '.category',
			siteUrl: 'http://www.christinaperri.com',
			urlSelector:'.title h4 a',
			viaParam: '&amp;via=christinaperri',
			relatedParam: '&amp;related=christinaperri',
			fanclubviaParam: '&amp;via=christinaperri',
			fanclubrelatedParam: '&amp;related=christinaperri,christinaperri'
		}
		var fbLikeObj = {
			blockSelector: '#home .articles li.article',
			insertionSelector: '.category',
			urlSelector:'.title h4 a',
			siteUrl: 'http://www.christinaperri.com'
		}
		var fbShareObj = {
			blockSelector: '#home .articles li.article',
			insertionSelector: '.category',
			urlSelector:'.title h4 a',
			siteUrl: 'http://www.christinaperri.com'
		}
		$.wmgfeature.fbLike(fbLikeObj, listing);
		if (($("#home .articles li.article").find('.twitter-share-button').length == 0)) {
			$.wmgfeature.twttrButton(twitterObj, listing);
		}		
	}
		
		/* adding home page social buttons on pagination - Ends */
				
 var eventArchiveHead='<div id="archiveHead"><span id="archiveSpan">WANT TO SEE CHRISTINA PERRI?<a id="archiveTag" href="/shows/"> CHECK OUT UPCOMING DATES. </a></span></div>';	
	$("#event_listing-3301619.event_listing .module .content .body").prepend(eventArchiveHead);
	
	var eventUpcomingHead='<div id="upcomingHead"><span id="upcomingSpan">BEEN TO A SHOW?<a id="upcomingTag" href="/past-shows/" > UPLOAD YOUR SHOWS PHOTOS AND VIDEOS </a></span></div>';	
	$("#event_listing-707476.event_listing .module .content .body").prepend(eventUpcomingHead);

var memGoing="Fans Going ";

	$('#event_listing-707476.event_listing ul.cal_events li.cal_event').each(function(){
		
		var attendeeCount= $(this).find('.attendee_count').html();
		var buyBtn= $(this).find('.buy');
		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();
			if(attendeeCount=='0' || attendeeCount=="1"){memGoing="Fan Going";}
			else{memGoing="Fans Going";}
			writeToConsole("memgoing"+memGoing);
			var member_det='<div class="member_details"><div class="membrGoing"><a href="'+eventPath+'">'+ attendeeCount +" "+ memGoing +'</a></div></div><div class="moreinfo"><a class="viewmoreinfo" href="'+eventPath+'">More info</a></div>';
			writeToConsole("memgoing"+member_det);
			$(this).find('.txt').append(member_det);		
		}else{
			var member_det='<div class="moreinfo"><a class="viewmoreinfo" href="'+eventPath+'">More info</a></div>';
			$(this).find('.txt').append(member_det);
		}
			
	});	
	
	var fansWent=" Fans Went";
		$('#event_listing-3301619.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');
			eventPath=eventPath+"?show=archive";
			$(this).find('.txt .date h4 a').attr('href',eventPath);
			$(this).find('.attendee_count').remove();
			$(this).find('.buy').remove();
			var viewEveMedia="<div class='viewMedia'><a class='viewpix'>View Photos and videos</a></div>";
             $(viewEveMedia).insertBefore($(this).find('.txt .date'));
			$(this).find('.viewMedia a').attr('href',eventPath);
			var venueact=$(this).children('.txt').children('.venue');
			$(this).children('.txt').append(venueact);
			if(attendeeCount!=null && attendeeCount!=""){
				attendeeCount=attendeeCount.substring((attendeeCount.lastIndexOf(":")+1),attendeeCount.length).trim();
				if(attendeeCount=='0' || attendeeCount=="1"){fansWent="Fan Went";}
				var member_det='<div class="fan_details"><div class="fanWent"><a href="'+eventPath+'">'+ attendeeCount +" "+ fansWent +'</a></div></div><div class="moreinfo"><a class="viewmoreinfo" href="'+eventPath+'">More info</a></div>';
				$(this).find('.txt').append(member_det);			
			}else{
			var member_det='<div class="moreinfo"><a class="viewmoreinfo" href="'+eventPath+'">More info</a></div>';
			$(this).find('.txt').append(member_det);
		}
			
			var eventPath=  $(this).find('.txt .date h4 a').attr('href');
			var venuename= $(this).find('.venue').text();
 var venueDiv='<div class="venue"><a class="venueLink">'+venuename+'</a></div>';
 				
	});

	
	/*START - Fix for truncating title of blogs in home page */
	var blogtitle = 70;
	$('#home .blog_listing .articles .title h4 a').each(function(){
	var trunc = (this).innerHTML;
	if (trunc.length > blogtitle) {
	trunc = trunc.substring(0, blogtitle);
	trunc += '<span>' + '...</span>';
	(this).innerHTML = trunc;
	}
	})
	/*END - Fix for truncating title of blogs in home page */ 	


	/* var alink=$('#blog_listing-886676.blog_listing .module .content .body .articles .article .description a').html();
	  
	 if(alink.indexOf('Read More')>0)
	 {
	  	$('#blog_listing-886676.blog_listing .module .content .body .articles .article .description a').addClass('readMore');
	 }
	 */


	//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(); 		

	
	
	/* Remove link in event listing */
	
/*facebook language change */
$('#edit_account #fbcLoginButton p').remove();
$('#edit_account #facebookSettings .title').append('<p>Click on the Facebook Connect button to share your comments, photos, videos and discussion posts with your Facebook friends.</p>');

	eoscInitCallBack();			
}

   $.urlParam = function(name){
        var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
        if (results == null) {
            return 0;
        }
        else {
            return results[1];
        }
    }	
	
/* 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 = "javascript: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");
    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(){
	
var maxCount =15;
  
	$('#rss_content-2477091.rss_in .body .csCell').each(function(){
		var cellstreamTitle=$(this).find(".text").text();
		var actCount=cellstreamTitle.length;
		var newCSTitle="";
		if(actCount>maxCount){
			newCSTitle=(cellstreamTitle.substring(0,14))[0] + "...";
			$(this).find(".text").append(newCSTitle);
			$(this).find(".text").attr('title',cellstreamTitle);
		}	
	});
	
	if ($("#lovestrong #merchContainer").length > 0) {
        $("#merchContainer").html(generateMerchStructure());
        $("#merchData").empty();
        $("#merchContainer a").makeLinksExternal();
        //registerMerchHoverEvents();
    }
	
   else if ($("#merchContainer").length > 0) {
        $("#merchContainer").html(generateMerchStructure());
        $("#merchData").empty();
        $("#merchContainer a").makeLinksExternal();
       registerMerchHoverEvents();
    }
	else{
		
	}
    
	var discusspan = $("#discussion_entry-294529.discussion_entry .content div.topic .txt .date span");
	if(discusspan.length > 0 ){
		var fileUnder = discusspan.text();
		$("#discussion_entry-294529.discussion_entry .content div.topic .txt .date").html(fileUnder);
	}
	
	
});
/* End of Functions for New Merch */	

