$(document).ready(function() {
	
	$('.search a').click(function() {
		var $marginLefty = $(this).next();
			$marginLefty.animate({
				marginLeft: parseInt($marginLefty.css('marginLeft'),10) == 0 ?
			$marginLefty.outerWidth() :
			0 },
		{ 
			duration: 'slow',
           	easing: 'easeInCirc'		
	});
	
	$(this).toggleClass("active"); return false;
	});
	
	$('.logos, .allProjects').hide();

	$('.view_logos').click(function(){
        if($(this).hasClass('on')){
            $(this).removeClass('on').next('.logos').fadeTo(250,0).slideUp("fast");
        }else{
            $(this).addClass('on').next('.logos').fadeTo(0,0).slideDown("fast").fadeTo(1000,1);
        }
        return false;
    });
    
    $(".panel").toggle(function(){
		$(this).animate({ height:"200px"}, 800, "easeInBack");
		$(this).toggleClass("active");
	},function(){
		$(this).animate({ height:"44px"}, 500, "easeInQuad");
		$(this).toggleClass("active");
	});
	
	function onBefore() { 
    	$(".panel").animate({ height:"0"}, 800, "easeInBack");
	} 
	function onAfter() { 
    	$(".panel").animate({ height:"44px"}, 800, "easeInBack");
	}
	
    
    $('.slideshow').cycle({
        fx:      'dapa', 
   		speedIn:  500, 
   		speedOut: 500,  
   		timeout: 7000,
   		easing: 'jswing',
   		pauseOnPagerHover: 'true',
   		pause: 'true',
   		delay: 1000,
   		sync: 0,
        pager:  '.pager',
        before:  onBefore, 
   		after:   onAfter, 
        pagerAnchorBuilder: function(idx, slide) {
            return '.pager li:eq(' + (idx) + ') a';
        }
    });
    
     $('.slides').cycle({
        fx:      'scrollHorz',
        easing: 'jswing',
        speed:  500,
   		timeout: 0, 
        pager:  '.projectPager ul',
        pagerAnchorBuilder: function(idx, slide) {
            return '.projectPager ul li:eq(' + (idx) + ') a';
        }
    });
    
    $("#logo span").hide();
		$("#logo a").hover(
			function(){
				$(this).find("span").fadeIn();
			},
			function() {
				$(this).find("span").fadeOut();
			}
	);
	
	$('.contact').click(function(){
		$('#contact, #mask').fadeIn('fast');
		$(this).addClass('current');
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		return false;
	})
	
	$('.closeBtn').click(function(){
		$('#contact, #mask').fadeOut("fast");
		$('.contact').removeClass('current');
		return false;
	})
	
	$('#mask').click(function () {  
		$(this).fadeOut("fast");  
		$('#contact').fadeOut("fast");
		$('.contact').removeClass('current');  
	});
	
	$('.viewAll span').click(function() {
		$('.allProjects').fadeSliderToggle();
		$(this).text($(this).text() == 'View All Design' ? 'Hide All Design' : 'View All Design');
		$(".viewAll").toggleClass("selected"); return false;
	});  
	
	 $("div.scrollable").scrollable();
	 
	 $(".search a").tooltip({ 
        tip: '#tooltip', 
        position: 'bottom left', 
        offset: [10, -30], 
        lazy: true, 
        delay: 0 
    });
    
    $(".next span.title").hide();
		$(".next .button").hover(
			function(){
				$(".next span.title").fadeIn();
			},
			function() {
				$(".next span.title").fadeOut();
			}
	);
	
	$(".prev span.title").hide();
		$(".prev .button").hover(
			function(){
				$(".prev span.title").fadeIn();
			},
			function() {
				$(".prev span.title").fadeOut();
			}
	);
	
	$('.projectDetail').hide().delay(800).fadeIn(500);
	 		    
});	
