
function b(elem){
//$(elem).css("width",$(window).width()); 
$(elem).css("height",$(document).height()); 	
var x = parseInt($(window).width()); var L = (x - $(elem).width())/2; $(elem).css( "left", L + "px" );		
}

(function($){
 /* defval */
 $.fn.defval = function(text) {
	
	var obj =  $(this[0]);	
	var val = obj.attr('value');
	
	if(val==""){ $(this).attr('value',text); }
	
	obj.focus(function(){ if($(this).attr('value')=="" || $(this).attr('value') == text ){ $(this).attr('value',''); }  }).blur(function(){ if($(this).attr('value')==""){ $(this).attr('value',text); }  });
	
	return this; 
 };
 
  $.fn.defval2 = function(text) {
	
	var obj =  $(this[0]);	
	var val = obj.html();
	
	if(val==""){ $(this).html(text); }
	
	obj.focus(function(){ if($(this).html()=="" || $(this).html() == text ){ $(this).html(""); }  }).blur(function(){ if($(this).html()==""){ $(this).html(text); }  });
	
	return this; 
 };
})(jQuery);	



function checkEmail(email){ var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i 
return filter.test(email); 
}
function message_post(){
	$(".hata").css("display","none"); $(".tamamlandi").css("display","none");	
	var hata = 0 ; var ad = $("#ad").val(); var eposta = $("#eposta").val(); var mesaj = $("#mesaj").val(); 		
	if( eposta == "" || !checkEmail(eposta) ){hata = 1; alert("eposta"); }	
	var str = $("div.ILR *").serialize(); //"IS=1&ad="+ad+"&eposta="+eposta+"&mesaj="+mesaj;
	if(hata == 0){ $.ajax({type:'POST',url:'ajax.asp',data:str,cache:false,timeout:5000,error:function(e){  $(".hata").css("display","block"); alert("hata"); },success:function(d){ if(d=="1"){ $(".tamamlandi").css("display","block"); $("#ad").val("Adım Soyadım"); $("#eposta").val("Eposta Adresim"); $("#mesaj").val("Mesajım"); }else{  $(".hata").css("display","block"); alert(d); } }}); }else{ $(".hata").css("display","block"); }
}



function scrollTop() {
	  return document.body.scrollTop || document.documentElement.scrollTop;
}

function libackpos(x) {	
	var w,l;
	if(x == 0 || x == undefined ){ w = 73; l = 15; }
	if(x == 1 ){ w = 67; l = 118; }
	if(x == 2 ){ w = 60; l = 200; }
	if(x == 3 ){ w = 79; l = 275; }
	if(x == 4 ){ w = 73; l = 384; }
	if(x == 5 ){ w = 68; l = 487; }
	if(x == 6 ){ w = 60; l = 582; }
	
	$("li.homeLava").css({left:l-15,width:w});
	
	$("li.backLava").dequeue().stop().animate({left:l,width:w},300);
	
	//$("#monitor").html(x + " " + w + " " + l);
}

$(document).ready(function () {
    $("body").queryLoader2({
        barColor: "#222222",
        backgroundColor: "#fff",
        percentage: true
    });
	
	$('html, body').animate({ scrollTop:'0'},500);
	
	var sect1Height = $("#anasayfa").height();
	var sect2Height = $("#projeler").height()+sect1Height;
	var sect3Height = $("#arti").height()+sect2Height;
	var sect4Height = $("#portfolyo").height()+sect3Height;
	var sect5Height = $("#markalar").height()+sect4Height;
	var sect6Height = $("#haberler").height()+sect5Height;
	var sect7Height = $("#iletisim").height()+sect6Height;
	var sectAtual = 1;




	$(".tmenu").lavaLamp({ fx: "backout", speed: 1100,returnHome:true });
	
	$("#ad").defval("Adım Soyadım");
	$("#eposta").defval("Eposta Adresim");
	$("#mesaj").defval2("Mesajım");
	
	$("#aaop").click(function(){ $("#aslogan").slideToggle(); $(this).css("display","none"); $("#aaopcl").css("display","block"); 
	//$('html, body').animate({ scrollTop:'120'},500); 
	});
	$("#aacl").click(function(){ $("#aslogan").slideToggle(); $("#aaop").css("display","block"); $("#aaopcl").css("display","none"); 
	//$('html, body').animate({ scrollTop:'0'},500); 
	});
	
	$('a[rel*=facebox]').facebox(); 
	
	
	
	$("#solmenu li").click(function(){
		
		$("#solmenu li").removeClass('current'); $(this).addClass('current');
		var index = $(this).index();
		//alert(index);
		$("#portfolyo_list li").removeClass('current'); $("#portfolyo_list li").eq(index).addClass('current');
		
		$('html, body').animate({ scrollTop:$("#portfolyo").offset().top},500);
	
	});
	
	    $(window).scroll(function() { 
		    var x = 0;
			if(scrollTop() < ( sect1Height )) { x = 0; }			
			if(scrollTop() > ( sect1Height )) { x = 1; }			
			if(scrollTop() > ( sect2Height )) { x = 2; }			
			if(scrollTop() > ( sect3Height )) { x = 3; }			
			if(scrollTop() > ( sect4Height )) { x = 4; }
			if(scrollTop() > ( sect5Height )) { x = 5; }						
			if(scrollTop() > ( sect6Height )) { x = 6; }	
				
			//libackpos(x);
			
			//$("nav ul li").removeClass("current").eq(x).addClass("current");	

	      
			var ofsetTop = $("#portfolyo").offset().top;
			var ofsetBottom = (ofsetTop + $("#portfolyo").height());
            var topPadding = 0;
			var scrolTop = $(window).scrollTop() + 201;
				
                if ( ($(window).scrollTop() > ofsetTop+201) && ($(window).scrollTop() < ofsetBottom-$("#solmenu").height())  ) {
                    $("#solmenu").stop().animate({
                        marginTop: ($(window).scrollTop()-201) - (ofsetTop + topPadding)
                    });
                }else if ( $(window).scrollTop() > ofsetBottom-$("#solmenu").height() ){

                }else {
                    $("#solmenu").stop().animate({
                        marginTop: 0
                    });
                };
            });
	
});
