
/* 
 * Jquery browser detect plugin to identify browser/os detection.
 * jQuery Browser Plugin - http://jquery.thewikies.com/browser/
 */

/*
 * Jquery Plugin - opens external links in a new window.  
 * Checks if the links are relative, and are of the same domain.
 * Sampe Usage - $("#someDiv a").makeLinksExternal();_6
 */
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")}})};


/* Supplant Function. Remedial JS. Thanks to Douglas Crockford. 
 * Substitues the variables in a string. The variables must be preceded by {}.
*/

if(!String.prototype.supplant){String.prototype.supplant=function(a){return this.replace(/{([^{}]*)}/g,function(d,c){var e=a[c];return typeof e==="string"||typeof e==="number"?e:d})}};


$(document).ready(function(){
	
	/*js for international all dates translation*/
	$('body#international_france_home.international .event_listing .module .content .head .nav_meta ul li.more a').text('toutes les dates');
	$('body#international_germay_home.international .event_listing .module .content .head .nav_meta ul li.more a').text('alle Termine');
	$('body#international_italy_home.international .event_listing .module .content .head .nav_meta ul li.more a').text('tutte le date');
	$('body#international_spain_home.international .event_listing .module .content .head .nav_meta ul li.more a').text('todas las fechas');


	/*german translations*/
	$('#international_germay_home .video_thumbnail .nav_meta ul li.more a').html('mehr Videos');
	$('#international_germay_home .photo_thumbnail .nav_meta ul li.more a').html('mehr Fotos');
	
	/*france translations*/
	$('#international_france_home .video_thumbnail .nav_meta ul li.more a').html('plus de videos');
	$('#international_france_home .photo_thumbnail .nav_meta ul li.more a').html('plus de photos');
	
	/*spain translations*/
	$('#international_spain_home .video_thumbnail .nav_meta ul li.more a').html('mas videos');
	$('#international_spain_home .photo_thumbnail .nav_meta ul li.more a').html('mas fotos');
	
	/*italy translations*/
	$('#international_italy_home .video_thumbnail .nav_meta ul li.more a').html('altri video');
	$('#international_italy_home .photo_thumbnail .nav_meta ul li.more a').html('altre foto');
	
	/*finland translations*/
	$('#international_finland_home .rss_in.blog_listing li.article .activity .keepreading a').html('pitää käsittelyssä');
	$('#international_finland_home .rss_in.blog_listing .foot .rssblogFoot a').html('Katso kaikki uutiset');
	$('#international_finland_home .video_thumbnail .nav_meta li.more a').html('lisää videoita');
	$('#international_finland_home .photo_thumbnail .nav_meta li.more a').html('lisää kuvia');
	$('#international_finland_home .event_listing .nav_meta li.more a').html('kaikki päivämäärät');
	
	/*sweden translations*/
	$('#international_sweden_home .rss_in.blog_listing li.article .activity .keepreading a').html('hålla behandlingen');
	$('#international_sweden_home .rss_in.blog_listing .foot .rssblogFoot a').html('visa alla nyheter');
	$('#international_sweden_home .video_thumbnail .nav_meta li.more a').html('fler videor');
	$('#international_sweden_home .photo_thumbnail .nav_meta li.more a').html('fler bilder');
	$('#international_sweden_home .event_listing .nav_meta li.more a').html('alla datum');
	
		
	
	/* Fanclub nav - fix - begins */
	var fan_url=window.location.pathname;	
	if (location.href.indexOf("/group/hooligans/?intcmp=brunomars/fanclub-landing/global-nav") != -1){
		$('.nav_main li.nav-fanclub').addClass('active');
	}
	else{
		$('.nav_main li.nav-fanclub').removeClass('active');
	}
	
	var fnews_url=window.location.pathname;	
	if(fnews_url == "/news/category/fan-club-news/"){		
		$('.nav_main ul.flyoutMenu li#FCNews').addClass('active');
		$('.nav_main ul li.nav-fanclub').addClass('active');
		$('.nav_main ul li.nav-blog').removeClass('active');
	}
	else{
		$('.nav_main ul.flyoutMenu li#FCNews').removeClass('active');
	}
	
	var fphoto_url=window.location.pathname;	
	if(fphoto_url == "/photo/category/hooligans-exclusive-photos/"){		
		$('.nav_main ul.flyoutMenu li#FCPhoto').addClass('active');
		$('.nav_main ul li.nav-fanclub').addClass('active');
		$('.nav_main ul li.nav-photo').removeClass('active');
	}
	else{
		$('.nav_main ul.flyoutMenu li#FCPhoto').removeClass('active');
	}
	
	var fvideo_url=window.location.pathname;	
	if(fvideo_url == "/video/category/official-hooligans-videos/"){		
		$('.nav_main ul.flyoutMenu li#FCVideo').addClass('active');
		$('.nav_main ul li.nav-fanclub').addClass('active');
		$('.nav_main ul li.nav-video').removeClass('active');
	}
	else{
		$('.nav_main ul.flyoutMenu li#FCVideo').removeClass('active');
	}
	
	var fdiscussion_url=window.location.pathname;	
	if(fdiscussion_url == "/forums/category/hooligans-fan-club-talk/"){		
		$('.nav_main ul.flyoutMenu li#FCForumNav').addClass('active');
		$('.nav_main ul li.nav-fanclub').addClass('active');
		$('.nav_main ul li.nav-community_landing').removeClass('active');
		$('.nav_main ul.flyoutMenu li#discussionsNav').removeClass('active');
	}
	else{
		$('.nav_main ul.flyoutMenu li#FCForumNav').removeClass('active');
	}
	
	var fchat_url=window.location.pathname;	
	if(fchat_url == "/hooligans-chat/"){		
		$('.nav_main ul.flyoutMenu li#FCForumchat').addClass('active');
		$('.nav_main ul li.nav-fanclub').addClass('active');
		$('.nav_main ul li.nav-community_landing').removeClass('active');
		$('.nav_main ul.flyoutMenu li#chatNav').removeClass('active');
	}
	else{
		$('.nav_main ul.flyoutMenu li#FCForumchat').removeClass('active');
	}
	
	/* chat nav - fix - begins */
	var chat_url=window.location.pathname;	
	if(chat_url == "/chat/"){		
		$('.nav_main ul.flyoutMenu li#chatNav').addClass('active');
		$('.nav_main ul li.nav-community_landing').addClass('active');
	}
	else{
		$('.nav_main ul.flyoutMenu li#chatNav').removeClass('active');
	}
	/* chat nav - fix - ends */
	
	/* Blog and detail page members module alignment - begins */
	var memberCount=1;
	$('.members li.m').each(function(){
		memberCount=memberCount%4;
		if(memberCount==1){
			$(this).addClass('first');
		}
		memberCount=memberCount+1;
	});
	/* Blog and detail page members module alignment - ends */


	$('#html-5586824.html .cellstream .cs_anchor').addClass('selected');

	$('.blog_entry .module .content .body .article .meta .category ul a').each(function(){
	var trunc = (this).innerHTML;
	trunc=trunc.trim();
	if (trunc.length > 8) {
		trunc = trunc.substring(0, 8);
		trunc += '<span>' + '...</span>';
		(this).innerHTML = trunc;
	}
	});
	
	/* Design review comment - fix in blog detail page - begins*/
	$('.blog_entry .module .content .body div.article .category').insertBefore('.blog_entry .module .content .body div.article .tools ul li.sharelink.vd');
	/* Design review comment - fix in blog detail page - ends */
	
	
	
	/* home page and international - photos hover effect - begins */
	$('#home .photos li.m').hover(
	function(){$(this).addClass('on');},
	function(){$(this).removeClass('on');}
	); 
	$('.international .photos li.m').hover(
	function(){$(this).addClass('on');},
	function(){$(this).removeClass('on');}
	); 
	/* home page - photos hover effect - ends */
	
	/* fanclub page - photos hover effect - begins */
	$('body#group_detail_7251 .photos li.photo').hover(
	function(){$(this).addClass('on');},
	function(){$(this).removeClass('on');}
	); 
	/* fanclub page - photos hover effect - ends */
	
	
	/* Keep Reading fix - begins */
	var $customReadMoreClass = $('.blog_listing .description a');
	$customReadMoreClass.filter(function(){
	return (/^keep reading/i).test($(this).text())
	}).addClass('readmore');
	
	$('.blog_listing .module .content .body .articles li').each(function(){
		$(this).find('.description a.readmore').insertAfter($(this).find('.activity a.comment'));
	});
	
	/* Keep Reading fix - ends */
	
	/* blog detail page - changing comments to read comments */
	var comments_text=$('#blog_detail a.comment').text();
	comments_text="read " + comments_text;
	$('#blog_detail a.comment').text(comments_text);
	
	var comments_text=$('#blog_detail span.comment').text();
	comments_text="read " + comments_text;
	$('#blog_detail span.comment').text(comments_text);
	
	$("#member_detail .member_detail .membergroups ul").each(function(){	
		if ($(this).find("li").length > 0) {	
			$(this).html('<li class="badgeImageReplace"><a class="badge" href="/group/hooligans/">Hooligans</a>member</li>');
		}
	});
	
	/* community page */
	$('.member_listing .module .content .foot .nav_meta ul .register').insertAfter('#member_listing-340499.member_listing .module .content .head .title .nav_meta ul .more');
	/* community page*/
	
	
	/* Changing round bracket to square bracket in counts - begins */
	        $('#member_listing-294561 .module .content .head h3 span.total').each(function(){
	        var count=$(this).text(); 
	        var count=count.replace("(","[");
	        var count=count.replace(")","]");
	        $(this).text(count);
	        });	        
	        
	        $('#list_album-383753 .module .content .head h3 span.total').each(function(){
			        var count=$(this).text(); 
			        var count=count.replace("(","[");
			        var count=count.replace(")","]");
			        $(this).text(count);
	        });
	        
	        $('#member_listing-294561 .module .content .head h3 span.total').each(function(){
			        var count=$(this).text(); 
			        var count=count.replace("(","[");
			        var count=count.replace(")","]");
			        $(this).text(count);
	        });
	        
	        $('#photo_thumbnail-294569 .module .content .head h3 span.total').each(function(){
			        var count=$(this).text(); 
			        var count=count.replace("(","[");
			        var count=count.replace(")","]");
			        $(this).text(count);
	        });
	        
	        $('#video_thumbnail-294591 .module .content .head h3 span.total').each(function(){
			        var count=$(this).text(); 
			        var count=count.replace("(","[");
			        var count=count.replace(")","]");
			        $(this).text(count);
	        });
			$('#photo_thumbnail-294570 .module .content .head h3 span.total').each(function(){
			        var count=$(this).text(); 
			        var count=count.replace("(","[");
			        var count=count.replace(")","]");
			        $(this).text(count);
	        });	
	        
	        $('#list_album-407371 .module .content .head h3 span.total').each(function(){
			        var count=$(this).text(); 
			        var count=count.replace("(","[");
			        var count=count.replace(")","]");
			        $(this).text(count);
	        });
	        
	        $('#photo_thumnail-294571 .module .content .head h3 span.total').each(function(){
			        var count=$(this).text(); 
			        var count=count.replace("(","[");
			        var count=count.replace(")","]");
			        $(this).text(count);
	        });
	        
	        $('#video_thumbnail-294593 .module .content .head h3 span.total').each(function(){
			        var count=$(this).text(); 
			        var count=count.replace("(","[");
			        var count=count.replace(")","]");
			        $(this).text(count);
	        });
	        
	        $('#member_listing-666354 .module .content .head h3 span.total').each(function(){
			        var count=$(this).text(); 
			        var count=count.replace("(","[");
			        var count=count.replace(")","]");
			        $(this).text(count);
	        });
	        
	        $('#member_listing-340499 .module .content .head h3 span.total').each(function(){
			        var count=$(this).text(); 
			        var count=count.replace("(","[");
			        var count=count.replace(")","]");
			        $(this).text(count);
	        });
	        
	        $('#video_thumbnail-340502 .module .content .head h3 span.total').each(function(){
			        var count=$(this).text(); 
			        var count=count.replace("(","[");
			        var count=count.replace(")","]");
			        $(this).text(count);
	        });
	        
	        $('#photo_thumbnail-340501 .module .content .head h3 span.total').each(function(){
			        var count=$(this).text(); 
			        var count=count.replace("(","[");
			        var count=count.replace(")","]");
			        $(this).text(count);
	        });
			
			$('#photo_thumbnail-4108889 .module .content .head h3 span.total').each(function(){
			        var count=$(this).text(); 
			        var count=count.replace("(","[");
			        var count=count.replace(")","]");
			        $(this).text(count);
	        });	
			
			$('#video_thumbnail-4108890 .module .content .head h3 span.total').each(function(){
			        var count=$(this).text(); 
			        var count=count.replace("(","[");
			        var count=count.replace(")","]");
			        $(this).text(count);
	        });			
			
    /* Changing round bracket to square bracket in counts - ends */
	
});

