// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var $j = jQuery.noConflict();

(function ($j) {
$j.fn.vAlign = function() {
	return this.each(function(i){
		var ah = $j(this).height();
		var ph = $j(this).parent().height();
		var mh = (ph - ah) / 2;
		$j(this).css('margin-top', mh);
		});
};
})(jQuery);

(function ($j) {
$j.fn.vAlign2 = function() {
	return this.each(function(i){
		//var ah = $j(this).height();
		//var ph = $j(this).parent().height();
		//var mh = (ph - ah) / 2;
		var l = $j(this).html().length;
		var margin = 12;
		if (l > 17) {
			margin = 2;
		}		
		$j(this).css('padding-top', margin);
		});
};
})(jQuery);

(function ($j) {
$j.fn.ajustBg = function() {
	return this.each(function(i){
		var h = $j(this).height() + 30; // 10*2 for padding + 10 for bottom margin
		$j('body').css('background-position', '50% ' + h + 'px');
		});
};
})(jQuery);

function show_wip() {
	$j('#wip').css('display', 'block');
}

function hide_wip() {
	$j('#wip').css('display', 'none');
}

$j(function(){ 
	// find all the input elements with title attributes
	//$j('input[title!=""]').hint();
});



$j(document).ready(function() {
	
	// Setup the nav drop-downs
	$j('#nav').nmcDropDown({
    	show: {height: 'show', opacity: 'show'}
	});
	
	$j('#side-bar-nav').nmcDropDown({
    	trigger: 'click',
    	submenu_selector: 'p',
    	show: {height: 'show'},
    	hide: {height: 'hide'}
	});

	 
	$j('.sidebox').corner("round 6px").parent().css('padding', '2px').corner("round 8px");

 	$j("#register-to-use-im").fadeOut(800).fadeIn(800).fadeOut(400).fadeIn(400).fadeOut(400).fadeIn(400);

	$j('#quick-search-field').addClass("idleField");  
   $j('#quick-search-field').focus(function() {  
	        $j(this).removeClass("idleField").addClass("focusField");  
	        if (this.value == this.defaultValue){  
	            this.value = '';  
	        }  
	        if (this.value != this.defaultValue){  
	            this.select();  
	        }  
	    });
	

	// zoom on pics search results
  // http://www.queness.com/post/590/jquery-thumbnail-with-zooming-image-and-fading-caption-tutorial
  var move = -15;  
  var zoom = 1.2;  
  $j('.picture-profile').hover(function() {  
    width = $j('.picture-profile').width() * zoom;  
  	height = $j('.picture-profile').height() * zoom;  
  	$j(this).find('img').stop(false,true).animate({'width':width, 'height':height, 'top':move, 'left':move}, {duration:200});  
  	$j(this).find('div.caption').stop(false,true).fadeIn(200);  
  },  
  function() {  
  	$j(this).find('img').stop(false,true).animate({'width':$j('.picture-profile').width(), 'height':$j('.picture-profile').height(), 'top':'0', 'left':'0'}, {duration:100});    
  	$j(this).find('div.caption').stop(false,true).fadeOut(200);  
  });  
	
});