var $ = jQuery.noConflict();


jQuery(document).ready(function($) {
	
	$(document).click(function() {
            if ( $('.search-form').is(':visible') ) { 
                    $('.search-form').fadeOut(200);
	    }
        });
        
        $('.search').click(function(e) {
                e.stopPropagation();
                $('.search-form').toggle();            
        });
        
         $('.search-form').click(function(e) {
                e.stopPropagation(); 
        });
	
	rainbows.init({
		selector: '#header h1',
		highlight: false,
		shadow: false,
		from: '#ffffff',
		to: '#999999'
	});
	
	rainbows.init({
		selector: '.description',
		highlight: false,
		shadow: false,
		from: '#cccccc',
		to: '#666666'
	});
	
	
	rainbows.init({
		selector: '#content h2',
		highlight: false,
		shadow: false,
		from: '#999999',
		to: '#000000'
	});
	 $(".topbar ul").superfish({
		//firstOnClick: true,
		minWidth:    20,   // minimum width of sub-menus in em units 
		maxWidth:    27,   // maximum width of sub-menus in em units
		speed:  0
                
	});
	
	$(".login-button").fancybox(
	{
		'overlayColor'	:		'#000',
		'zoomOpacity'			: true,
		'hideOnContentClick'		: false,
		'zoomSpeedIn'			: 500,
		'zoomSpeedOut'			: 500
	}
	);
	
	
	 
        
	
	var margintop = 0;

	
	$('.widgets .widget').each(function(index){
		margintop += $(this).prev(".widget").height() + 30;
		$(this).css({'margin-top' : margintop});
		$(this).prepend("<div class='widget-top'></div>");
		$(this).append("<div class='widget-bottom'></div>");
		
		$(this).children().each(function(index){
			$(this).not(".widget-top, .widget-bottom, .widget-title, .clear").wrap("<div class='inner-widget'></div>");
			$(this).not(".widget-top, .widget-bottom, .widget-title, .clear").css({'padding' : '20px', 'clear' : 'both'});
		});
	
	});
	

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

	$(window).bind("resize", resizeWindow);
		function resizeWindow( e ) {
			$('.inside').vAlign();
	};
	
	jQuery.fn.fadeToggle = function(speed, easing, callback) {
	 return this.animate({opacity: 'toggle'}, speed, easing, callback);  
	};
	
        $('.topbar ul li ul li ul').each(function(index){
		var left = $(this).parent().parent().width();
		
		$(this).css({'left' : left});
	});	
	
	
	$(".dock ul li a img").hover(
		function(){
			$(this).animate({ 
			width:"46px",
			height:"46px"
			},80);			
			
	},
		function(){
			$(".dock ul li a img").animate({ 
			width:"40px",
			height:"40px"
			},80);
		}
		
	
	);
	
	

	$('.widget-title').click(function() {
		$(this).parent().children(".inner-widget").toggle("blind",'200');
		return false;
	});
	
	$('.close').click(function() {
		$(this).parent().parent().fadeOut("fast");
		return false;
	});

	 
	 $('.post-title').click(function() {
		$(this).parent().children(".entry-content").toggle("blind",'200');
		
		return false;
	});
	
	$('.dashboard').click(function() {
		$('.widgets').fadeToggle(400);
		return false;
	});
	
	 	
	$('#page').draggable({ handle: '.page-top' });
	
	$('.widgets .widget').draggable({ handle: '.widget-top'});
});	