// JCAROUSELLITE 

$(function() {
    $(".homeSlider1").jCarouselLite({
        circular: true,
		visible: 1,
		scroll: 1,
		auto: 6000,
		speed: 0,
		beforeStart: function(a) {
			$(a).parent().fadeTo(0, 0);
			var bg = $(a).find('img').attr('src');
			$('.gallery_carousel').css({
				backgroundImage: "url("+bg+")"
			}, 0);
		},
		afterEnd: function(a) {
			$(a).parent().fadeTo(500, 1);
		}
    });
});

$(function() {
    $(".homeSlider2").jCarouselLite({
        circular: true,
		visible: 1,
		scroll: 1,
		auto: 6000,
		speed: 0,
		beforeStart: function(a) {
			$(a).parent().fadeTo(0, 0);
			var bg = $(a).find('img').attr('src');
			$('.gallery_carousel').css({
				backgroundImage: "url("+bg+")"
			}, 0);
		},
		afterEnd: function(a) {
			$(a).parent().fadeTo(500, 1);
		}
    });
});

$(function() {
    $(".homeSlider3").jCarouselLite({
        circular: true,
		visible: 1,
		scroll: 1,
		auto: 6000,
		speed: 0,
		beforeStart: function(a) {
			$(a).parent().fadeTo(0, 0);
			var bg = $(a).find('img').attr('src');
			$('.gallery_carousel').css({
				backgroundImage: "url("+bg+")"
			}, 0);
		},
		afterEnd: function(a) {
			$(a).parent().fadeTo(500, 1);
		}
    });
});

$(function() {
    $(".homeSlider4").jCarouselLite({
        circular: true,
		visible: 1,
		scroll: 1,
		auto: 6000,
		speed: 0,
		beforeStart: function(a) {
			$(a).parent().fadeTo(0, 0);
			var bg = $(a).find('img').attr('src');
			$('.gallery_carousel').css({
				backgroundImage: "url("+bg+")"
			}, 0);
		},
		afterEnd: function(a) {
			$(a).parent().fadeTo(500, 1);
		}
    });    
});

$(function() {
    $(".aboutCarousel").jCarouselLite({
        btnNext: ".teamBtn",
        btnPrev: ".servicesBtn",
        visible: 1,
        circular: false
    });
});

 

// CONTACT DROPDOWN

$(document).ready(function(){

	$("#slidingDiv").hide(); 
	$(".trigger").click(function(){
		$('html, body').animate({scrollTop: '0px'}, 0);
		$("#slidingDiv").slideToggle("slow");
		return false;
	});

});

// NEW ARCHIVES FILTER FUNCTION

$(document).ready(function() {

	$('ul#filter a').click(function() {
		$(this).css('outline','none');
		$('ul#filter .current').removeClass('current');
		$(this).parent().addClass('current');
		
		var filterVal = $(this).text().toLowerCase().replace(' ','-');

		if(filterVal == 'all') {
			$('ul#portfolio li.hidden').fadeIn('slow').removeClass('hidden');
		} else {

			$('ul#portfolio li').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).fadeOut('normal').addClass('hidden');
				} else {
					$(this).fadeIn('slow').removeClass('hidden');
				}
			});
		}
	
		return false;

	});

});


// OLD ARCHIVES FILTER FUNCTION


$(document).ready(function() {
	$('.menuSort li a').click(function() {

		$('.menuSort li').removeClass('selected');
		$(this).parent('li').addClass('selected');

		thisItem 	= $(this).attr('rel');

$('.itemSort li[rel!='+thisItem+']').stop().animate({'width' : 0, 'opacity' : 0,'marginRight' : 0},function(){
$('.itemSort li[rel!='+thisItem+']').css("display","none");});

		if(thisItem != "all") {

			$('.itemSort li[rel~='+thisItem+']').stop()
				.animate({'width' : '220px',
				'opacity' : 1,
				'marginRight' : '7px',
				'marginLeft' : '7px'
			});

			$('.itemSort li:not([rel~='+thisItem+'])').stop()
				.animate({'width' : 0,
				'opacity' : 0,
				'marginRight' : 0,
				'marginLeft' : 0
			});

		} else {

			$('.itemSort li').stop()
				.animate({'opacity' : 1,
				'width' : '220px',
				'marginRight' : '7px',
				'marginLeft' : '7px'
			});
		}
	})


	//$('.itemSort li img').animate({'opacity' : 0.5}).hover(function() {

		//$(this).animate({'opacity' : 1});

	//}, function() {

		//$(this).animate({'opacity' : 0.5});

	//});

});



// FIXED SIDEBAR

$(function() {
    var $sidebar   = $("#fixedSidebar"),
        $window    = $(window),
        offset     = $sidebar.offset(),
        topPadding = 15;
    $window.scroll(function() {
        if ($window.scrollTop() > offset.top) {
            $sidebar.stop().animate({
                marginTop: $window.scrollTop() - offset.top + topPadding
            });

        } else {
            $sidebar.stop().animate({
                marginTop: 0
            });
        }
    });
});




// DROP DOWN MENU
var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}

	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();
