$(document).ready(function() {
	$('li#meta-home a').html('<img src="/fileadmin/templates/Renz_standard/images/icon-home.png" alt="Home" />');
	$('select#languageselect').change(function () {
		var url = $(this).val();
		window.location.href = '/'+url;
	});

    if (jQuery.browser.msie) {
        select_init();
    }

	$('.toggle_container').hide();
	$('.trigger').click( function() {
		if ( $(this).hasClass('trigger_active') ) {
			$(this).next('.toggle_container').slideToggle('slow');
			$(this).removeClass('trigger_active');
		} else {
			$('.trigger_active').next('.toggle_container').slideToggle('slow');
			$('.trigger_active').removeClass('trigger_active');
			$(this).next('.toggle_container').slideToggle('slow');
			$(this).addClass('trigger_active');
		};
	return false;
	});
	
	$('table.downloads ul').each(function() {
	    var list = $('li',this);
	    list.sort(function(oA,oB) {
		var a = $(oA).text();
		a = a.toString().toLowerCase();	
		var b = $(oB).text();
		b = b.toString().toLowerCase();	
	        if (a > b) return 1;
	        return -1;
	    });
	    $(list).remove();
	    $(this).append(list);
	});
	
	$('table.downloads tbody').each(function() {
	    var list = $('tr:not(:has(th))',this);
	    list.sort(function(oA,oB) {
		var a = $('td:first',oA).text();
		a = a.toString().toLowerCase();	
		var b = $('td:first',oB).text();
		b = b.toString().toLowerCase();	
	        if (a > b) return 1;
	        return -1;
	    });
	    $(list).remove();
	    $(this).append(list);
	});
	
})
 
function select_init () {
    var selects = $('table select');
    for (var i = 0; i < selects.length; i++) {
        _resizeselect.init(selects[i]);
    }
}
 
 
var _resizeselect = {
    obj : new Array(),
    init : function (el) {
        this.obj[el] = new resizeselect (el);
    }
}
 
function resizeselect (el) {
    this.el = el;
    this.p = el.parentNode;
    this.ht = el.parentNode.offsetHeight;
    var obj = this;
    this.set = false;
    el.onmousedown = function () {
        obj.set_select("mousedown");
    }
    el.onblur = function () {
        obj.reset_select("blur");
    }
/*
    el.onchange = function () {
        obj.reset_select("change");
    }
*/
    jQuery(el).bind('change',function(){
      obj.reset_select("change");
    });
}
 
resizeselect.prototype.set_select = function (str) {
 
    if (this.set) {
        this.set = false;
        return;
    }
 
    this.el.style.width = "auto";
    this.el.style.position = "absolute";
    
    this.p.style.zIndex = 100;
    this.set = true;
    this.el.focus();
}
 
resizeselect.prototype.reset_select = function (str) {
    this.el.style.width = "";
    this.el.style.position = "";
    
    this.p.style.zIndex = 1;
    this.set = false;
    window.focus();
}

