(function($){
       $.jscroll = function(options){
               var options = $.extend({
                       to: 0,
                       easing: 'swing',
                       duration: 1000
               }, options || {});

               var c = 0, ie=false;
               
               if(typeof window.scrollX === "undefined"){
               	  ie=true;
               }
               var start = (ie===true)?document.documentElement.scrollLeft:window.scrollX;
               var startY= (ie===true)?document.documentElement.scrollTop:window.scrollY;
			   var changeY= parseInt(0 - startY);
			   
               if(typeof(options.to)==="number"){
                       var change = parseInt(options.to - start);
                       
               }else{
                       var $targ = $(options.to).eq(0);
                       var change = parseInt($targ.offset().left - start);
               };

               var anim = setInterval(function(){
                       c+=30;
                       window.scrollTo($.easing[options.easing](0, c, start, change, options.duration), $.easing[options.easing](0, c, startY, changeY, options.duration));

                       if(c >= options.duration){
                               clearInterval(anim);
                       };
               }, 30);

               return this;
       };
       
	$.fn.swapper = function(parent, child, hider){
		if(typeof parent==="undefined" || typeof child==="undefined"){return;}
		$(parent).children(child+(typeof hider==="undefined"?":gt(0)":"")).hide();
		var $that = this;
		return this.each(function(i, el){
			var $link = $(this);
			$link.bind('click', function(){
				$(parent).children(child).add(hider).animate({opacity:0}, function(){
					$(this).css({display:'none'});
					$that.removeClass('active');
				});
				setTimeout(function(){$(parent).children(child).eq(i).css({display:'block', opacity:0}).animate({opacity:1}); $link.addClass('active');},420);
				return false;
			});
		});
    };
})(jQuery);

$(function(){
	$('.scroll-pane').jScrollPane({dragMinHeight:64, dragMaxHeight:64, scrollbarWidth:18});

   $('#nav ul a').unbind('click').bind('click', function(){
       var tmp = this.href.slice( this.href.indexOf("#"), this.href.length );
       if(tmp==="#index.php"){
           $.jscroll({to:0});
       }else{
           $.jscroll({to:tmp});
       };
       return false;
   });
   
   $('#header h1 a').unbind('click').bind('click', function(){
   		$.jscroll({to:0});
   		return false;
   });
   
   // anchor selector........ parent div.. p wrap.. original content
   $('#serv_btns a').swapper('#serv_left', 'span', 'div.tohide');
   
   $('.back_btn').live('click', function(){
   		$('#serv_left > span').stop(true).animate({opacity:0}, function(){$(this).css({display:'none'});
   		$('#serv_left > .tohide').css({display:'block'}).stop(true).animate({opacity:1});
   		});
   		return false;
   });
     
   $('#slow_links a').swapper('#slow_content_swap', 'span' );
   $('#test_vid_links a').swapper('#video_swaper', 'span' );
	//$('#faq_links li a').swapper('#faq_answers', 'div' );
   
   
	var testiw = $('#testim_swap').width();
	var testin = $('#testim_wrap span').length, cur=0;

	$('#testim_swap').css({position:'relative', overflow:'hidden'}).find('#testim_wrap').css({
		position:'absolute', top:0, left:0
	}).find('span').css({float:'left', display:'block', width:testiw});
	
	$('#testim_wrap').css({
		width:testiw*$('#testim_wrap span').length
		//height:$('#testim_swap').height()
	});
	
	$('#test_arrows a:first').bind('click', function(){
		// ale is a douche
		if(cur>0){cur--;};
		$('#testim_wrap').stop(true).animate({left:-(cur*testiw)});
		return false;
	});
	
	$('#test_arrows a:last').bind('click', function(){
		// ale is a douche
		if(cur<testin-1){cur++;};
		$('#testim_wrap').stop(true).animate({left:-(cur*testiw)});
		return false;
	});
});
