/* 
 * 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/sean-paul-imperial-blaze-1/"
	}
	if(location.href.match("/music/$") == "/music/" ) {
		window.location = location.href.substring(0, location.href.indexOf("/music/")) + "/album/sean-paul-imperial-blaze-1/"		
	}	

var blogTwitterBlurbText = 	"Follow this on Twitter using the tag #";
var privacyPolicyText   = 'By registering, I acknowledge that I have reviewed and agreed to the ' + '<a target="_new" href="/privacy-policy/" rel="external">Privacy Policy</a> and <a target="_new" href="/terms-of-use/" rel="external">Terms of Service</a>' + ', and  I agree to receive marketing messages from Atlantic Records, its affiliates and AllSeanPaul.com with the latest news, updates and information about Sean Paul';

$(document).ready(function(){
	
	$("html").addClass($.os.name);
	$("body").addClass($.browser.className);
	
	ord=Math.random()*10000000000000000;
		/* 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 */
	
	/*Code added to remove Sifr from Upload page as it affects the uploading of content*/
	
	$('#upload .module .content .head h3').addClass('removeSifr');
	$('#upload .module .content .body h3').addClass('removeSifr');
	$('#upload .module .content .body h4').addClass('removeSifr');	
	
	/* add popup onClick handler for audio player links */
	$("a.launchPlayerLink").click(function() {
			window.open("/music-player/", "Window2", "width=369,height=276,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.nav-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/sean-paul-imperial-blaze-1/");
	
	/* 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: Store drop-down for top nav */
		//Define XHTML source for the community subnav inn the variable below
					
		$('.nav_main ul li.nav-custom a').filter(function(){
		  return (/\Store/i).test($(this).text())
		}).parent()
		  .addClass('dropdown')
		  .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						
						
	$('.nav_main ul li.nav-custom a').filter(function(){
	  return (/\Global/i).test($(this).text())
	}).attr("rel","external")
	  .parent()
	  .addClass('dropdown')	  
	  .append(countrySubNav);
	/* END: country drop-down for top nav */
	
	$('.nav_main ul li.nav-custom a').filter(function(){
	  return (/\Ringtones/i).test($(this).text())
	}).parent()
	  .addClass('dropdown')
	  .addClass('tonesNav');	  

	
	var ringtonesNavCell = $('.nav_main ul li.tonesNav');   //change this selector to target a different cell in the top nav
		ringtonesNavCell.addClass('dropdown');
		
	$('.nav_main ul li.nav-custom a').filter(function(){
	  return (/\Extras/i).test($(this).text())
	}).parent()
	  .addClass('extrasNav');	  
	
	var extrasNavCell = $('.nav_main ul li.extrasNav');   //change this selector to target a different cell in the top nav
		/*
extrasNavCell.addClass('dropdown');	
*/
		
	/* Code for replacing all instances of album landing page link with album detail page link */
	$("a[href$=/album/]").attr("href", "/album/sean-paul-imperial-blaze-1/");
	
	/* Removing the upload from the top, and adding at the bottom; */
	uploadDiv = $("#home .nav_main ul li.upload");
	$("#home .nav_main div > ul").append(uploadDiv);
	uploadDiv.show();
		
	/*Hover event handler for all drop-downs in top nav */
	$(".dropdown").hover(
			function() { $(".flyoutMenu", this).show(); },
			function() { $(".flyoutMenu", this).hide(); }
	);
	
	/* Flag subnav pages in parent top nav li */
	if (location.href.indexOf("/member/") != -1) {
    if(!(location.href.indexOf("/category/member/") != -1)){ 
         communityNavCell.addClass("active");
         $("#memberNav").addClass("active");
     }  
     }	
	if (location.href.indexOf("/talk/") != -1) {
			communityNavCell.addClass("active");
			$("#discussionsNav").addClass("active");
		}
	if (location.href.indexOf("/ringtones/") != -1) {
		ringtonesNavCell.addClass("active");		
	}
	if (location.href.indexOf("/extras/") != -1) {
		extrasNavCell.addClass("active");		
	}
	
	if (location.href.indexOf("/album/") != -1) {	
		$("a[href^=/album/]").parent(".nav-custom").addClass("active");
	}
	if (location.href.indexOf("/music/") != -1) {	
		$("a[href^=/album/]").parent(".nav-custom").addClass("active");
	}
	if (location.href.indexOf("/take-a-tour/") != -1) {	
		communityNavCell.addClass("active");
		$("#takeatourNav").addClass("active");	
	}
	if (location.href.indexOf("/music/") != -1) {	
		$(".nav_main ul li.nav-custom a[href^='/albums/']").addClass("active");
	}
	
	
	
	if($("#sign_up-350438 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-350438 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-350438 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");
		}
	});
	
	


	/* 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 */	
	
	 //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"); 
	
	
	
	/* Make rel="external" links open in a new window */
	$("a[rel=external]").attr("target", "_new");
	/* Fixing the target for the digg link */
	$(".shareweb .digg a").attr("target", "_new");
	
	/* Setting the width of the nav bar*/
	$("#nav_global").css({width : '993px'});
	$("#nav_global").children("ul").css({width : '983px'});
	
	/* Append labels to elements in discussion module */
	$(".topics li.list .category li:first-child").prepend("Category: ");
	$(".topics li.list .activity").prepend("Replies: ");
	$(".topics li.list .date").prepend("Last Reply: ");
	
	/* Add "Close" text to close link in social media sharebox on photo and video detail pages */
	$(".sharebox .sb_head .sb_title a.shareclose").prepend("Close");
	
	/* Home page album links changing the title */
	$("#moduleForm382837 ul.albums li:last-child").addClass("albumsLastChild");
		
		
	/* 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');
			 }
		};
		
	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);	
			}
		}
	$('#rss_in-413300 .head').append('<div class="csDesc">Pics from Da Dutty Cam</div>');
	
	/* Make global top nav link does not open in new window*/
	$('.nav_main ul li.nav-custom a[href*=javascript:void(0)]').removeAttr("target");
	
	//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*/		
	
});

   if ($("body").attr("id") == "add_new_blog" && typeof tinyMCE !== 'undefined') {
   	tinyMCEEditor = tinyMCE.get('cmsgData[body]')
   	var tinyMCEtext = tinyMCEEditor.getContent();
   	var additionText = "<br><br><p>" + blogTwitterBlurbText + "</p>";
   	tinyMCEtext = tinyMCEtext + additionText;
   	tinyMCEEditor.setContent(tinyMCEtext);   }
   
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(); 
}