$j(document).ready(function(){

    // First and last classes
    $j('.pre-nav li:last, .tFooter li:last').addClass('last');
    $j('.productresults tbody tr td .cell:first-child').addClass('first');
    $j('.productresults tbody tr td .cell:last-child').addClass('last');
    $j('.productresults tbody tr:last td').addClass('bottom');

    // Main navigation
    $j('#nav li:first a').css({ 'margin-left': '15px' });
    $j('#nav li:last a').css({ 'margin-right': 0 });
    
	// Product finder 
	
	$j('#product_finder').change(function() {
		$j('#product_finder_form').attr('action',$j(this).val()).submit();
	});
	
    // Search placeholder
    $j('#query').each(function(){
        var placeholder = 'Search';
        $j(this).attr('value', placeholder);
        $j(this).addClass('blurred');
        $j(this).focus(function(){
            if ($j(this).attr('value') == placeholder) {
                $j(this).removeClass('blurred').attr('value', '');
            }
        });
        $j(this).blur(function(){
            if ($j(this).attr('value') == '') {
                $j(this).addClass('blurred').attr('value', placeholder);
            }
        });
    });
    
    $j('td').each(function(){
        $j(this).wrapInner('<div/>').children('div').addClass('cell');
    });
    
    // Equal heights...zzzz...
    // Uhh...not working...?
    function equalize(parent, offset) {
        parent.each(function(offset){
            var tallest = 0;
            $j(this).children().each(function(){
                thisHeight = $j(this).height();
                if (thisHeight > tallest) {
                    tallest = thisHeight;
                }
            });
            $j(this).children().each(function(){
                $j(this).height(tallest);
            });
        });
    }
    // equalize($j('#main .equal'), 17);

    
    // Product detail tabs
//    $j('.tabs-nav').tabs('.tabs-panel');

    // Fadey fade + arrows on category homepage
    $j('.category p a').append('<span class="enhanced"/>').hover(function(){
        $j(this).find('.enhanced').stop(true, true).fadeIn('fast');
    }, function(){
        $j(this).find('.enhanced').stop(true, true).fadeOut('fast');
    });
    
    // Vertical centering
//     $j('.category p a span').not('.enhanced, .arrow').each(function(){
//         var move = ($j(this).parent().height() - $j(this).height()) / 2;
//         $j(this).css({ 'top': move + 'px' });
//     });
//             
//     $j('.category').each(function(){
//         var total = $j(this).find('.thumb > a').height();
//         var image_width;
//         var image_height;
//         $j(this).find('img').load(function() {
//             image_width = this.width;
//             image_height = this.height;
//             var move = Math.round((total - image_height) / 2);
//             $j(this).css({ 'top': move + 'px' });   
//         });
//     });
});
