/* 
 * 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);


/* Replace links to latest album */
	if(location.href.match("/album/$") == "/album/") {
		window.location = location.href.substring(0, location.href.indexOf("/album/")) + "/album/happy-hour/"
	}
	if(location.href.match("/music/$") == "/music/" ) {
		window.location = location.href.substring(0, location.href.indexOf("/music/")) + "/album/happy-hour/"		
	}

var privacyPolicyText   = 'By registering, I acknowledge that I have reviewed and agreed to the '+ '<a target="_new" href="/privacy/" rel="external">Privacy Policy</a> and <a target="_new" href="/termsofuse/" rel="external">Terms of Service</a>' + ', and  I agree to receive marketing messages from Atlantic Records, its affiliates and Uncle Kracker with the latest news, updates and information about Uncle Kracker';

$(document).ready(function(){
	
	ord=Math.random()*10000000000000000;
	
	/* Setting the browser name and classname in the top */
	$("html").addClass($.os.name);
	$("body").addClass($.browser.className);
	
	/* Suppresses display of empty footers on IE */
	$('.module .foot:empty').addClass('empty');
	
	/* START Add "Launch Player" links to footer nav of all audio playlist modules */
	var launchLink =  $('<li class="launchPlayer"><a href="/music-player/" class="launchPlayerLink">Launch Player</a></li>');
	$(".song_playlist .module .content .nav_meta ul").prepend(launchLink);
	/* END Add "Launch Player" links to footer nav of all audio playlist modules */
	
	/*Fix for Bug#2247 - upload issue in FF*/
	$('#upload .module .content .head h3').addClass('removeSifr');
	$('#upload .module .content .body h3').addClass('removeSifr');
	$('#upload .module .content .body h4').addClass('removeSifr');
	$('#upload .pagetitleWrap h1').addClass('removeSifr');
	
	/* add popup onClick handler for audio player links */
	$("a.launchPlayerLink").click(function() {
			window.open("/music-player/", "Window2", "width=375,height=275,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no"); 
			return false;
	});
	
	/* Make store top nav link open in a new window */
	$('.nav_main ul li.custom a[href*=amazon.com]').attr("rel", "external");
	
	
		
	/* Replace links to "Music" to links to latest album. NOTE: this will need to be reworked whenever a new album is released */
	$("a[href$=/music/]").attr("href", "/album/happy-hour/");
	$("a[href$=/album/]").attr("href", "/album/happy-hour/");
	
	
	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 */
	
	
		
		var storeNavCell = $('.nav_main ul li.nav-custom').eq(1);   //change this selector to target a different cell in the top nav
		storeNavCell.addClass('dropdown');
		storeNavCell.append(storeSubNav);
	/* END: Store drop-down for top nav */
	
	/* START: country drop-down for top nav */
	//Define XHTML source for the community subnav inn the variable below
/*	var countrySubNav = '<ul class="flyoutMenu" id="internationalSubNav" style="display:none">\
			<li id="spainNav"><a href="/spain/" class="flag spain" >Visit Spain page</a></li>\
			<li id="japanNav"><a href="/japan/" class="flag japan" >Visit Japan page</a></li>\
			<li id="ukNav"><a href="/united-kingdom/" class="flag uk" >Visit UK page</a></li>\
			<li id="germanyNav"><a href="/germany/" class="flag germany" >Visit Germany page</a></li>';
	var countryNavCell =  $('.nav_main ul li.custom:has(a[href*=javascript:void(0)])');    //change this selector to target a diffent cell in the top nav
	countryNavCell.addClass('dropdown');
	countryNavCell.append(countrySubNav);*/
	/* END: country drop-down for top nav */
	
		
	/*Hover event handler for all drop-downs in top nav */
	$(".dropdown").hover(
			function() { $(".flyoutMenu", this).show(); },
			function() { $(".flyoutMenu", this).hide(); }
	);
	
	/* Flag subnav pages in parent top nav li */
	if (location.href.indexOf("/member/") != -1) {
	    if(!(location.href.indexOf("/category/member/") != -1)){ 
	         communityNavCell.addClass("active");
	         $("#memberNav").addClass("active");
	    	}		
     }	

	if (location.href.indexOf("/community-landing/") != -1) {
			communityNavCell.addClass("active");
			$("#communityHomeNav").addClass("active");
		}
	if (location.href.indexOf("/extras/") != -1) {
			communityNavCell.addClass("active");
			$("#extrasNav").addClass("active");
		}
	if (location.href.indexOf("/community-landing/") != -1) {
			communityNavCell.addClass("active");
			$("#communityHomeNav").addClass("active");
		}
	
	if (location.href.indexOf("/talk/") != -1) {
			communityNavCell.addClass("active");
			$("#discussionsNav").addClass("active");
		}
	if (location.href.indexOf("/ringtones/") != -1) {
		storeNavCell.addClass("active");
		$("#ringtonesNav").addClass("active");
		}
		
	
	if (location.href.indexOf("/album/") != -1) {	
		$("a[href^=/album/]").parent(".custom").addClass("active");
	}
	if (location.href.indexOf("/take-a-tour/") != -1) {	
		$(".nav_main .community_landing").addClass("active");
		$("#takeatourNav").addClass("active");		
	}
	

/*
if (location.href.indexOf("/spain/") != -1) {
		$("a[href^=/spain]").parent(".custom").addClass("active");
		$("#spainNav").addClass("active");
	}
		
	if (location.href.indexOf("/germany/") != -1) {
		$("a[href^=/germany]").parent(".custom").addClass("active");
		$("#germanyNav").addClass("active");
	}
		
	if (location.href.indexOf("/japan/") != -1) {
		$("a[href^=/japan]").parent(".custom").addClass("active");
		$("#japanNav").addClass("active");
	}
		
	if (location.href.indexOf("/united-kingdom/") != -1) {
		$("a[href^=/united-kingdom]").parent(".custom").addClass("active");
		$("#ukNav").addClass("active");
	}	
*/
	
	if (location.href.indexOf("/music/") != -1) {	
		$(".nav_main ul li.custom a[href^='/albums/']").addClass("active");
	}

	/* START: Merch module drop-downs */
	$(".ArtistStore").hover (
			function() { $(".flyoutMenu", this).show(); },
			function() { $(".flyoutMenu", this).hide(); }
		);
			
	$(".mainAlbumBuyDrop").hover (
		function() { $("#subMainAlbumBuy", this).show(); },
		function() { $("#subMainAlbumBuy", this).hide(); }		
	);

	$(".productLeftBuyDrop").hover (
		function() { $("#subLeftAlbumBuy", this).show(); },
		function() { $("#subLeftAlbumBuy", this).hide(); }		
	);

	$(".productCenterBuyDrop").hover (
		function() { $("#subCenterAlbumBuy", this).show(); },
		function() { $("#subCenterAlbumBuy", this).hide(); }		
	);
	
	$(".productRightBuyDrop").hover (
		function() { $("#subRightAlbumBuy", this).show(); },
		function() { $("#subRightAlbumBuy", this).hide(); }		
	);

	$(".ArtistStoreBottom").hover (
		function() { $(".flyoutMenuFooter", this).show(); },
		function() { $(".flyoutMenuFooter", this).hide(); }		
	);
	/* END: Merch module drop-downs */	
	
	
	/* Replace EOS default privacy policy and terms of use with Atlantic Records links */
	$('[href=/privacy-policy/]').attr("href", "http://www.atlanticrecords.com/privacy/eos").attr("rel", "external");
	$('[href=/terms-of-use/]').attr("href", "http://www.atlanticrecords.com/termsofuse/eos").attr("rel", "external");

	/* Make rel="external" links open in a new window */
	$("a[rel=external]").attr("target", "_new");

	/* Fixing the target for the digg link */
	$(".shareweb .digg a").attr("target", "_new");
	
	/* Setting the width of the nav bar*/
	$("#nav_global").css({width : '993px'});
	$("#nav_global").children("ul").css({width : '983px'});
	
	if ($("#moduleForm350371").length){
		moduleContainer1Height = ($("#moduleForm350371").height()-122)+'px';
		$("#moduleContainer1").css({'margin-top': moduleContainer1Height })
	}
	
	/* 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");
	
	/* Home page album links changing the title */
	$("#moduleForm382837 ul.albums li:last-child").addClass("albumsLastChild");
	
	
	var noOfImageDscDtl=$("#discussion_entry-350389 .topic .description img").length;
		for(i=0;i<noOfImageDscDtl;i++){
			var discussionImageElement = $("#discussion_entry-350389 .topic .description img:eq(" +i+ ")");
			var imgHeight=discussionImageElement.height();
			var imgWidth=discussionImageElement.width();
			if(imgHeight>200 && imgWidth>200){		
				var calcheight = (imgHeight/imgWidth)*200;		
				discussionImageElement.css("height",calcheight);	
				discussionImageElement.css("width",200);	
			}
			
		}
	
	
	var noOfImageDscDtl=$("#discussion_listing-399821  .topic .description img").length;
		for(i=0;i<noOfImageDscDtl;i++){
			var discussionImageElement = $("#discussion_listing-399821 .topic .description img:eq(" +i+ ")");
			var imgHeight=discussionImageElement.height();
			var imgWidth=discussionImageElement.width();
			if(imgHeight>200 && imgWidth>200){		
				var calcheight = (imgHeight/imgWidth)*200;		
				discussionImageElement.css("height",calcheight);	
				discussionImageElement.css("width",200);	
			}
			
		}
	
		//Album detail stuff 
	$buylinks = $('#album_info-390840 .foot .nav_meta ul');
	$buylinks.insertBefore('#album_info-390840 .album .txt div.description');
	$('#album_info-390840.album_info .module .content .foot .nav_meta ul').css("display","block");
			  	
	
	//Sean Enright - add id to custom nav items
	
	
	$('.nav_main ul li.nav-custom').eq(0).addClass('nav-custom0');
	$('.nav_main ul li.nav-custom').eq(1).addClass('nav-custom1');
	$('.nav_main ul li.nav-custom').eq(2).addClass('nav-custom2');
	
	
	$('#blog_listing-350370.blog_listing .articles li:odd').addClass('odd_blog');
	$('#blog_listing-350370.blog_listing .articles li:even').addClass('even_blog');
	$('#blog_listing-350370.blog_listing .articles li:last-child').addClass('last_blog');
	$('#blog_listing-350370.blog_listing .articles li li').removeClass('last_blog');
	
	$('.module .content .foot').children().children().parent().parent().addClass('foot_bg');
	$('.module .content .body').addClass('yes_body_bg');
	$('.module .content .foot').children().children().parent().parent().parent('.content').find('.body').removeClass('yes_body_bg');
	
	$('#blog_listing-350370 .module .content .head .nav_meta').parent().parent().addClass('head_bg_dark');
	
	$('#list_album-390842.list_album .module .content .body ul.albums li.xs:last-child').css('border','none');
	
	$("#jump_fanclub a img").css('visibility','visible');
	$("#jump_fanclub a img").hide();
	
	$("#jump_fanclub a").hover(
      function () {
        $(this).find('img').show();
      }, 
      function () {
        $(this).find("img").hide();
      }
    );
	
	//$("#album_detail .date .val:contains('2009')").text("September 15th, 2009");
	//$("#album_detail .album_info .content .album .txt .title h4:contains('Happy Hour')").text("Happy Hour (available September 15th, 2009)");


	if (location.href.indexOf("/album/") != -1) {	
		$(".nav_main ul li.nav-custom0").addClass("active");
	}
	if (location.href.indexOf("/music/") != -1) {	
		$(".nav_main ul li.nav-custom0").addClass("active");
	}
	
	
	$( "#member_listing-408226 .module .content .head h3 span" ).remove();
	
	$( ".module .content .head h3 span" ).each(
  		 function( intIndex ){
   		var theCount = $(this).html();
  		$(this).parent().append(theCount);
		$(this).remove();
	
 	}
  
 );
 	
	//$('#rss_in-399814.rss_in .module .content .body .description h4:last-child').addClass('no_dots');
	
	//Modifying the legal text in the log in and sign up pages.
	$("body#sign_up #cmsgData\\[agreeToTerms\\]").next().html(privacyPolicyText + "").show();
	$("body#join #cmsgData\\[agreeToTerms\\]").next().html(privacyPolicyText + "").show(); 
	
	/*START- code which obfuscates email addresses #2420*/	
		var m_ = "mailto:";
		var a_ = "@";
		var d_ = ".";
		var i = 0;
		var j  = 0;
		var q_ = "?";
		var e_ = "=";
		
		$('span.ciReplace').each(function(){	
			if(cId[i].format == ""){
				$(this).html('<a href="'+m_+cId[i].name+a_+cId[i].domain+d_+cId[i].tld+'">'+ cId[i].name + a_+ cId[i].domain + d_+ cId[i].tld +'</a>');
			}
			else{
				if(cId[i].param == ""){
					$(this).html('<a href="'+m_+cId[i].name+a_+cId[i].domain+d_+cId[i].tld+'">'+ cId[i].format+'</a>');
				}
				else{
					$(this).html('<a href="'+m_+cId[i].name+a_+cId[i].domain+d_+cId[i].tld+q_+'subject'+e_+cId[i].param+'">'+cId[i].format+'</a>');
				}
			}
		i++;				
		});
		
		
		$('span.footReplace').each(function(){
					if(fId[j].format == ""){
				$(this).html('<a href="'+m_+fId[j].name+a_+fId[j].domain+d_+fId[j].tld+'">'+ fId[j].name + a_+ fId[j].domain + d_+ fId[j].tld +'</a>');
			}
			else{
				if(fId[j].param == ""){
					$(this).html('<a href="'+m_+fId[j].name+a_+fId[j].domain+d_+fId[j].tld+'">'+ fId[j].format+'</a>');
				}
				else{
					$(this).html('<a href="'+m_+fId[j].name+a_+fId[j].domain+d_+fId[j].tld+q_+'subject'+e_+fId[j].param+'">'+fId[j].format+'</a>');
				}
			}
			j++;		
		});	
		
	/*End - code which obfuscates email addresses #2420*/	
	
});

$.urlParam = function(name){
		var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
		if (results == null) {
			return 0;
		}
		else {
			return results[1];
		}
}

function eoscInit(){
	
	 //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();    
 
}