/* 
 * 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);

/*
 * Jquery Plugin - opens external links in a new window.  
 */
jQuery.fn.makeLinksExternal=function(){return this.each(function(){var a=$(this).attr("href");if(a.indexOf(location.host)==-1&&a.indexOf("/")!=0){$(this).attr("target","_blank")}})};

var userVisitCount;
var userVCount;
$(document).ready(function(){
	//Old discussion board link
	$("#discussion_listing-340654.discussion_listing .foot .nav_meta ul li.new a").html("Old Message Board").show();	
	$("#discussion_listing-340654.discussion_listing .foot .nav_meta ul li.new a").attr("target","_blank").attr("href","http://boards.atlanticrecords.com/artists/shinedown/forums");

	//$("#discussion_listing-340654.discussion_listing .foot .nav_meta ul li.new a").html("Castro Cafe").show();	
	//$("#discussion_listing-340654.discussion_listing .foot .nav_meta ul li.new a").attr("target","_blank").attr("href","http://cafe.jasoncastromusic.com/");
	
	var discussoldlink='<li class="discussion_old_link"><a href="http://boards.atlanticrecords.com/artists/shinedown/forums" target="_blank">Old Message Board</a></li>'
	$("#discussion_listing-294531.discussion_listing .foot .nav_meta ul ").prepend(discussoldlink);

	/*
	 * prompting user to signup for sight
	 */
	$('.article .description a[href*=/updates/]').addClass("readmorelink");
if($('#photo_thumbnail-294569 .seperater').length == 0){
	$("#photo_thumbnail-294569 .module .content .body ul.photos li.photo:nth-child(3n)").each(function(){
    $(this).after('<div class="seperater"></div>')
    })
}
if($('#photo_thumnail-294571 .seperater').length == 0){	
	$("#photo_thumnail-294571 .module .content .body ul.photos li.photo:nth-child(3n)").each(function(){
    $(this).after('<div class="seperater"></div>')
    })
}
if($('#video_thumbnail-294591 .seperater').length == 0){    
	$("#video_thumbnail-294591 .module .content .body ul.videos li.video:nth-child(3n)").each(function(){
    $(this).after('<div class="seperater"></div>')
    })
}
if($('#video_thumbnail-294593 .seperater').length == 0){
	$("#video_thumbnail-294593 .module .content .body ul.videos li.video:nth-child(3n)").each(function(){
    $(this).after('<div class="seperater"></div>')
    })
}	
	$(".msie8 div.ad.medium").parent("div.ad").parent("form").attr("style","display:none"); $(".msie8 div.ad.leaderboard").parent("div.ad").parent("form").attr("style","display:none");
	
var $blogFootFix = $('.blog_listing .nav_meta .more a');
 $blogFootFix.filter(function(){
 return (/^Post/i).test($(this).text())
 }).parent()
 .removeClass('more')
 .addClass('new'); 
	
 	/*
$('#album .list_album .module .content .body .txt .title h4').addClass('removeSifr');
*/
 	
	$('.site_activity .module .content .body ul.events li:last-child').addClass('lastEntry');
	
	 var $blogFootFix = $('#blog_listing-327529 .foot .nav_meta .more a');
 $blogFootFix.filter(function(){
 return (/^Post/i).test($(this).text())
 }).parent()
.removeClass('more')
 .addClass('new'); 
	
    /* Suppresses display of empty footers on IE */
    $('.module .foot:empty').addClass('empty');
	
	/* Suppresses display of empty footers on IE for twitter module */
	$('#html-683925.html .module .content .foot').removeClass('empty');
	
	$("html").addClass($.os.name);
	$("body").addClass($.browser.className);
	
    /* 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><li class="viewmoremusic">Visit the Music Page for More</li>');
    $(".song_playlist .module .content .nav_meta ul").prepend(launchLink);
    /* END Add "Launch Player" links to footer nav of all audio playlist modules */
    

    $('#song_playlist-348671 .viewmoremusic').click( function() {
    window.opener.focus();
    //window.opener.location('http://www.mysite.com/index.php?id='+id);
   window.opener.window.location.href="/music/";
   //window.parent.location.replace('/music/');
   self.close();
   return false;		
   });
    
    /* 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;
    });

	//reformat Comments copy - MIKE - 04-28-2010
	$.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); 
	
	});


	//reword comment widget default copy on member's wall - MIKE - 04-28-2010
	// var newDefaultText = "Write on " + $("#member_detail .member_detail .member .txt .title h4").text() + "'s wall (no HTML please)";
	// 	$('#member_detail .comments fieldset textarea').html(newDefaultText);
	// 	$('#member_detail .comments fieldset textarea').attr("title", $('#member_detail .comments fieldset textarea').attr("title").replace("Add your comment (no HTML please)", newDefaultText));
	// 	   
	// 	//var newTaOnFocus = taOnFocus.replace("Add your comment (no HTML please)", newDefaultText);
	// 	$('#member_detail .comments fieldset textarea').removeAttr("onfocus")
	// 	
	// 	
	// 	
	// 	    $('#member_detail .comments fieldset textarea').focus(function(){
	// 	
	// 	
	// 	
	// 		 if ($('#member_detail .comments fieldset textarea').html() == "Write on " + $('.member_detail .member .txt .title h4').text() + "'s wall (no HTML please)") {
	// 				 		        $('.comments fieldset textarea').html("");
	// 				 }
	// 			
	// 	});
    
    /* Make store top nav link open in a new window */
    $('.nav_main ul li.custom a[href*=amazon.com]').attr("rel", "external");
    
	/*START - Fix for truncating author name in the discussions page #698 */
			$('.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 #698 */
	
		
    $("a[href^=http://starterfanclub1.wmg.ciscoeos.com]").parent(".custom").addClass("Fanclub");
	
	/* START: Community drop-down for top nav */
    //Define XHTML source for the community subnav inn the variable below	
  	  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: 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 (/^Fan Club$/i).test($(this).text())
	}).parent()
	  .addClass('nav-custom')
	  .addClass('nav-fanclub')
	  .addClass('dropdown')
	  .removeClass('nav-home');
	  
	  
	 $customNavs.filter(function(){
		  return (/^Store$/i).test($(this).text())
		}).parent()
    	  .addClass('nav-custom')		  
		  .addClass('nav-store');	
	 
	 $customNavs.filter(function(){
		  return (/^Store$/i).test($(this).text())
		}).attr("target","_blank");
		
	  
	 $customNavs.filter(function(){
		  return (/^Global$/i).test($(this).text())
		 }).parent()
 		  .addClass('nav-custom')
		  .addClass('dropdown')
		  .addClass('nav-global_int')
		  .append(globalSubNav);
		  
	/* START: Bio drop-down for top nav */

 	var bioNavCell = $(".nav_main ul li.nav-bio"); //change this selector to target a diffent cell in the top nav
 	bioNavCell.addClass('dropdown');
 	bioNavCell.append(bioSubNav);
	/* END: Bio drop-down for top nav */
	
	    /* START: Store drop-down for top nav */
    //Define XHTML source for the community subnav inn the variable below
	var storeNavCell=$(".nav_main ul li.nav-store");	
	storeNavCell.addClass('dropdown');
	storeNavCell.append(storeSubNav); 
    /* END: Store drop-down for top nav */
	
	
		/* START: shinedown nation drop-down for top nav */

 	var shinedownNationNavCell = $(".nav_main ul li.nav-fanclub"); //change this selector to target a diffent cell in the top nav
 	shinedownNationNavCell.addClass('dropdown');
 	shinedownNationNavCell.append(shinedownNationSubNav);
	/* END: shinedown Nation drop-down for top nav */
	
	/* END: Custom drop-downs for top nav */
	
	 $('.nav_main ul li.nav-custom ul.flyoutMenu #australiaNav').addClass('australiaDropdown');
	 	var $australiaStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #australiaNav ul');	 
	 	$australiaStoreNav.addClass('australiaFlyoutMenu');
		
	$('.nav_main ul li.nav-custom ul.flyoutMenu #austriaNav').addClass('austriaDropdown');
	 	var $austriaStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #austriaNav ul');	 
	 	$austriaStoreNav.addClass('austriaFlyoutMenu');
		
	$('.nav_main ul li.nav-custom ul.flyoutMenu #belgiumNav').addClass('belgiumDropdown');
	 	var $belgiumStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #belgiumNav ul');	 
	 	$belgiumStoreNav.addClass('belgiumFlyoutMenu');
		
	$('.nav_main ul li.nav-custom ul.flyoutMenu #canadaNav').addClass('canadaDropdown');
	 	var $canadaStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #canadaNav ul');	 
	 	$canadaStoreNav.addClass('canadaFlyoutMenu');
		
	$('.nav_main ul li.nav-custom ul.flyoutMenu #denmarkNav').addClass('denmarkDropdown');
	 	var $denmarkStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #denmarkNav ul');	 
	 	$denmarkStoreNav.addClass('denmarkFlyoutMenu');
		
	$('.nav_main ul li.nav-custom ul.flyoutMenu #finlandNav').addClass('finlandDropdown');
	 	var $finlandStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #finlandNav ul');	 
	 	$finlandStoreNav.addClass('finlandFlyoutMenu');
		
	$('.nav_main ul li.nav-custom ul.flyoutMenu #franceNav').addClass('franceDropdown');
	 	var $franceStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #franceNav ul');	 
	 	$franceStoreNav.addClass('franceFlyoutMenu');
		
	$('.nav_main ul li.nav-custom ul.flyoutMenu #germanyNav').addClass('germanyDropdown');
	 	var $germanyStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #germanyNav ul');	 
	 	$germanyStoreNav.addClass('germanyFlyoutMenu');
	
	$('.nav_main ul li.nav-custom ul.flyoutMenu #greeceNav').addClass('greeceDropdown');
	 	var $greeceStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #greeceNav ul');	 
	 	$greeceStoreNav.addClass('greeceFlyoutMenu');
	
	$('.nav_main ul li.nav-custom ul.flyoutMenu #irelandNav').addClass('irelandDropdown');
	 	var $irelandStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #irelandNav ul');	 
	 	$irelandStoreNav.addClass('irelandFlyoutMenu');
	
	$('.nav_main ul li.nav-custom ul.flyoutMenu #italyNav').addClass('italyDropdown');
	 	var $italyStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #italyNav ul');	 
	 	$italyStoreNav.addClass('italyFlyoutMenu');
	
		
	$('.nav_main ul li.nav-custom ul.flyoutMenu #japanNav').addClass('japanDropdown');
	 	var $japanStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #japanNav ul');	 
	 	$japanStoreNav.addClass('japanFlyoutMenu');
	
	$('.nav_main ul li.nav-custom ul.flyoutMenu #mexicoNav').addClass('mexicoDropdown');
	 	var $mexicoStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #mexicoNav ul');	 
	 	$mexicoStoreNav.addClass('mexicoFlyoutMenu');
	
	$('.nav_main ul li.nav-custom ul.flyoutMenu #netherlandsNav').addClass('netherlandsDropdown');
	 	var $netherlandsStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #netherlandsNav ul');	 
	 	$netherlandsStoreNav.addClass('netherlandsFlyoutMenu');
		
		$('.nav_main ul li.nav-custom ul.flyoutMenu #newzealandNav').addClass('newzealandDropdown');
	 	var $newzealandStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #newzealandNav ul');	 
	 	$newzealandStoreNav.addClass('newzealandFlyoutMenu');
	
	$('.nav_main ul li.nav-custom ul.flyoutMenu #norwayNav').addClass('norwayDropdown');
	 	var $norwayStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #norwayNav ul');	 
	 	$norwayStoreNav.addClass('norwayFlyoutMenu');
		
	$('.nav_main ul li.nav-custom ul.flyoutMenu #portugalNav').addClass('portugalDropdown');
	 	var $portugalStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #portugalNav ul');	 
	 	$portugalStoreNav.addClass('portugalFlyoutMenu');
		
	$('.nav_main ul li.nav-custom ul.flyoutMenu #spainNav').addClass('spainDropdown');
	 	var $spainStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #spainNav ul');	 
	 	$spainStoreNav.addClass('spainFlyoutMenu');
		
	$('.nav_main ul li.nav-custom ul.flyoutMenu #swedenNav').addClass('swedenDropdown');
	 	var $swedenStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #swedenNav ul');	 
	 	$swedenStoreNav.addClass('swedenFlyoutMenu');
		
	$('.nav_main ul li.nav-custom ul.flyoutMenu #switzerlandNav').addClass('switzerlandDropdown');
	 	var $switzerlandStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #switzerlandNav ul');	 
	 	$switzerlandStoreNav.addClass('switzerlandFlyoutMenu');
		
	$('.nav_main ul li.nav-custom ul.flyoutMenu #unitedkingdomNav').addClass('unitedkingdomDropdown');
	 	var $unitedkingdomStoreNav = $('.nav_main ul li.nav-custom ul.flyoutMenu #unitedkingdomNav ul');	 
	 	$unitedkingdomStoreNav.addClass('unitedkingdomFlyoutMenu');
	/* ********** Home Page SS3 *********************** */
	
	/* Removing the upload from the top, and adding at the bottom; */
	var uploadDiv = $("#homepage_ss3 .nav_main ul li.upload");
	$("#homepage_ss3 .nav_main div > ul").append(uploadDiv);
	
	/* Carousel Button */
	/* algo 
	 * Have an event handler for the click of the buttons.
	 * Have global variables like currentActiveCaros
	 * 
	 * 
	 */	
	 var carosActiveCurrent = 0;
	 var carosTotal = $("#carosUnitWrapper .carosUnit").length;

	 if (carosTotal > 1){
	 	$("#rightCarosButton").addClass('active');
	 	$("#carosUnitWrapper .carosUnit:eq("+ carosActiveCurrent +")").toggle(100);
	 }
	 	 
	 $("#rightCarosButton").click(function (event){
	 	 if (carosTotal-carosActiveCurrent != 1){
		 	$("#carosUnitWrapper .carosUnit:eq("+ carosActiveCurrent +")").toggle(100);
			carosActiveCurrent++;
		 	$("#carosUnitWrapper .carosUnit:eq("+ carosActiveCurrent +")").toggle(100);
		 }
		 setCarosButtonsState();
		 
		});
	 $("#leftCarosButton").click(function (event){
	 	 if (carosActiveCurrent > 0 ){
		 	$("#carosUnitWrapper .carosUnit:eq("+ carosActiveCurrent +")").toggle();
			carosActiveCurrent--;
		 	$("#carosUnitWrapper .carosUnit:eq("+ carosActiveCurrent +")").toggle();
		 }
		 setCarosButtonsState();
		});
		function setCarosButtonsState(){
			
			 if (carosActiveCurrent == carosTotal-1 ){
				 	$("#rightCarosButton").removeClass('active');
			 }else {
				 	$("#rightCarosButton").addClass('active');
			 }
			 if (carosActiveCurrent == 0){
				 $("#leftCarosButton").removeClass('active');
			 }else {
		   	 	 $("#leftCarosButton").addClass('active');
			 }
		};
		
		/* ********** Home Page SS3 ends *********************** */	 	  

	
	
	var storeNavCell= $(".nav_main ul li.nav-store"); 
	
    /*Hover event handler for all drop-downs in top nav */
    $(".dropdown").hover(
		function(){$(".flyoutMenu", this).show();}, 
		function(){$(".flyoutMenu", this).hide();}
	);
    
  $(".australiaDropdown").hover(
    		function(){$(".australiaFlyoutMenu", this).show();}, 
    		function(){$(".australiaFlyoutMenu", this).hide();}
    );
	
	$(".austriaDropdown").hover(
    		function(){$(".austriaFlyoutMenu", this).show();}, 
    		function(){$(".austriaFlyoutMenu", this).hide();}
    );
	
	$(".belgiumDropdown").hover(
    		function(){$(".belgiumFlyoutMenu", this).show();}, 
    		function(){$(".belgiumFlyoutMenu", this).hide();}
    );
	
	$(".canadaDropdown").hover(
    		function(){$(".canadaFlyoutMenu", this).show();}, 
    		function(){$(".canadaFlyoutMenu", this).hide();}
    );
	
	$(".denmarkDropdown").hover(
    		function(){$(".denmarkFlyoutMenu", this).show();}, 
    		function(){$(".denmarkFlyoutMenu", this).hide();}
    );
	
	$(".finlandDropdown").hover(
    		function(){$(".finlandFlyoutMenu", this).show();}, 
    		function(){$(".finlandFlyoutMenu", this).hide();}
    );
	
	$(".franceDropdown").hover(
    		function(){$(".franceFlyoutMenu", this).show();}, 
    		function(){$(".franceFlyoutMenu", this).hide();}
    );
	
	$(".germanyDropdown").hover(
    		function(){$(".germanyFlyoutMenu", this).show();}, 
    		function(){$(".germanyFlyoutMenu", this).hide();}
    );
	
	$(".greeceDropdown").hover(
    		function(){$(".greeceFlyoutMenu", this).show();}, 
    		function(){$(".greeceFlyoutMenu", this).hide();}
    );
	
	$(".irelandDropdown").hover(
    		function(){$(".irelandFlyoutMenu", this).show();}, 
    		function(){$(".irelandFlyoutMenu", this).hide();}
    );
	
	$(".italyDropdown").hover(
    		function(){$(".italyFlyoutMenu", this).show();}, 
    		function(){$(".italyFlyoutMenu", this).hide();}
    );
	
	$(".japanDropdown").hover(
    		function(){$(".japanFlyoutMenu", this).show();}, 
    		function(){$(".japanFlyoutMenu", this).hide();}
    );
	
	$(".mexicoDropdown").hover(
    		function(){$(".mexicoFlyoutMenu", this).show();}, 
    		function(){$(".mexicoFlyoutMenu", this).hide();}
    );
	
	$(".swedenDropdown").hover(
    		function(){$(".swedenFlyoutMenu", this).show();}, 
    		function(){$(".swedenFlyoutMenu", this).hide();}
    );
	
	$(".netherlandsDropdown").hover(
    		function(){$(".netherlandsFlyoutMenu", this).show();}, 
    		function(){$(".netherlandsFlyoutMenu", this).hide();}
    );
	
	$(".newzealandDropdown").hover(
    		function(){$(".newzealandFlyoutMenu", this).show();}, 
    		function(){$(".newzealandFlyoutMenu", this).hide();}
    );
	
	$(".norwayDropdown").hover(
    		function(){$(".norwayFlyoutMenu", this).show();}, 
    		function(){$(".norwayFlyoutMenu", this).hide();}
    );
	
	$(".portugalDropdown").hover(
    		function(){$(".portugalFlyoutMenu", this).show();}, 
    		function(){$(".portugalFlyoutMenu", this).hide();}
    );
	
	$(".spainDropdown").hover(
    		function(){$(".spainFlyoutMenu", this).show();}, 
    		function(){$(".spainFlyoutMenu", this).hide();}
    );
	
	$(".swedenDropdown").hover(
    		function(){$(".swedenFlyoutMenu", this).show();}, 
    		function(){$(".swedenFlyoutMenu", this).hide();}
    );
	
	$(".switzerlandDropdown").hover(
    		function(){$(".switzerlandFlyoutMenu", this).show();}, 
    		function(){$(".switzerlandFlyoutMenu", this).hide();}
    );
	
	
	$(".unitedkingdomDropdown").hover(
    		function(){$(".unitedkingdomFlyoutMenu", this).show();}, 
    		function(){$(".unitedkingdomFlyoutMenu", this).hide();}
    );
	
	
    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");
        $("#communityNav").addClass("active");
    }
	
	 if (location.href.indexOf("/extras/") != -1) {
        communityNavCell.addClass("active");
        $("#extrasNav").addClass("active");
    }
	/*For international pages*/
	var globalNavCell=$(".nav_main ul li.nav-global");
	
	 if (location.href.indexOf("/es/") != -1) {
		globalNavCell.addClass("active");
		$("#esNav").addClass("active");
		}
		if (location.href.indexOf("/jp/") != -1) {
		globalNavCell.addClass("active");
		$("#jpNav").addClass("active");
		} 
		
		if (location.href.indexOf("/gb/") != -1) {
		globalNavCell.addClass("active");
		$("#gbNav").addClass("active");
		} 
		 if (location.href.indexOf("/de/") != -1) {
		globalNavCell.addClass("active");
		$("#deNav").addClass("active");
		}
	
    var photoNavCell = $(".nav_main ul li.photo");
    if (location.href.indexOf("/cellstream/") != -1) {
        photoNavCell.addClass("active");
    }
    
    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");
    }	
    /* ********** Merch module code ********* */
	$('#merchContainer').parent(".description").parent(".body").siblings(".head").addClass("clearfix");				
						
	$('#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'});

	
	$('#twitterContainer').parent(".description").parent(".body").addClass("tweetbody");	
	
	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);

	$('#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");
		}
	});

   /* 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");
    
    /* 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");
    
    var noOfImageDscDtl = $("#discussion_entry-294529 .topic .description img").length;
    for (i = 0; i < noOfImageDscDtl; i++) {
        var discussionImageElement = $("#discussion_entry-294529 .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-340654  .topic .description img").length;
    for (i = 0; i < noOfImageDscDtl; i++) {
        var discussionImageElement = $("#discussion_listing-340654 .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);
        }
        
    }
	
	// 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: "/"
        });
    }


	

	
    //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");
	
    
    
	$errmsg = $('.reset_password .module .content .body');
    $errmsg.insertBefore('#errorMsg');
    
    //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>');
				}
			}			
		});	
		
	/*End - code which obfuscates email addresses #2420*/
	
	var prvteCont="<i class='prText'>&nbsp;&nbsp;</i>";

	$('#join-294550.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;
	})
	
	$tweetmorelink = $('#twitterContainer').siblings(".tweetBottom"); 
    var twitterFoot = $('#twitterContainer').parent(".description").parent(".body").siblings(".foot");
    $tweetmorelink.appendTo(twitterFoot); 
	
	/* var liLength = $('#event_listing-707476.event_listing .module .content .body ul.cal_events li.cal_event').length;
	for (var i = 1; i <= liLength; i++) {
		
		var viewhref = $('#event_listing-707476.event_listing .module .content .body ul.cal_events li.cal_event:nth-child('+i+') .txt .date h4 a ').attr("href");
		
		$('#event_listing-707476.event_listing .module .content .body ul.cal_events li.cal_event:nth-child('+i+')').append('<div class="viewEvent"><a href="'+viewhref+'">Photos & Videos</a></div>');
		
		
	} */
	
	$('#event_listing-707476.event_listing .module .content .head .title').append('<div class="upComing"><a href="/tour-dates/">see upcoming</a></div>');
	
	$('#event_listing-707476.event_listing .module .content .body').prepend('<div class="outerDesc"><div class="innerDesc"> were you at one of these shows? Share you photos and videos! </div><div>');
	
	$('#html-1602795 .module .content .head').append('<div class="upComing"><a href="/concerts/">see upcoming</a></div>');
	
	var pastEvent=$('#event-707479.event .module .content .head .title .nav_meta ul li.more a');
	$('.grid_9 .pastEvents').append(pastEvent);
	
	
	$('#event_listing-1642801.event_listing .module .content .body ul.cal_events li.cal_event .txt').each ( function() {
		
		var invite_title = "Shinedown - " + $(this).find('.venue').text();
		var invite_location = $(this).find('.city').text()+$(this).find('.region').text();
		var date = new Date($(this).find('.date h4').text());
		invite_date = (date.getMonth()+1) + '/' + date.getDate() + '/' + date.getFullYear();
		
		/*
		alert(invite_title);
		alert(invite_location);
		*/
		/*alert(invite_date);*/
		
		invite_title = invite_title.replace(/\'/g,"\\'");
    	invite_title = invite_title.replace(/\&/g,'\&amp;');
		invite_title = invite_title.replace(/\n/g,'');
		invite_location = invite_location.replace(/\'/g,"\\'");
   		invite_location = invite_location.replace(/\&/g,'\&amp;');
		invite_location = invite_location.replace(/\n/g,'');
		/*onclickString = "populateInviteData('"+ invite_title + "','"+invite_location+"','"+invite_date +"');";
		$(this).append('<div class="iggli-invite-button"><a class="iggli-button" onclick="' + onclickString + '">Invite Friends</a></div>');
	*/
	});
	
	
	/* Changing the Venue to Hyperlinks Start */
	
	$('#event_listing-707476.event_listing .module .content .body ul.cal_events li.cal_event').each ( function() {
		var anchorTag = $(this).find('.viewEvent a').attr('href');
		var replace_title = $(this).find('.venue').text();
		var replace_city = $(this).find('.city').text();
		var replace_region = $(this).find('.region').text();
		
		$(this).find('.venue').html('<a href = "' + anchorTag + '">' + replace_title + '</a>');
		$(this).find('.city').html('<a href = "' + anchorTag + '">' + replace_city + '</a>');
		$(this).find('.region').html('<a href = "' + anchorTag + '">' + replace_region + '</a>');
		
	});
	
	
	/* Changing the Venue to Hyperlinks End */

	$(".blog_listing li.article.category_29794").append('<div class="blogshinedownlogo" />');
	$("#group_detail_3231 .blog_listing li").removeClass('blogshinedownlogo');
	
	
	//Badges implementation
	$(".badges ul").each(function(){	
		if ($(this).find("li").length > 0) {	
			$(this).html('<li class="badge"><a class="badgeImageReplace" href="/group/shinedown-nation/"></a></li>');
		}
	});

	
});

function eoscInit(){
	//Badges implementation in pagination	
	$(".badges ul").each(function(){	
		if ($(this).find("li").length > 0) {	
			$(this).html('<li class="badge"><a class="badgeImageReplace" href="/group/shinedown-nation/"></a></li>');
		}
	});
	
	if($('#sign_up_confirm-294579').length !=0){							
		$.cookie("newregusersuccess", "true", {path: '/',expires: 30});	
	}	
	
	if($('#photo_thumbnail-294569 .seperater').length == 0){
		$("#photo_thumbnail-294569 .module .content .body ul.photos li.photo:nth-child(3n)").each(function(){
	    $(this).after('<div class="seperater"></div>')
	    })
	}
	if($('#photo_thumnail-294571 .seperater').length == 0){	
		$("#photo_thumnail-294571 .module .content .body ul.photos li.photo:nth-child(3n)").each(function(){
	    $(this).after('<div class="seperater"></div>')
	    })
	}
	if($('#video_thumbnail-294591 .seperater').length == 0){    
		$("#video_thumbnail-294591 .module .content .body ul.videos li.video:nth-child(3n)").each(function(){
	    $(this).after('<div class="seperater"></div>')
	    })
	}
	if($('#video_thumbnail-294593 .seperater').length == 0){
		$("#video_thumbnail-294593 .module .content .body ul.videos li.video:nth-child(3n)").each(function(){
	    $(this).after('<div class="seperater"></div>')
	    })
	}
	
	$('.module .content .head h3').css("display","block");
	
	$('#event_listing-707476.event_listing .module .content .body ul.cal_events li.cal_event').each ( function() {
		
		var viewhref = $(this).find('.txt .date h4 a').attr("href");
		$(this).append('<div class="viewEvent"><a href="'+viewhref+'">Photos & Videos</a></div>');
		
	});
	
	if(!($("#member_detail").length == 0)){
		if(($("#successMsg").length != 0) ){
						$(".innercontainer").css("margin-top","0px");
						$("#container.container_14").css("margin-top","7px");
		}
	}else if(($("#errorMsg").length != 0) ){
			$(".innercontainer").css("margin-top","0px");
			$("#container.container_14").css("margin-top","13px");
	}
	
	//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(); 		
	
	/*reset password screen*/	
	$('.reset_password .module .content .body').insertBefore('#errorMsg');
	
	$(".edit_account #accountData .buttons.input .button.submit input.submit").removeAttr("onclick");
	$(".edit_account #accountQuestoins .buttons.input .button.submit input.submit").removeAttr("onclick");
	
	 $('.edit_account #accountData .buttons.input .button.submit input.submit').unbind('click');
	 $(".edit_account #accountData .buttons.input .button.submit input.submit").click( function(event) {
		event.preventDefault();
		var isUpdateReal = true;
		replaceContentRealSignUp('edit_account-294534', 'edit_account-294534', isUpdateReal);
	});
	
	$('.edit_account #accountQuestoins .buttons.input .button.submit input.submit').unbind('click');
	$(".edit_account #accountQuestoins .buttons.input .button.submit input.submit").click( function(event) {
		event.preventDefault();
		var isUpdateReal = true;
		isAccountQuestions = true;
		replaceContentRealSignUp('edit_account-294534', 'edit_account-294534', isUpdateReal);
	});
	
}

   $.urlParam = function(name){
        var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
        if (results == null) {
            return 0;
        }
        else {
            return results[1];
        }
    }	
	

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:"145", 			//Do not change this id. This is unique
		title:iTitle,
		location:iLocation,
		date:iDate
		}

		//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 Merch Hover Card */
function bringMerchHCOn(merchImg){
	merchImg.showTimer = window.setTimeout(function(){
		$(merchImg).siblings(".merchHC").fadeIn(350);
	},300);
}
function killMerchHC(merchImg){
	if (merchImg.showTimer){
		window.clearTimeout(merchImg.showTimer);
	}
}


function getMerchOmnitureArray(omnitureString){
	var omnitureArrayLinks = new Array();
	var omnitureStrRegex = /intcmp=(.*)(&.*|\/)$/;
	omnitureString = $.trim(omnitureString);
	if (omnitureString.charAt(omnitureString.length-1) != "/" ){omnitureString += "/";}
	regExCapture = omnitureString.match(omnitureStrRegex);
	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 merchBuilder(){
	var $merchData = $("#merchData");
	var $merchItem = $merchData.children(".merchItems")
	var merchViewAllLink = $merchData.children(".merchViewAll").html();
	
	/* Code for the Merch Head */
	var merchHead = '<div class="merchHead"><div class="visitStore"><a href="'+ merchViewAllLink +'"class="visitStoreLink"  >ALL</a></div></div>'
	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 merchImage = $(this).children(".merchImage").html();
		var merchTitle = $(this).children(".merchTitle").html();
		var merchBuyNow = $(this).children(".merchBuyNow").html();
		var merchDesc = $(this).children(".merchDesc").html();
		var merchSizes = $(this).children(".merchSizes").html();
		var merchPrice = $(this).children(".merchPrice").html();
		var omnitureArrayLinks = getMerchOmnitureArray(merchBuyNow);
		merchBody += '<li class="merch small item'+(i+1)+'">\
			<div class="merchImg"><a href="'+ omnitureArrayLinks["page-thumb"] +'"><img src="'+ merchImage +'"/></a><div class="merchZoomIcon"></div></div>\
			<div class="merchDetail">\
				<div class="merchPriceWrapper"><div class="merchName"><a href="'+ omnitureArrayLinks["page-title"]+'">'+ merchTitle +'</a></div><div class="merchPrice">'+ merchPrice +'</div></div>\
				<div class="merchBuy"><a href="'+omnitureArrayLinks["page-button"]+'" class="merchBuyLink">' + merchPrice + '</a></div>\
			</div>\
			<div class="merchHC merchHC'+ (i + 1) +'">\
				<div class="merchHCWrapper">\
					<div class="merchHCInnerWrapper">\
						<div class="merchHCHead"><a href="'+ omnitureArrayLinks["hovercard-title"] +'" >'+ merchTitle +'</a></div>\
						<div class="merchHCBody">\
							<div class="merchHCLeftCon"><a href="'+ omnitureArrayLinks["hovercard-thumb"]+ '" ><img src="'+merchImage+'" width="230px"/></a></div>\
							<div class="merchHCRightCon">\
								<h3 class="merchHCPrice">'+merchPrice+ '</h3>';
								if (merchDesc != "" && merchDesc != null){
									merchBody += '<h3>Description</h3><div>'+ merchDesc +'</div>';	
								}
								if (merchSizes !="" && merchSizes !=null){
									merchBody += '<h3>Sizes</h3><div>'+merchSizes+'</div>';	
								}
								
								merchBody += '<div class="merchHCBuyNowCon"><a class="merchHCBuyNow" href="'+ omnitureArrayLinks ["hovercard-button"] +'">Buy Now &raquo;</a></div>\
							</div>\
							<div class="clear"></div>\
						</div>\
						<div class="merchHCFoot"></div>\
					</div>\
				</div>\
			</div>\
		</li>';
	});
	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>';
	var visitStoreFoot = $('#merchContainer').parent(".description").parent(".body").siblings(".foot");
    $(merchFoot).appendTo(visitStoreFoot);
	$(visitStoreFoot).find("a").makeLinksExternal();
        return merchBody;
}

$(document).ready(function(){
    var domStr = merchBuilder;
    $("#merchContainer").html(merchBuilder());
    $("#merchData").empty();
    registerMerchHoverEvents();
	$("#merchContainer a").makeLinksExternal();
});

function registerMerchHoverEvents(){
	$(".merchImg").hover(function(){
		bringMerchHCOn(this);
	},function(){
		killMerchHC(this);
	});
	$(".merchHC").hover(function(){
	},function(){
		$(this).fadeOut(300);
	});	
}


jQuery.fn.makeLinksExternal = function() {
  return this.each(function(){
  	var linkHref =$(this).attr("href");  
    if (linkHref.indexOf(location.host) == -1 && linkHref.indexOf('/') !=0 ){
			$(this).attr("target","_blank");
	}
  });
};



		
/* End of Functions for Merch Hover Card */



