$(document).ready(function() {

	/**
	 * This code is related to selecting comments for startpage widget
	 */
	$('.enet_comments_ext .select_comment')
		.parent()
			.find('button').css('visibility', 'hidden')
			.end()
			.end()
		.click(function() {
			$(this).parent().submit();
	});

	/**
	 * styling of <ol> with big numbers needs inner element in each li:
	 */
	$(".liste-ziffer-gross li").each(function(i) {
		var alt = jQuery(this).text();
		$(this).html('<p>'+alt+'</p>');
	});


	/**
	 * avoid scrollbars overlaying tables in widgets when table height causes scrollbars
	 */
	var numberOfWidgetTableRowsInWidgetTableBody = $('.widgetContent table tbody').children().size();
	if ( numberOfWidgetTableRowsInWidgetTableBody > 4 ) {
		$(".widgetContent table").each(function(i) {
			$(this).css("width","308px");
		});
	}
	/* undo this for wide widget: */
	$(".widget-wide table").removeAttr("style");


	/**
	 * avoid problems with paddings if two std-ce-innerwrap2 are nested in each other
	 */
	$(".std-ce-innerwrap2").each(function(i) {
		$(this).has(".std-ce-innerwrap2").removeClass("std-ce-innerwrap2");
	});


	/**
	 * init enet tooltip matrix
	 **/
	initEnetTooltips();



	$.extend({
		getUrlVars: function(){
			var vars = [], hash;
			var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
			for(var i = 0; i < hashes.length; i++) {
				hash = hashes[i].split('=');
				vars.push(hash[0]);
				vars[hash[0]] = hash[1];
			}
			return vars;
		},
		getUrlVar: function(name){
			return $.getUrlVars()[name];
		}
	});





});


function initEnetTooltips(){
	// questionmark hint in forms
	$(".tooltip-hint").tooltip({
		extraClass: "tooltip-hint-box",
		showURL: false,
		top: 5,
		left: 5,
	});

	// descriptiontext for e.g. edit icons
	$(".tooltip-doit").tooltip({
		extraClass: "tooltip-doit-box",
		showURL: false,
		top: 5,
		left: 5,
	});
}

