jQuery.noConflict();

jQuery(document).ready(function() {
	jQuery('a.iframemodal').click(function() {
        	var myhref = jQuery(this).attr('href');
        	jQuery.nyroModalManual({
                	type: 'iframe',
                	url: myhref,
                	minWidth: 900,
                	minHeight: 600
        	});
        	return false;
	});

	jQuery('input#suchbegriff').focus(function() {
		jQuery(this).css({
			color: '#000',
			textAlign: 'left'
			
		}).val('');
	});


	jQuery('a.chatbox').click(function() {
		if (jQuery(this).hasClass('livedinxoff')) {
			jQuery(this).removeClass('livedinxoff').addClass('livedinxon').text('live-dinx ausschalten');
			top.takemeonline();
		} else {
			top.takemeoffline();
			jQuery(this).removeClass('livedinxon').addClass('livedinxoff').text('live-dinx anschalten');
		}
		return false;
	});

	jQuery('a.invitelink').live('click',function() {

		var myid = jQuery(this).attr('id');
		myid = myid.substr(2,myid.length);
		var title = jQuery(this).attr('title');
		var chatid = top.inviteMe(myid);
		top.addChat(chatid,title);
		
		return false;
	});
	
	jQuery('a.ajax-submit').click(function() {
		jQuery(this).parents('form').get(0).submit();
		return false;
	});
	
	jQuery('input.jqdate').datepicker({
		mandatory: true,
		firstDay: 1,
		defaultDate: +0,
		dateFormat: 'dd.mm.yy'
	});
	
	
	jQuery('div.loginbox input.submitbutton').hover (
		function () {	jQuery(this).css('background','transparent url(/bilder/bg-button-loginbox-hover.png) no-repeat scroll 0 0'); }
		,function () {	jQuery(this).css('background','transparent url(/bilder/bg-button-loginbox.png) no-repeat scroll 0 0'); }
	);
	
	
	jQuery('select.jq-subsel').change(function() {
		var val = jQuery(this).val();
		jQuery('select.jq-subme').hide().attr('name','dummy');
		jQuery('select#'+val).show().attr('name','gemeinde');
	});  
	
	//jq-condinput
	jQuery('select.jq-condinput').change(function() {

		var val = jQuery(this).val();
		if (jQuery('option[value="'+val+'"]',this).attr('disabled')) {
			this.selectedIndex--;
		}
		jQuery('input.jq-condinput').hide().val('');
		jQuery('input.jq-condinput[rel="'+val+'"]').show();
	});
	
	jQuery('select.jq-condinput > option[disabled]').css('color','#aaa');
	jQuery('a.imgsel').click(function() { 
		var self = this;
		var rel = jQuery(self).attr('rel');
		var id = jQuery(self).attr('id');
		jQuery('input[name="'+rel+'"]').val(id);
		jQuery('a.imgsel').removeClass('imgselected');
		jQuery(self).addClass('imgselected');
		return false;
	});
	
	jQuery('a.ajax-exec-hide').click(function() { 
		var self = this;
		var href = jQuery(self).attr('href');
		//console.log(href);
		var doit = true;
		if (jQuery(this).hasClass('confirm')) {
			doit = confirm(jQuery(this).attr('confirm'));
		}
		if (doit) {
			jQuery.get(href,function(data) {
				var rel = jQuery(self).attr('rel');
				jQuery('#'+rel).fadeOut('slow');	
			});
		}
		return false;
	});
	
	jQuery('a.confirm-exec').click(function() {
		var doit = confirm(jQuery(this).attr('confirm'));
		return(doit);
	});
	
	jQuery('a.calmodal').click(function() {
		jQuery.nyroModalManual({
			type: 'iframe',
			url: jQuery(this).attr('href'),
			minWidth: 900,
			minHeight: 600
		});
		return false;
	});
	
	jQuery('a.modalsimple').nyroModal();
	jQuery('a.modal').nyroModal({
		endRemove: function () {
			location.href=location.href;
		}
	});

	jQuery('a.post-modal').click(function(e){
		e.preventDefault();
		jQuery.ajax({
			url: this.href,
			async: true,
			cache: false,
			data: jQuery(document.forms[0]).serialize(),
			type: 'post',
			success: function (msg) {
				jQuery.nyroModalManual({
					content: msg
				});
			}
		});
		return false;
	});

	preloadImg('/extern/img/ajaxLoader.gif');	
	preloadImg('/extern/img/prev.gif');
	preloadImg('/extern/img/next.gif');
	
	jQuery('div.imglist').sortable({
		axis: 'y',
		stop: function () {
			var myorder = [];
			jQuery('div.imglist dl').each(function() { 
				myorder.push(this.id);
			});
			myorder = myorder.toString();
			jQuery.post('/aktion/imgorder',{order: myorder},function() {
				// thanks
			});
		}
	});
	
	jQuery('div.dlsortable').sortable({
		axis: 'y',
		stop: function () {
			var myorder = [];
			var url = jQuery(this).attr('rel');
			jQuery('div.dlsortable dl').each(function() { 
				myorder.push(this.id);
			});
			myorder = myorder.toString();
			jQuery.post(url,{order: myorder},function() {
				// thanks
			});
		}					
	});
	jQuery('dl.imglist,div.dlsortable dl').hover(function() { jQuery(this).css('cursor','row-resize'); }, function () {jQuery(this).css('cursor','auto'); });

	jQuery('select.sortlink').change(function() {
		var href = jQuery(this).parent('form').attr('action');
		var val = jQuery(this).val();
		location.href = href+'/'+val;
	});
	
	jQuery('.ajax-face a').click(function() {
		var rel = jQuery(this).attr('rel');
		jQuery('#profil-gesicht').attr('class','gesicht-'+rel);
		jQuery('input[name="av_gesicht"]').val(rel);
		return false;
	});
	jQuery('.ajax-haare a').click(function() {
		var rel = jQuery(this).attr('rel');
		var farbe = jQuery('input[name="av_haarfarbe"]').val();
		jQuery('#profil-haare').attr('class','haare-'+rel+'-'+farbe);
		jQuery('input[name="av_haare"]').val(rel);
		return false;
	});
	jQuery('.ajax-haarfarbe span').click(function() {
		var rel = jQuery(this).attr('rel');
		var haare = jQuery('input[name="av_haare"]').val();
		jQuery('#profil-haare').attr('class','haare-'+haare+'-'+rel);
		jQuery('input[name="av_haarfarbe"]').val(rel);
		return false;
	});
	
	jQuery('.ajax-gewand a').click(function() {
		var rel = jQuery(this).attr('rel');
		var robe = jQuery('input[name="av_robe"]').val();
		jQuery('#profil-gewand').attr('class','gewand-'+rel+'-'+robe);
		jQuery('input[name="av_gewand"]').val(rel);
		return false;
	});
	jQuery('.ajax-robe span').click(function() {
		var rel = jQuery(this).attr('rel');
		var gewand = jQuery('input[name="av_gewand"]').val();
		jQuery('#profil-gewand').attr('class','gewand-'+gewand+'-'+rel);
		jQuery('input[name="av_robe"]').val(rel);
		return false;
	});
	
	jQuery('div#whoisonline ul li#online-left a').click(function() {
		var pos = parseInt(jQuery('li#online-middle div').css('margin-left'));
		var width = parseInt(jQuery('li#online-middle div').css('width'));
		
		if (pos < 0) {	
			var moveby = (pos+200);
			jQuery('li#online-middle div').animate({marginLeft: moveby+'px'},1000,'swing');
		}
		//console.log([pos,width,width+pos,widthli]);
		return false;
	});
	
	jQuery('li#online-right a').click(function() {
		//var moveby = -100;
		var pos = parseInt(jQuery('li#online-middle div').css('margin-left'));
		var width = parseInt(jQuery('li#online-middle div').css('width'));
		var widthli = parseInt(jQuery('li#online-middle').css('width'));
		
		if (width+pos > widthli) {
		
	
			var moveby = (pos-200);

			jQuery('li#online-middle div').animate({marginLeft: moveby+'px'},1000,'swing');
		}
		//console.log([pos,width,width+pos,widthli]);
		return false;
	});
	
	jQuery('input[name=username]').focus();
	
});



function preloadImg(image) {
 var img = new Image();
img.src = image;
}

function decode (str)
{
	return str.replace(/[a-zA-Z]/g,function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});
}

function sendMailTo(user,host)
{
	var loc = 'mai' + 'lto:' + decode(user) + '@' + decode(host);
	window.location.replace(loc);
}

