/* 
 * 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);


	function realignForDropShadow (moduleSelector,ajaxReq) {
	var startz_index=9;	
	var checkFirstChild=true;
	$(moduleSelector).each( function(){
 			$(this).css({'z-index': startz_index--});
			if(checkFirstChild){
				$(this).css({'margin-top': 0});
				checkFirstChild=false;
				if(ajaxReq){
					return;
				}
			}
		}
	 ); 
	 }
	  

$(document).ready(function(){
	
	
	$("#nav_global").children('ul').each(function(){
        var child=$("this");
        $(this).css({width: 993});
    }
    );
	

	realignForDropShadow("#leftWrapper .module",false); 
	realignForDropShadow("#centerWrapper .module",false);
	realignForDropShadow("#rightWrapper .module",false);

	 
	 
	

    /* Suppresses display of empty footers on IE */
    $('.module .foot:empty').addClass('empty');
	
		/*For fixing IE empty footer issue*/
	    var fullEmpty=true;
		$('#member_listing-666354 .module .foot').children('div').each(function(){
			$(this).html($(this).html().trim());
			if ($(this).is(":empty")) {
				$(this).addClass('empty');
			} else {
				var allChildEmpty=true;
				var $lastreferredChild;
				$(this).children().each(function(){
					
					$(this).html($(this).html().trim());
					if ($(this).is(":empty")) {
						$(this).addClass('empty');
					}else{
						allChildEmpty=false;
					}
					$lastreferredChild=$(this);
				});
				if(allChildEmpty){
					$lastreferredChild.parent().addClass('empty');
				} else {
					fullEmpty = false;
				}
			}
	});
if (fullEmpty) {
	$('#member_listing-666354 .module .foot').addClass('empty');
}
	
	

	 /* Make store top nav link open in a new window */
	$('.nav_main ul li.custom a[href*=amazon.com]').attr("rel", "external"); 	
	
	$('.article .description a[href*=/news/]').addClass("readmore");	
	
	$("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>');
    $(".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");
    
	/*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('dropdown')
	  .removeClass('nav-home')
	  .append(FCSubNav);
	  
	  
	   $customNavs.filter(function(){
		  return (/^Store$/i).test($(this).text())
		}).parent()
    	  .addClass('nav-custom')		 
		  .addClass('nav-store');

	
	  
	 $customNavs.filter(function(){
		  return (/^Global$/i).test($(this).text())
		 }).parent()
 		  .addClass('nav-custom')
		  .addClass('dropdown')
		  .addClass('nav-global_int')
		  .append(globalSubNav);
		  

	
	/* END: Custom drop-downs for top nav */
	
	/* ********** 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();}
	);
    
  
	
    if (location.href.indexOf("/forums/") != -1) {
        communityNavCell.addClass("active");
        $("#discussionsNav").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").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);

  
	$('#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*/	
       
});

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(); 		
	
	/*reset password screen*/	
	$('.reset_password .module .content .body').insertBefore('#errorMsg');
	
	$('#forgot_password_confirm-294542 .module .content .head h3').addClass('removeSifr');
	
	//for Reset pwd success page headers
	sIFR.replace(foundrymonolinebold, {
	  selector: '.m32 #moduleContainer1 .module .content .head h3:not(.removeSifr)',
	  css: [
	  	'.sIFR-root { text-transform: uppercase; color: #ffffff;font-size:14px;}',
	  	'.sIFR-root a {color:#ffffff; text-decoration:none}',
	  	'.sIFR-root a:hover {color:#ffffff}'
	  	],
	  tuneHeight: '-10',
	  wmode: 'transparent'
	});
	
	//for login page headers
	sIFR.replace(foundrymonolinebold, {
	  selector: '.m32 .module .content .head h3:not(.removeSifr)',
	  css: [
	  	'.sIFR-root { text-transform: uppercase; color: #ffffff;font-size:30px;}',
	  	'.sIFR-root a {color:#ffffff; text-decoration:none}',
	  	'.sIFR-root a:hover {color:#ffffff}'
	  	],
	  tuneHeight: '-10',
	  wmode: 'transparent'
	});
	
	
	//for page headers and module headers
	sIFR.replace(foundrymonolinebold, {
  selector: '.video_thumbnail .module .content .head h3,.blog_listing .module .content .head h3 ,.photo_thumbnail .module .content .head h3 , .photo_thumnail .module .content .head h3,.list_audio .module .content .head h3',
   css: [
  	'.sIFR-root { text-transform: uppercase; font-size:30px;color: #000000; }',
  	'.sIFR-root a {color:#000000; text-decoration:none}',
  	'.sIFR-root a:hover {color:#000000}'
  	],
  tuneHeight: '-10',
  wmode: 'transparent'
});

	realignForDropShadow("#centerWrapper .module",true);
	realignForDropShadow("#rightWrapper .module",true);
	realignForDropShadow("#leftWrapper .module",true);

	
}

   $.urlParam = function(name){
        var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
        if (results == null) {
            return 0;
        }
        else {
            return results[1];
        }
    }	
	



