$(document).ready(function() {
    // Prevent IE from displaying alt text as tooltips here
    $("#search_results img").attr("title","");
    
    // Initialize the tooltips  
	$("#search_results > div > a")
	.tooltip({ 
            // use "slide" effect 
            effect: 'slide',
            position: "center right",
            predelay: 200,
            offset: [0, 9],
            relative: true,
            lazy: false
        // add dynamic plugin  
        })
    .dynamic({
        top: { 
            // slide downwards 
            direction: 'up', 
            // bounce back when closed 
            bounce: true,
            offset: [0, -140]
        },
        bottom: { 
            // slide downwards 
            direction: 'down', 
            // bounce back when closed 
            bounce: true,
            offset: [0, -140]
        },
        left: { 
            // slide downwards 
            direction: 'left', 
            // bounce back when closed 
            bounce: true,
            offset: [0, 0]
        }
    });
    
    $('#content_mainA form').jqTransform();
    $('#content_mainA form button span span').addClass('hiddenText');
    $('#keywords_search').labelify({
      text: "label"
    });
    
    var category_name = $('h3 span.category').text();
    
    $('.photo_categories .jqTransformSelectWrapper li a')
    .click(function() 
        { 
			if ($(this).text() == 'Archive by Date') {
                $('#content_mainA fieldset').show();
                $('#content_mainA form button').removeClass('toprow');
            } else {
                $('#content_mainA fieldset').hide();
                $('#content_mainA form button').addClass('toprow');
            }
        })
    .each(function()
        {
            if ($(this).text() == category_name) {
                $(this).addClass('selected');
                $('.photo_categories .jqTransformSelectWrapper span').text(category_name);
            } else {
                $(this).removeClass('selected');
            }
        });
        
    if ($('.photo_categories .jqTransformSelectWrapper li a.selected').text() == 'Archive by Date') {
        $('#content_mainA fieldset').show();
        $('#content_mainA form button').removeClass('toprow');
    } else {
        $('#content_mainA fieldset').hide();
        $('#content_mainA form button').addClass('toprow');
        
    }
    
    $('#photo_submit').after('<div id="form_errors"></div>');
            
    $("#content_mainA form").submit(function() {
		if ($('.photo_categories .jqTransformSelectWrapper span').text() == "Archive by Date") {
            if ($("fieldset .jqTransformSelectWrapper span:contains('---')").length != 0) {
                $('#form_errors').html('Please select a month and year');
                return false;
            }            
        }

    });

	/* commenting out -- hasError isn't defined anywhere and is causing errors in layout manager 
	if(hasError)$("#form_errors").html('Please select a month and year'); */
        
});