// JavaScript Document general scripts for every page

$(document).ready(function(){
	
	/* detect mobile */
	/**********************/
	var detectMobile = function(){
		if($(window).width()<=463/* && $('body:not(.mobile)')*/) {
			
			//hide paragraph
			$('.articles .article-content p:not(.short), .articles .article-content p:not(.mobi), div .article-results .article-content p:not(.mobi)').hide();
			if($('.carousel').length>0){
				$('.carousel .article-content p').show()
			}
			
			//run through articles
			$('.articles article, .article-results article').each(function(index){	/*.jobs article,.jobs-results article,*/
				//only show first article
				if($("p.mobi", this).length == 0 && $("p", this).length > 0){
					var shortPar = $('.article-content',this).children('p').eq(0).text().substring(0,150);
					$('.article-content',this).append('<p class="mobi">'+shortPar+'...</p>');
				}else{
					if($("p.mobi",this).is(':hidden')) {
						$('.article-content p.mobi').show();
					}
				}
				
				if(index < 3){
					$('a', this).addClass("open");
				}
				
				//collapse articles from 4 to the end
				if(index >= 3){
					$('a:not(.star)', this).addClass("closed");
					if($(this).parents('.articles').length > 0){
						$('img', this).hide();
					}
					$('.article-content',this).hide();		
				
				}
				
			})
			

			//toggle articles, jobs
			/**/
			//$('.mobile .articles article a, .mobile div .jobs article a, .mobile div .jobs-results article a:not(.star), .mobile div .article-results article a').click(function(){
			$('.articles article a, div .jobs article a, div .jobs-results article a:not(.star), div .article-results article a').click(function(){
													
				if($('.article-content',this).is(':hidden')) {
					$('a.sel .article-content').hide();
					$('article a:not(.open):last-child').removeClass('sel').addClass('closed');
					$(this).removeClass('closed').addClass('sel');
					$('.article-content',this).fadeIn();					
					return false;
				}else{
					return true;
				}
			})
			
	
		}else if($('body').hasClass('mobile')){
			
			//show full paragraph articles
			$('.article-content p.mobi').remove();
			$('.article-content p').show();
			
			//show item 4-end
			$('div:not(.col1) .articles article').each(function(index){
				if(index >= 3){
					$('img', this).show()
					$('.article-content',this).show();		
				}
			})

			$('div:not(.col1) .jobs article').each(function(index){
				if(index >= 3){
					$('img', this).show()
					$('.article-content',this).show();		
				}
			})
			
			$('div:not(.col1) .jobs-results article, div:not(.col1) .article-results article').each(function(index){
				if(index >= 3){
					$('img', this).show()
					$('.article-content',this).show();		
				}
			})
			
		}
	}
	detectMobile();

	$(window).resize(function() {
		detectMobile();
	});

	/*$('.articles > div').hover(function(){
		$(this).addClass('hover')
	},function() {
		$(this).removeClass('hover')
	});*/
});




