jQuery(document).ready(function($){ 

	$('body').removeClass('no_js'); 
        
		
		
     /* CAROUSEL Scroller */ 		

        /* for News  / home */
    	$(".news-scroll-content").jCarouselLite({
		vertical: true,
		hoverPause:true,
        easing:'easeInOutBack',
		visible: 1,
		speed:1000,
		auto:3000,
		});  
		
		
		/* for Links  / home */
		$(".links-scroll-content").jCarouselLite({
		horizontal: true,
		hoverPause:true,
        easing:'easeInOutBack',
		visible: 1,
		speed:1000,
		btnNext: ".next",
    	btnPrev: ".prev"
		});         

       
	    /* for References  / home */
		$(".references-scroll-content").jCarouselLite({
		vertical: true,
		hoverPause:true,
        easing:'easeOutQuad',
		visible: 4,
		speed:300,
		btnNext: ".next2",
    	btnPrev: ".prev2",
		auto:1000,
		}); 
		
		
		 /* for e-Bilgi  / home */
		$(".ebilgi-scroll-content").jCarouselLite({
		vertical: true,
		hoverPause:true,
        easing:'easeOutQuad',
		visible: 4,
		speed:300,
		btnNext: ".next3",
    	btnPrev: ".prev3",
		}); 
		
		/* for e-Bilgi  / home */
		$(".bilgihavuzu-scroll-content").jCarouselLite({
		vertical: true,
		hoverPause:true,
        easing:'easeOutQuad',
		visible: 1,
		speed:500,
		btnNext: ".next4",
    	btnPrev: ".prev4",
		});
		
	   
	//  Navigation
    $('#nav li > ul.sub-menu li').each(function(){
        n = $('ul.sub-menu', this).length;
        
        if(n) $(this).addClass('sub');
    });
    
    $('#nav ul > li').hover(
        function()
        {
            $('ul.sub-menu:not(ul.sub-menu li > ul.sub-menu)', this).fadeIn(700);    
        },
    
        function()
        {
            $('ul.sub-menu:not(ul.sub-menu li > ul.sub-menu)', this).fadeOut(1000);    
        }
    );               
    
    $('ul.sub-menu li', this).hover(
        function()
        {
            var options;
            
            winWidth = $(document).width();
            subMenuWidth = $(this).outerWidth();
            space = $(this).offset().left + subMenuWidth * 2;
            
            if(space < winWidth) options = {left:subMenuWidth};
            else options = {left:subMenuWidth*-1};
            
            $('ul.sub-menu', this).hide().css(options).fadeIn(300);
        },
    
        function()
        {
            $('ul.sub-menu', this).fadeOut(200);
        }
    ); 
    
    
    //  Slider
    $('img:not(.nofade, #slider img, img.icon, #slider-full-width img, a.thumb img)').hover(
	
        function(){ $(this).stop().animate({opacity:0.6}, 500); },
        function(){ $(this).stop().animate({opacity:1}, 500); }
    );      
    
	//  toTOP
		$(document).ready(function() {
			/*
			var defaults = {
	  			containerID: 'moccaUItoTop', // fading element id
				containerHoverClass: 'moccaUIhover', // fading element hover class
				scrollSpeed: 1200,
				easingType: 'linear' 
	 		};
			*/
			$().UItoTop({ easingType: 'easeOutQuart' });
			
		});
		
	
	//  Pretty Photo
    $("a[rel^='prettyPhoto']").prettyPhoto({
        slideshow:5000, 
        autoplay_slideshow:false,
        show_title:false
    });
    
	//  img hover zoom
    $('a.thumb').hover(
                            
        function()
        {
            $('<a class="zoom">zoom</a>').appendTo(this).css({dispay:'block', opacity:0}).animate({opacity:0.4}, 500);
        },
        
        function()
        {           
            $('.zoom').fadeOut(500, function(){$(this).remove()});
        }
    );
	

	

    $('a.socials').tipsy({fade:true, gravity:'s'});
    
    $('.toggle-content').hide();
    $('.toggle-title').click(function(){
        $(this).next().slideToggle(300);
        $(this).children('span.open-toggle').toggleClass('closed');
        $(this).attr('title', ($(this).attr('title') == 'Close') ? 'Open' : 'Close');
        return false;
    });
	  $('.toggle-title-press').click(function(){
        $(this).next().slideToggle(300);
        $(this).children('span.open-toggle').toggleClass('closed');
        $(this).attr('title', ($(this).attr('title') == 'Close') ? 'Open' : 'Close');
        return false;
    });     
    
    $('.tabs-container').tabs();                                       
    $('.tabs-container').tabs( "option", "fx", { opacity: 'toggle' } );
    
	
    // contact                           
    var error = true;      
    
    function addLoading()
    {
		$('#sendbutton').val('bekleyiniz...').attr('disabled', true);
	}    
    
    function removeLoading()
    {
		$('#sendbutton').val('Send').attr('disabled', false);
	}
	
	function addError(msg, e)
	{
		error = true;
		$(e).addClass('error');
		$('#usermessagea').html(msg);	
	}
	
	function removeError(e)
	{
		error = false;
		$('#usermessagea').html('');     
		$(e).removeClass('error');
	}
	
	$('#email').blur(function(){             
		var expr = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
		
		if( !expr.test( $(this).val() ) )  
			addError('<p class="error">Geçerli bir e-mail adresi giriniz!</p>', this);            
		else 
			removeError(this);
	});
    	
	$('#form-contact .required').blur(function(){
		if( $(this).val() == '' )
			addError('<p class="error">doldurulması gerekli alanlar boş bırakılmış!</p>', this);
		else               
			removeError(this);
	});
    
	$('#form-contact').submit(function(){
		if( !error )
		{                                                
			var datastring = '';
			
			$('#form-contact input, #form-contact select, #form-contact textarea').each(function(){
				datastring = datastring + $(this).attr('name') + "=" + $(this).val() + '&';
			});
			
			$('#usermessagea').html(''); 
			addLoading();
			
			$.post( $(this).attr('action'), datastring, function(response){
				$('#usermessagea').html(response);
				removeLoading();	
			});
		}
		else    
			addError('<p class="error">Gerekli alanlar doğru şekilde doldurulmamış!</p>', this);
		
		return false;
	});
});
