/* Author: mij@llgc.org.uk

*/

// Do this to keep mootools from breaking on sitemap :(
var $j = jQuery.noConflict();

$j(document).ready(function() {	
	autocomp_lang = $j('html').attr('lang'); // get html lang - used for autocomplete drop down

    /***************************************************************************************/
    // Autocomplete
    // drop down list of libraries - used on sidebar and find your library pages
	if(autocomp_lang == 'cy_GB') autocomp_lang = autocomp_lang.replace('_GB','');

	$j.ajax({
		url: "/fileadmin/autocomplete/libs.xml",
		dataType: "xml",
		success: function( xmlResponse ) {
			var data = $j( "geoname", xmlResponse ).map(function() {
				return {
					value: $j( "library_" + autocomp_lang, this ).text(),
					link: $j( "link_" + autocomp_lang, this ).text()
				};
			}).get();
			
			$j( "#library_search" ).autocomplete({
				source: data,
				minLength: 0,
				select: function( event, ui ) {
					window.location = ui.item.link;							
				}
			});
			
			$j( "#library_search2" ).autocomplete({
				source: data,
				minLength: 0,
				select: function( event, ui ) {
					window.location = ui.item.link;							
				}
			});			
		}
	});	
	
	/***************************************************************************************/
	// Express yourself
	// drops for read more and comments
	$j('.express_description_read_more').click(function(){
		express_read_more_id = this.id.replace('express_description_read_more','');
				
		$j('#express_description_full'+express_read_more_id).show();
		$j('#express_description_read_less'+express_read_more_id).show();
	
		$j('#express_description_part'+express_read_more_id).hide();
		$j('#express_description_read_more'+express_read_more_id).hide();		
	});
	
	$j('.express_description_read_less').click(function(){
		express_read_more_id = this.id.replace('express_description_read_less','');
				
		$j('#express_description_full'+express_read_more_id).hide();
		$j('#express_description_read_less'+express_read_more_id).hide();
	
		$j('#express_description_part'+express_read_more_id).show();
		$j('#express_description_read_more'+express_read_more_id).show();		
	});	
	
	$j('.express_toggle_comments').click(function(){
		$j('#add_comments_drop_down'+this.id).slideToggle();
	});
	
	/***************************************************************************************/
	
	//console.log(BrowserDetect.OS + ' ' + BrowserDetect.browser);
	// Linux Firefox
	if(autocomp_lang == 'cy' && BrowserDetect.OS == 'Linux' && BrowserDetect.browser == 'Firefox')
	{
		$j('#top_nav_left ul li a').css({
			fontSize : '11px'
		});
		
		$j('#social_top_nav_links').css({
			width : '421px'
		});
	}
	
	/***************************************************************************************/

	$j('#social_top_nav_links span').eq(3).attr('id','lang_switch');
	
	/*var h = $j('#top_nav').css('height');
	$j('#top_nav').css({
		height: h
	});*/
		
});

