var current_star = 0;
$(document).ready(function () {
	$('#i_country').change(function () {
		$('#i_state').load('ajax/getState.php?id='+this.value);

		$(".class_null").addClass('inactive');

		$(".class_de").removeClass('active');
		$(".class_ch").removeClass('active');
		$(".class_at").removeClass('active');
		$(".class_de").addClass('inactive');
		$(".class_ch").addClass('inactive');
		$(".class_at").addClass('inactive');		

		//Auswahl aufheben
		$('#i_vorwahl').removeAttr('selected');

		//AT
		if (this.value == 1) {
			$(".class_at").removeClass('inactive');
			$(".class_at").addClass('active');
			$("#i_vorwahl option[value='43']").attr('selected',true);
		}
		
		//DE
		if (this.value == 2) {
			$(".class_de").removeClass('inactive');
			$(".class_de").addClass('active');
			$("#i_vorwahl option[value='49']").attr('selected',true);			
		}
		
		//CH
		if (this.value == 3) {
			$(".class_ch").removeClass('inactive');
			$(".class_ch").addClass('active');
			$("#i_vorwahl option[value='41']").attr('selected',true);			
		}		
		
		return false;
	});

	$('a.thickbox').lightBox({
		fixedNavigation:true,
		imageBtnPrev: '',
		imageBtnNext: '',
		containerResizeSpeed: 350,
		txtImage: '',
		txtOf: ''		
	});

	
	$("input.textreg").each(function (i) {
		$(this).focus(function () {
			$(this).css("color","#000");
			return false;
		}); 		
	});	
	
	$('.bezahlart').click(function () {
			
		$('.bezahlart1').hide();
		$('.bezahlart2').hide();
		$('.bezahlart3').hide();		
									  
		var type = this.value;
		switch (type) {
			case '1': $('.bezahlart1').show(); break;
			case '2': $('.bezahlart2').show(); break;
			case '3': $('.bezahlart3').show(); break;			
		}
	});	
	
	$('#lnk_frauen').click(function() {
		$('#frauen').show();
		$('#maenner').hide();		
	});
	
	$('#lnk_maenner').click(function() {
		$('#frauen').hide();
		$('#maenner').show();		
	});
	
	$('.aktivierungsart').click(function () {
			
		$('#frm_telefon').hide();
		$('#frm_netdebit').hide();
		$('#frm_ueberweisung').hide();
		$('#frm_paypal').hide();
									  
		var type = this.value;
		switch (type) {
			case '1': $('#frm_telefon').show(); break;
			case '2': $('#frm_netdebit').show(); break;
			case '3': $('#frm_ueberweisung').show(); break;
			case '4': $('#frm_paypal').show(); break;
		}
	});		
	
	$('#fahne').mouseover(function () {
		left = $('#fahne').css('left');
		if (left == '-285px') {
			  $('#fahne').animate({
				left: '+=265'
			  }, 1000, function() {
				// Animation complete.
			  });
		}
	});	
	
	$('#fahne').mouseleave(function () {
		left = $('#fahne').css('left');
		if (left == '-20px') {
			  $('#fahne').animate({
				left: '-=265'
			  }, 1000, function() {
				// Animation complete.
			  });
		}
	});	
	
	$('#anzeige_bild').click(function () {
		var value = $('#anzeige_bild').val();
		if (value == 1) {
			$('#anzeige_text').attr("checked","");
			$('#block_text').hide();
			$('#block_foto').show();
			$('#anzahl').attr("value","250");
				
			length = 200 - $('#letters').html();
			letters = 250 - length;
			$('#letters').html(letters);
		}
	});
	
	$('#anzeige_text').click(function () {
		var value = $('#anzeige_text').val();
		if (value == 1) {
			$('#anzeige_bild').attr("checked","");
			$('#block_foto').hide();
			$('#block_text').show();
			$('#anzahl').attr("value","200");
			
			length = 250 - $('#letters').html();
			letters = 200 - length;
			$('#letters').html(letters);
		}
	});
	
	$('.star').mouseover(function () {
		var id = $(this).attr("id");
		var id = id.replace("star","");
		for (i=1; i<= id; i++) {
			$("#star" + i).attr("src","images/star_active.png");
		}
	});
	
	$('.star').mouseout(function () {
	    current_star = $('#star-rating').attr("value");
		for (i=1; i<= 5; i++) {
			$("#star" + i).attr("src","images/star_inactive.png");
		}	  
		for (i=1; i<= current_star; i++) {
			$("#star" + i).attr("src","images/star_active.png");
		}
	});
	
	$('.star').click(function () {
		var id = $(this).attr("id");
		var id = id.replace("star","");								  
	    current_star = $('#star-rating').attr("value",id);
	});	
	
	$('.bewertungen_ansehen').click(function () {
		$(".bewertungen").slideToggle();
		var text = $(".bewertungen_ansehen a").html();
		if (text == "aufklappen") {
			$(".bewertungen_ansehen a").html("zuklappen");
		} else {
			$(".bewertungen_ansehen a").html("aufklappen");			
		}
	});
	
	$('#sort').change(function() {
		$('#sortform').submit();
	});
	
	$('#wSlider, #mSlider').anythingSlider({
		 startStopped        : false,
		 autoPlay : false,
	});
	
	$('#add_file').live('click',function () {
		var count = $('.fileupload').size() + 1;
		if (count < 16) {
			$("#filecontainer").append('<div id="filecontainer'+count+'"><input type="file" class="fileupload" name="file[' + count + ']"/><div id="taglist'+count+'" class="taglist"> </div><input type="text" class="textfeld-klein addtag" /></div>');
		} else {
			alert('Mehr Bilder können nicht hochgeladen werden.');
		}
	});
	
	if(typeof $('.ad-gallery').adGallery == 'function' ){
		$('.ad-gallery').adGallery({
		  width: 580, // Width of the image, set to false and it will read the CSS width
		  height: 400, // Height of the image, set to false and it will read the CSS height
		  thumb_opacity: 0.7, // Opacity that the thumbs fades to/from, (1 removes fade effect)
							  // Note that this effect combined with other effects might be resource intensive
							  // and make animations lag
		  start_at_index: 0, // Which image should be displayed at first? 0 is the first image
		  animate_first_image: false, // Should first image just be displayed, or animated in?
		  animation_speed: 400, // Which ever effect is used to switch images, how long should it take?
		  display_next_and_prev: true, // Can you navigate by clicking on the left/right on the image?
		  display_back_and_forward: true, // Are you allowed to scroll the thumb list?
		  scroll_jump: 0, // If 0, it jumps the width of the container
		});
	}
	
	$('.taglist a img').live('click', function() {
		$(this).parent().remove();
	});
	
	$('.addtag').live('keydown', function(e) {
	  if(e.keyCode == 13) {
		var file = $(this).parent().attr('id');
		file = file.replace('filecontainer','');
		
		var id = $("#taglist" + file + " a").last().attr('class');
		if (id == undefined)
		{ var all = 1; }
		else 
		{ id = id.replace('tag',''); var all = parseInt(id) + 1; }
		
		var html = '<a href="#" class="tag' + all + '">' + $(this).val() + '<img src="images/msg-loeschen.png" alt="" /><input type="hidden" value="' + $(this).val() + '" name="tag[' + file + '][' + all + ']" /></a>';
		$('#taglist' + file).append(html);
		$(this).val('');
		return false;
	  }  
	});
	
	if(typeof $('.pic_container img').tooltip == 'function' ){
		$('.pic_container img').tooltip({ showURL: false });
	}
	
	$('.tagid').live('click', function() {
		var tag_id = $(this).attr('id');
		
		$(this).remove();		
		
		tag_id = parseInt(tag_id.replace('tagid',''));
		
		//Tag löschen - Ajax
		$.ajax({
		   type: "POST",
		   url: "ajax/removeTag.php",
		   data: "tag_id=" + tag_id,
		   success: function(msg){
				
		   }
		 });
	});
	
	$('#sexyvotes_ul').anythingSlider({
		 startStopped   : false,
		 autoPlay 		: false,
		 buildNavigation :false,
		 width			: '454px'
	});
	
	$('.star_sexyvote').live('mouseenter', function () {
		var id= $(this).attr("id");
		var position = id.substr(4, 1);
		var picture_id = parseInt(id.substr(6, 5));
		
		current_star = $('#star-rating' + picture_id).attr("value");
		if (current_star != "X") {
		
			for (i=1; i<= position; i++) {
				$("#star" + i + "_" + picture_id).attr("src","images/star_active.png");
			}
		}
	});
	
	$('.star_sexyvote').live('mouseleave', function () {
						
		var id= $(this).attr("id");
		var position = id.substr(4, 1);
		var picture_id = parseInt(id.substr(6, 5));
						
		current_star = $('#star-rating' + picture_id).attr("value");
		if (current_star != "X") {
					
			current_star = $('#star-rating' + picture_id).attr("value");
			for (i=1; i<= 5; i++) {
				$("#star" + i + "_" + picture_id).attr("src","images/star_inactive.png");
			}	  
			for (i=1; i<= current_star; i++) {
				$("#star" + i + "_" + picture_id).attr("src","images/star_active.png");
			}
		}
	});
	
	$('.star_sexyvote').click(function () {
		var id= $(this).attr("id");
		var position = id.substr(4, 1);
		var picture_id = parseInt(id.substr(6, 5));							  
		
	    current_star = $('#star-rating' + picture_id).attr("value","X");
		
		//Bewertung speichern
		$.ajax({
			   type: "POST",
			   url: "ajax/votePicture.php",
			   data: "picture_id=" + picture_id + "&value=" + position,
			   success: function(msg){
				
					$.fallr('show', {
						content     : '<p>Deine Bewertung wurde gespeichert</p>',
						autoclose   : 700
					});	
				
			   }
		 });  

		
	});
	
	$('#sexyvotes_ul').anythingSlider({
		 startStopped   : false,
		 autoPlay 		: false,
		 buildNavigation :false,
		 width			: '454px'
	});
	
	$(".changePanel").click(function(){
		$('.userbox').removeClass('marked');									 
		$(this).parent().parent().parent().parent().parent().addClass('marked');
		var id = $(this).attr('id');
		id = parseInt(id.replace('picturelink',''));
		$('#sexyvotes_ul').anythingSlider(id);	  
	});
	
}); 


function open_party(target,w,h) {
	popup(target,w,h);
}

function toggleDiv(el)
{
	closeAll();
	$('#'+el).slideToggle("slow", function () {
			$('#onlineuser').jScrollPane({showArrows:true, scrollbarWidth:17});
	});

	
	
	var arrow = $("#pic-" + el).attr("src");
	if (arrow == "images/plus.png") {
		$("#pic-" + el).attr("src","images/minus.png");
	} else {
		$("#pic-" + el).attr("src","images/plus.png");		
	}	
}

function closeAll()
{
	$("#pic-deutschland").attr("src","images/plus.png");
	$('#deutschland').hide();
	$("#pic-oesterreich").attr("src","images/plus.png");
	$('#oesterreich').hide();	
	$("#pic-schweiz").attr("src","images/plus.png");
	$('#schweiz').hide();	
}

function toggleSub(el,country)
{	
	$("div." + country).each(function (i) {
		$(this).hide();
	});
	
	$("img." + country).each(function (i) {
		$(this).attr("src","images/plus.png");
	});	
	
	$('#'+el).slideToggle("slow", function () {
			$('#onlineuser').jScrollPane({showArrows:true, scrollbarWidth:17});
	});
	
	var arrow = $("#pic-" + el).attr("src");
	if (arrow == "images/plus.png") {
		$("#pic-" + el).attr("src","images/minus.png");
	} else {
		$("#pic-" + el).attr("src","images/plus.png");		
	}	
}

function deleteInserat(iid) {
	var el = "#div_"+ iid;
	$(el).hide("puff", {}, 1000, function() {
		
		$.get("ajax/inserate.php", { del: iid }, function(data){
		  $("#inserate").html(data);
		});			
		
	});
	
}

function deleteMessage(message_id,direction,own,start,outbox) {
	var el = "#message_"+ message_id;
	$(el).hide("puff", {}, 1000, function() {
		
		$.get("ajax/mailbox.php", { del: message_id, direction: direction, own: own, start: start, outbox: outbox }, function(data){
		  $("#inserate").html(data);
		});	
		
	});
	
}

function toggleDialog(el) {
	/*
	$('.bezahlart1').hide();
	$('.bezahlart2').hide();
	$('.bezahlart3').hide();	
	$('.bezahlart1').show();	
	*/
	
	$("#" + el).toggle();
}
function letters(el,maximum)
{
	var content = document.getElementById(el).value;
	var length = content.length;
	
	if (length > maximum) {
		//Lösche immer das letzte Zeichen, was er eingibt.
		content = content.substr(0,maximum);
		document.getElementById(el).value = content;
		document.getElementById("letters").innerHTML = "0"
	} else {
		var diff = maximum - length;
		document.getElementById("letters").innerHTML = diff;
	}
}

function popup(ziel,w,h) {
	if (w == 0) { w = 600; }
	if (w == 0) { h = 400; }
	h = h - 20; var x=0, y=0, parameter="";
	if (w < screen.availWidth || h < screen.availHeight) {
	x = (screen.availWidth - w - 12) / 2;
	y = (screen.availHeight - h - 104) / 2;
	if (window.opera) y = 0; // Opera positioniert unter den Symbolleisten
	if (x<0 || y<0) { x=0; y=0; }
	else parameter = "width=" + w + ",height=" + h + ",";
	}
	parameter += "left=" + x + ",top=" + y;
	parameter += ",menubar=yes,location=yes,toolbar=no,status=no";
	parameter += ",resizable=yes,scrollbars=yes";
	var Fenster = window.open(ziel,"PopUp",parameter);
	if (Fenster) Fenster.focus();
	return !Fenster;
}

function toggleStandort(el) {
	if ($("#" + el).css("visibility") == "hidden") {
		$("#" + el).css("visibility","visible");
	} else {
		$("#" + el).css("visibility","hidden");		
	}
}

function setIps(val) {
	$.cookie("ips", val);
	window.location.reload();
}
