$(document).ready(function() {
	
$(".divtel input[type=text]").click(function(){
		$(this).val("");
	});
$(".divtel input[name=telcode]").click(function(){
	$(this).val("0");
});

$(".divtel input[name=telcode]").keyup(function(){
	if (document.getElementById("codetel").value.length==4) $(".divtel input[name=tel]").focus();
});
			
			//superfish menu init
			jQuery('ul.sf-menu').superfish();
			if ($("#s4").length) {
					$(function() {
					// run the code in the markup!
					$('#s4')
						.cycle({ 
						fx:     'scrollHorz', 
						speed:  1000, 
						timeout: 5000, 
						next:   '#next2', 
						prev:   '#prev2' 
					});
					});
				};
				
function ajaxContact(theForm) {
		var $ = jQuery;
	
        $('#loader').fadeIn();

        var formData = $(theForm).serialize(),
			note = $('#Note');
	
        $.ajax({
            type: "POST",
            url: "send.php",
            data: formData,
            success: function(response) {
				if ( note.height() ) {			
					note.fadeIn('fast', function() { $(this).hide(); });
				} else {
					note.hide();
				}

				$('#LoadingGraphic').fadeOut('fast', function() {
					//$(this).remove();
					if (response === 'success') {
						$('.field').animate({opacity: 0},'fast');
						$('.button_contact').animate({opacity: 0},'fast');
					}

					// Message Sent? Show the 'Thank You' message and hide the form
					result = '';
					c = '';
					if (response === 'success') { 
						result = 'Your message has been sent. Thank you!';
						c = 'success';
					}

					note.removeClass('success').removeClass('error').text('');
					var i = setInterval(function() {
						if ( !note.is(':visible') ) {
							note.html(result).addClass(c).slideDown('fast');
							clearInterval(i);
						}
					}, 40);    
				});
            }
        });

        return false;
    }
	if ($("#contactform").length) {
	jQuery("#contactform").validate({
			submitHandler: function(form) {				
				ajaxContact(form);
				return false;
			},
			 messages: {
    		 formname: "Please specify your name.",
			 formcomments: "Please enter your message.",
    		 formemail: {
      			 required: "We need your email address to contact you.",
      			 email: "Your email address must be in the format of name@domain.com"
    		 }
  		 }
		});
		 }
		 
		 
		 if ($(".overflow").length) {
			$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
			};	
		 
			$(".overflow").append("<span></span>")
			$(".overflow	").hover(function(){
						$(this).find("img").stop().animate({opacity:0.5}, "normal")
					}, function(){
						$(this).find("img").stop().animate({opacity:1}, "normal")
					});
					
		});	

function isNum(event) {
	var keyCode = event.which ? event.which : event.keyCode;
	if ( keyCode == 8 ) return true;
	return keyCode >= '0'.charCodeAt() && keyCode <= '9'.charCodeAt()
}

function istekgonder() {
	var obj = document.arayal;
	if (obj.name.value=="") { 
		alert("Lütfen isim hanesini boş bırakmayın.");
	} else if (obj.telcode.value=="0" || obj.telcode.value.length < 4) { 
		alert("Lütfen alan kodunu eksiksiz girin.");
	} else if (obj.tel.value=="" || obj.tel.value.length < 7) { 
		alert("Lütfen telefon numaranızı eksiksiz girin.");
	} else {
		$.get("/telefonual.php", { name: $(".divtel input[name=name]").val(), tel: $(".divtel input[name=telcode]").val() + " " + $(".divtel input[name=tel]").val()},
				   function(data){
				    if(data == 1) { 
					    $(".divtel form").slideUp("slow");
					    $(".divtel").append("<span class=\"siziarayal\">Bilgileriniz alınmıştır.<br/> En kısa sürede sizinle irtibata geçilecektir.</span>");
				    }
			 });
	} }

