$(function() {
				
		//png fix
		$(document).pngFix(); 

		$("#lead").addClass("noTMCE");
			
		//form text swap
		swapValues = [];
	    $(".swap_value").each(function(i){
	        swapValues[i] = $(this).val();
	        $(this).focus(function(){
	            if ($(this).val() == swapValues[i]) {
	                $(this).val("");
	            }
	        }).blur(function(){
	            if ($.trim($(this).val()) == "") {
	                $(this).val(swapValues[i]);
	            }
	        });
	    });
	    
	    
	    // Expand Panel
		$("#open").click(function(){
			$("div#panel").slideDown("slow");			
			return false;	
		});	
		
		// Collapse Panel
		$("#close").click(function(){
			$("div#panel").slideUp("slow");
			return false;	
		});		
		
		// Switch buttons from "Log In | Register" to "Close Panel" on click
		$("#toggle a").click(function () {
			$("#toggle a").toggle();
			return false;
		});	
	    
	    
	    //changepassword
	    $("#changepassword").click(function(){

			if( $('#changepassword').attr('checked') ){	    					
				$("#s_password, #s_passwordagain").css('display','');
			}else{									   		
				$("#s_password, #s_passwordagain").css('display','none');
			}						   				    	
	    	
	  	});
	  	
	  	//news slider
	  	$("#slider").easySlider({

	            controlsShow:   false,
	            controlsBefore: '',
	            controlsAfter:  '',
	            controlsFade:   true,
	            insertAfter:    true,
	            firstShow:      false,
	            lastShow:       false,
	            vertical:       false,
	            speed:          800,
	            ease:           'swing',
	            auto:           true,
	            pause:          2000,
	            continuous:     true,
	            prevNext:       true,
	            numeric:        false,
	            numericId:      'controls'
		});
		
		
		//pic delete
		$('a#delmupic1').click(function() {

				var data = 'del=1';
				
				$.ajax({
					url: 'include/ajax/ajaxProcessor.php',
					type: 'GET',
					data: data,
					
					success: function(result){
												
						$('#delmupic1').parent().remove();
						
					}
				
				});				
				
				
				return false;
		});
		
		$('a#delmupic2').click(function() {

				var data = 'del=2';
				
				$.ajax({
					url: 'include/ajax/ajaxProcessor.php',
					type: 'GET',
					data: data,
					
					success: function(result){
											
						$('#delmupic2').parent().remove();
						
						removePicFromTinyMCE(result);

					}
				
				});				
				
				
				return false;
		}); 
		
		$('a#delmupic3').click(function() {

				var data = 'del=3';
				
				$.ajax({
					url: 'include/ajax/ajaxProcessor.php',
					type: 'GET',
					data: data,
					
					success: function(result){						
						
						$('#delmupic3').parent().remove();
						
						removePicFromTinyMCE(result);

					}
				
				});				
				
				
				return false;
		});  
		
		
		function removePicFromTinyMCE(picName){
		
						tmce_content = tinyMCE.get('szoveg').getContent();
						/*alert(tmce_content);*/
						
						/*result = "button_search.png"*/
						/*result = "7even_logo.png"*/
						
						csere = new RegExp( '<img src="([a-zA-Z0-9._/-]*)/'+picName+'"([^>]*)/>' , "ig");
												
						tmce_content = tmce_content.replace(csere, '');												
						
						/*alert(tmce_content);*/								
						
						tinyMCE.get('szoveg').setContent(tmce_content);	
		
		}
		
		
		function limitChars(textid, limit, infodiv)
		{
			var text = $('#'+textid).val();	
			var textlength = text.length;
			if(textlength > limit)
			{
				$('#' + infodiv).html('A bevezető tartalma nem lehet több mint '+limit+' karakter!');
				$('#'+textid).val(text.substr(0,limit));
				return false;
			}
			else
			{
				$('#' + infodiv).html( (limit - textlength) +' karakter maradt.');
				return true;
			}
		}

		$('#lead').keyup(function(){
			limitChars('lead', 200, 'charlimitinfo');
		})


});
