/* DOCUMENT READY */

$(document).ready(function(){
	imagePreview();
	tooltip();
	/*$('.editor').wysiwyg(
			{
				controls : {
				separator01 : { visible : true },
				separator00 : { visible : true },
				insertOrderedList : { visible : true },
				insertUnorderedList : { visible : true },
				justifyLeft: { visible : true },
				justifyCenter: { visible : true },
				justifyRight: { visible : true },
				justifyFull: { visible : true },
				underline: { visible : true }
			}	}	
	);*/

	$(".datepicker").mask("99.99.9999");
	$(".saat").mask("99:99");
	$(".tarih").datepicker($.extend({}, 
			$.datepicker.regional["ar"], { 
				yearRange: "-80:+0", 
    			showStatus: true, 
    			showOn: "both", 
   				buttonImage: "images/calendar.png", 
   				buttonImageOnly: true 
		}));
	$(".secret").hide();
	$('.passer').each(function() {
		
		$(this).bind (
			"click",
			function(){
				$(this).next().show();
			}
		);
	  
	});
	
	$('#dt_example').dataTable();
	$('.validate').validate();
	
});

$.extend($.validator.messages, {
required: "Lütfen ad ve soyadınızı giriniz.",
email: "Lütfen geçerli bir e-posta adresi giriniz.",
equalTo: "Şifreleriniz eşleşmiyor.",
number: "Bu alan sadece sayılardan olusabilir."
});

tinyMCE.init({

	mode : "textareas",
	theme : "advanced",
	theme_advanced_buttons1 : "bold,italic,underline,link,unlink",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : "",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom"
	});
/* TOOLTIP FUNCTION */

this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

/* IMAGE PREVIEW FUNCTION */
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

/* ENABLE/DISABLE CALENDER FIELD */
function toggleCalendar()
{
	if ($('#hmn').is(':checked')) {
		$('.tarih').attr("disabled", true);
		$('#ys').attr("disabled", true);  
	}
	else{
		$('.tarih').removeAttr("disabled");
		$('#ys').removeAttr("disabled");  
	}
}
