/* -------------------------------------------------------------- 
  
   style.js
   * Javascript for
   * Author : Denis Fongue
   
-------------------------------------------------------------- */	



	 	/* Random Background
	 	var backgroundtotal = 3;
		$('html').addClass(function() {
		  return 'background' + Math.ceil(Math.random() * backgroundtotal);
		}); */
	
	 $(document).ready(function(){
	 
	 	// Relax News
	 	$("body.page-template article:first .entry").show();
	 	$("body.page-template article:first h4").toggleClass("selected");
	 	
	 	$("body.page-template article h4 a ").click( function(event){
	 				
	 				
	 				
	 				if (!$(this).parent().hasClass("selected")) {
	 				event.preventDefault();
					$("body.page-template article .entry").slideUp('slow');
					$('.selected').toggleClass("selected");
					$(this).parent().toggleClass("selected");
					
					var href = $(this).attr("href");
					
					$(this).parent().parent().children("div").slideDown('slow', function(){
				 	$.scrollTo(href,600);
					});
					
					}
					 
				 	return false;
					
		});
	 		
	 
	 	//Clear Search Input on Focus
	 	$("input.search-input").focus(function() {
			clearDefaultInput(this);
		});
		
		$("input.search-input").blur(function() {
			myValue = $.trim(this.value);
			if (myValue == ''){  
	            this.value = (this.defaultValue ? this.defaultValue : '');  
	        } 
		}); 
		
		function clearDefaultInput(el) {
		  if (el.defaultValue==el.value) el.value = "";
		}
	 	
		//Images in rounded mask  
		$("aside.thumbnail.rounded").each(function() {
    		var my_img_src = $(this).children("img").attr("src");
    		$(this).children("div.mask").css({'position':'relative','background-image':'url('+my_img_src+')', 'background-position':'center center'});
    		$(this).children("img").remove();
  		}); 
  		
	 	/****/
		function RoundedMaskResize() {
	 		$("aside.thumbnail.rounded").each(function(){
	 		
	 			var mask_width = $(this).children("div.mask").width();
	 			$(this).children("div.mask").height(mask_width);
	 		});
	 	}
	 
	 	// 
	 	
	 	if ($(document).width() >= 1240 && $(document).width() <= 1440 ) {
	 		RoundedMaskResize();
	 	}
	 	
	 	
	 	$(window).resize(function(){
	 		if ($(document).width() >= 1240 && $(document).width() <= 1440 ) {
	 			RoundedMaskResize();
	 		}
	 		else if ($(document).width() > 1440){
	 			$("aside.rounded div.mask").height(80);
	 			$("article.post.sticky aside.thumbnail.rounded div.mask").height(140);
	 			
	 		}
	 		else if ($(document).width() < 1240){
	 			$("aside.thumbnail.rounded div.mask").height(64);
	 			$("article.post.sticky aside.thumbnail.rounded div.mask").height(104);
	 			
	 		}
	 	});
		  

	});
