jQuery.noConflict();
jQuery(document).ready(function($){ 
    $('body').pngFix();
    $('#footer').show();
    $('#container .tout').show();
 	$('#container .result').show();

	$('#login #email').focus();

	$("#searchtag").autocomplete("../inc/taglist.php", {
		width: 320,
		max: 10,
		highlight: false,
		multiple: false,
		scroll: true,
		scrollHeight: 300
	});
	
	$("#advanced").bgiframe({src:"about:blank"});
    
    $('.dropdown p').click(function () {
    	$('.dropdown').children('ul').hide();
    	$(this).parent().children('ul').toggle();
    	/*
    	$(this).parent().children('ul').bind("mouseleave", function() {
    		$(this).parent().children('ul').hide();
    	});
    	*/
    });
    
	$('.dropdown').children('ul').bind("mouseleave", function() {
		$(this).hide();
	});
    
    
	$('.arrow').click(function () {
    	$('.dropdown').children('ul').hide();
    	$(this).siblings('.dropdown').children('ul').toggle();
    	$(this).siblings('.dropdown').children('ul').bind("mouseleave", function() {
    		$(this).siblings('.dropdown').children('ul').hide();
    	});
    });
    
    $('.dropdown ul li').hover(
    	function () {
    		$(this).css('background-color', '#eaeaea');
    	},
    	function () {
    		$(this).css('background-color', '#fff');
    	}
    )
    
    $('#header .dropdown ul li').click(function() {
    	$(this).parent().parent().children('p.selected').text($(this).text());
    	$(this).parent().hide();
    	$('#searchtype_nav').attr('value', $(this).attr('rel'));
    });
    
    $('#searchtype_select ul li').click(function() {
    	$(this).parent().parent().children('p.selected').text($(this).text());
    	$(this).parent().hide();
    	$('#search_page #searchtype').attr('value', $(this).attr('rel'));
    });
    
//    $('.tout .dropdown ul li').click(function() {
    $('#search_tout .dropdown ul li').click(function() {
    	$(this).parent().parent().children('p.selected').text($(this).text());
    	$(this).parent().hide();
//    	$('#container #searchtype').attr('value', $(this).attr('rel'));
    	$('#searchtype').attr('value', $(this).attr('rel'));
    });
    
    $('#showing .dropdown ul li').click(function() {
    	$(this).parent().parent().children('p.selected').text($(this).text());
    	$(this).parent().hide();
    	$('#ordertype').attr('value', $(this).attr('rel'));
    	$("form:story-search").submit();
    	
    });
    
    $('input.search').focus(function () {
    	$(this).attr('value', '');
    	$(this).css('font-style', 'normal');
    });
    
    $('input.search').blur(function () {
    	if ($(this).attr('value') == '') {
    		$(this).css('font-style', 'italic');
    		$(this).attr('value', $(this).attr('rel'));
    	}	
    });
    
    $('#container .advanced').hover(
    	function () {
    		$('#container #advanced_rollover').show();
    	},
    	function () {
    		$('#container #advanced_rollover').hide();
    	}
    )
    
    $('#advanced_toggle .refine').click(function () {
    	$('#advanced_toggle').hide();
    	$('#results.advanced').hide();
    	$('#pages').hide();
    	$('.bottom').hide();
    	$('#search_filter').show();
    });
    
});

function open_window(url) {
	newwindow=window.open(url,'name','height=600,width=600,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}