/* 
 * Jquery browser detect plugin to identify browser/os detection.
 * jQuery Browser Plugin - http://jquery.thewikies.com/browser/
*/
(function($){$.browserTest=function(a,z){var u='unknown',x='X',m=function(r,h){for(var i=0;i<h.length;i=i+1){r=r.replace(h[i][0],h[i][1]);}return r;},c=function(i,a,b,c){var r={name:m((a.exec(i)||[u,u])[1],b)};r[r.name]=true;r.version=(c.exec(i)||[x,x,x,x])[3];if(r.name.match(/safari/)&&r.version>400){r.version='2.0';}if(r.name==='presto'){r.version=($.browser.version>9.27)?'futhark':'linear_b';}r.versionNumber=parseFloat(r.version,10)||0;r.versionX=(r.version!==x)?(r.version+'').substr(0,1):x;r.className=r.name+r.versionX;return r;};a=(a.match(/Opera|Navigator|Minefield|KHTML|Chrome/)?m(a,[[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/,''],['Chrome Safari','Chrome'],['KHTML','Konqueror'],['Minefield','Firefox'],['Navigator','Netscape']]):a).toLowerCase();$.browser=$.extend((!z)?$.browser:{},c(a,/(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/,[],/(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/));$.layout=c(a,/(gecko|konqueror|msie|opera|webkit)/,[['konqueror','khtml'],['msie','trident'],['opera','presto']],/(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/);$.os={name:(/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase())||[u])[0].replace('sunos','solaris')};if(!z){$('html').addClass([$.os.name,$.browser.name,$.browser.className,$.layout.name,$.layout.className].join(' '));}};$.browserTest(navigator.userAgent,true);})(jQuery);


var privacyPolicyText   = 'By 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 Halestormrocks.com with the latest news, updates and information about Halestorm';

$(document).ready(function(){

	
	ord=Math.random()*10000000000000000;
		/* Suppresses display of empty footers on IE */
	$('.module .foot:empty').addClass('empty');
	
	/* Setting the browser name and classname*/
	$("html").addClass($.os.name);
	$("body").addClass($.browser.className);
	
	/* Fix for Bug#2247 - upload issue*/	
	$('#upload .module .content .head h3').addClass('removeSifr');
	$('#upload .module .content .body h3').addClass('removeSifr');
	$('#upload .module .content .body h4').addClass('removeSifr');
	$('#upload h1.pageTitle').addClass('removeSifr');	
	
	/* START Add "Launch Player" links to footer nav of all audio playlist modules */
	var launchLink =  $('<li class="launchPlayer"><a href="/music-player/" class="launchPlayerLink">Launch Player</a></li>');
	$(".song_playlist .module .content .nav_meta ul").prepend(launchLink);
	/* END Add "Launch Player" links to footer nav of all audio playlist modules */
	
	/* add popup onClick handler for audio player links */
	$("a.launchPlayerLink").click(function() {
			window.open("/music-player/", "Window2", "width=375,height=275,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no"); 
			return false;
	});
	
	/* Make store top nav link open in a new window */
	$('.nav_main ul li.nav-custom a[href*=amazon.com]').attr("rel", "external");
	
	
	
	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 */
	

		$('.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 */	
	
		
	/*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("/album/") != -1) {	
		$("a[href^=/album/]").parent(".nav-custom").addClass("active");
	}
	if (location.href.indexOf("/take-a-tour/") != -1) {	
		$(".nav_main .nav-community_landing").addClass("active");
	}
	if (location.href.indexOf("/upload/") != -1) {	
		$(".nav_main .upload").addClass("active");
	}
	if (location.href.indexOf("/music/") != -1) {	
		$(".nav_main ul li.nav-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 */	
	
	

	/* 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");
		
		
	if($("#sign_up-350438 li.input input").attr('class')== "focused"){		
		$descriptionDisplay = $("#sign_up-350438 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");
		}
	});	
		
	/* 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);	
			}
		}
	
	 //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"); 
	
	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);	
			}
		}

		TwitterMap = {
	    "lzzyhale": {
		"name"		: "Lzzy",
		"profileUrl": "/member/i/159727/",
		"color"		: "#8D3424"
	    },
	    "jodowa": {
		"name"		: "Josh",
		"profileUrl": "/member/i/159739/",
		"color"		: "#8D3424"
	    },
	    "thejoestorm": {
		"name"		: "Joe",
		"profileUrl": "/member/i/159748/",
		"color"		: "#8D3424"
	    },
	    "arejayhale": {
		"name"		: "Arejay",
		"profileUrl": "/member/i/159752/",
		"color"		: "#8D3424"
	    },
	    "halestormrocks": {
		"name"		: "Halestorm",
		"profileUrl": "/member/i/159707/",
		"color"		: "#8D3424"
	    }
	};


		/* Modifications in the navigation bar */
	$('.nav_main ul li.nav-custom a').filter(function(){
	  return (/\Music/i).test($(this).text())
	}).parent()
	  .addClass('nav-music');
	$('.nav_main ul li.nav-custom a').filter(function(){
	  return (/\Fan Club/i).test($(this).text())
	}).parent()
	  .addClass('nav-fanclub');
	$('.nav_main ul li.nav-custom a').filter(function(){
	  return (/\Store/i).test($(this).text())
	}).parent()
	  .addClass('nav-store');
	  
	  
	//to hide empty fan photo/video categories
	$('#photo #moduleContainer2 .categories .module .body #category-list .division:last-child ul li a:not(:contains("("))').parent().parent().hide();
	$('#photo_detail #moduleContainer3 .categories .module .body #category-list .division:last-child ul li a:not(:contains("("))').parent().parent().hide();
	$('#video #moduleContainer2 .categories .module .body #category-list .division:last-child ul li a:not(:contains("("))').parent().parent().hide();
	$('#video_detail #moduleContainer3 .categories .module .body #category-list .division:last-child ul li a:not(:contains("("))').parent().parent().hide();
	  
	  /* Home page album links changing the title */
	$("#blog_listing-350371 ul.articles li:last-child").addClass("blogLastChild");
	
	//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*/	
 
});

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();    
 	
	//for page headers and module headers
	sIFR.replace(rock, {
	  selector: '.blog_listing .module .content .head h3,#photo_detail .photo_thumnail .module .content .head h3',
	  css: '.sIFR-root { color: #F7F0E2; text-align:center; font-size:16px; text-decoration:none;text-transform: uppercase;  }',	  
	  wmode: 'transparent',
	  tuneHeight: '1'
	});
	
}
