jQuery.noConflict();
jQuery(document).ready(function($){
	var isIE = ($.browser.msie && parseInt($.browser.version.substr(0,1)) < 7);

	$('#pane2').jScrollPane({ showArrows:true, scrollbarWidth:21 });

	function tabSlide(item, timer) {
		var stop = false;
		var delay = 15000
		if($(item).find('li.act').hasClass('locked')) {
			$(item).find('li.act').removeClass('locked');
			stop = true;
			timer = delay;
		} else {
			timer = 5000;
			stop = false;
		}
		if(!stop) {
			if($(item).find('li.act').next()[0]) {
				$(item).find('li.act').next().click();
			} else {
				$(item).find('li:first').click();
			}
		}
		setTimeout(function () {
			tabSlide(item);
		}, timer);
	};

	$.fn.tabs = function(options) {
		var pClass = '';
		$this = $(this);
		$this.find('li').click(function() {
			$(this).parent().find('li').removeClass('act');
			pClass = $(this).attr('class').split(' ');
			if(options && options.effect) {
				$(this).parent().parent().find('>div').fadeOut();
				$('#'+pClass[0]).fadeIn('slow');
			} else {
				$(this).parent().parent().find('>div').css('display','none');
				$('#'+pClass[0]).attr('style','');
			}
			$(this).addClass('act');
		});
		$this.find('li').mousedown(function() {
			$(this).addClass('locked');
		});
		if(options && options.auto) {
			setTimeout(function () {
				tabSlide($this, 5000);
			}, 5000);
		}
		return false;
	};

	$('.tabs').tabs();
	$('.switcher').tabs({'effect': '1', 'auto': 1});

	$.fn.showPost = function() {
		//$(this).parent().toggleClass('collapsed').toggleClass('expanded');
		$(this).click(function() {
			$(this).parent().toggleClass('collapsed').toggleClass('expanded');
		});
	}
	$('.item-link').showPost();
	
	$('.i-text, .i-textarea').focus(function(){
		if($(this).attr("title") == $(this).val()) $(this).val('');
	}).blur(function(){
		if($(this).val() == '') $(this).val($(this).attr("title"));
	});
	
	// used for aoe_vorsorgerechner
	$('.swap_value').hint();
	$('#notify_1').click(function(){
		$('#label-user-email').show();
	});
	$('#notify_0').click(function(){
		$('#label-user-email').hide();
	});	
	
	
	$('.ivor-button:not(button)').each(function(){
		var button = $(this);
		
		if (button.attr('class') != 'ivor-button') {
			var customClass = ' ' + button.attr('class');
		} else {
			var customClass = '';
		}
		//var strMoreButton = '<div class="more-button' + customClass + '" title="' + button.attr('title') + '"><div class="more-button-content"><span>' + button.val() + '</span></div><em class="more-button-left"></em><em class="more-button-right"></em></div>';
		var strMoreButton = '<button class="f-right' + customClass + '" title="' + button.attr('title') + '"><span class="bu submit"><span>' + button.val() + '</span></span></button>';

		button.after(strMoreButton).css({'display': 'none'});
		button.next().click(function(){
			//$(strMoreButton).click();
			//button.click();
			button.parents('form').submit();
		});

		
	});
});


jQuery.fn.hint = function (blurClass) {
	if (!blurClass) { 
		blurClass = 'blur';
	}

	return this.each(function () {
		// get jQuery version of 'this'
		var $input = jQuery(this),

		// capture the rest of the variable to allow for reuse
		title = $input.attr('title'),
		$form = jQuery(this.form),
		$win = jQuery(window);

		function remove() {
			if ($input.val() === title && $input.hasClass(blurClass)) {
				$input.val('').removeClass(blurClass);
			}
		}

		function populate() {
			// only apply logic if the element has the attribute
			if (title) { 
				// on blur, set value to title attr if text is blank
				$input.blur(function () {
					if (this.value === '') {
						$input.val(title).addClass(blurClass);
					}
				}).focus(remove).blur(); // now change all inputs to title

				// clear the pre-defined text when form is submitted
				$form.bind('pre-submit', remove);
				$form.submit(function () {
					remove();
				});
				$win.unload(remove); // handles Firefox's autocomplete
			}
		}

		populate();

		$form.bind('re-populate', populate);
	});
};

