$(document).ready(function(){
	$(function() {
		var $elem = $('body');
		$('#nav_up').fadeIn('slow');
		$('#nav_down').fadeIn('slow');  
		
		$(window).bind('scrollstart', function(){
			$('#nav_up,#nav_down').stop().animate({'opacity':'0.2'});
		});
		$(window).bind('scrollstop', function(){
			$('#nav_up,#nav_down').stop().animate({'opacity':'1'});
		});
		
		$('#nav_down').click(
			function (e) {
				$('html').animate({scrollTop: $elem.height()}, 800);
			}
		);
		$('#nav_up').click(
			function (e) {
				$('html').animate({scrollTop: '0px'}, 800);
			}
		);
	});

	Cufon.set('arial').replace('.email_address');
	
/*Control Button slide*/
	
	$(function() {
		$('.slidebttn').hover(
			function () {
				var $this 		= $(this);
				var $slidelem 	= $this.prev();
				$slidelem.stop().animate({'width':'70px'},300);
				$slidelem.find('span').stop(true,true).fadeIn();
				
			},
			function () {
				var $this 		= $(this);
				var $slidelem 	= $this.prev();
				$slidelem.stop().animate({'width':'20px'},200);
				$slidelem.find('span').stop(true,true).fadeOut();
				
			}
		);
	});
	
	
/*Cycle functions (jquery.cycle.js) */

	$('#scrollNews ul').cycle({ 
	    fx: 'scrollVert',
		speed: 650,
		rev: true,
		timeout: 0,
		next:   '#scrollNews ol li.next', 
	    prev:   '#scrollNews ol li.previous',
	    cssBefore: {  
	        width: 220, 
	        height: 250  
	    },
	    cssAfter: {  
	        width: 220, 
	        height: 250  
	    },
	    delay: -2000
	});
/*
 * 	 scroll-testimonials
 */

	$('#scroll-testimonials ul').cycle({ 
	    fx: 'scrollVert',
		speed: 650,
		rev: true,
		timeout: 0,
		next:   '#scroll-testimonials ol li.next', 
	    prev:   '#scroll-testimonials ol li.previous',
	    cssBefore: {  
	        width: 220, 
	        height: 250  
	    },
	    cssAfter: {  
	        width: 220, 
	        height: 250  
	    },
	    delay: -2000
	});

	/*image slider */
	if (jQuery('.featured_item').length > 0 )jQuery('#featured').qs({  
			duration:600, 					// transition duration 
			transition:"easeInOutCubic", 	// transition easing
			opacity:0.6,					// opacity of second row
			opacity_level2:0,				// opacity of third row
			interval: 4000					// interval between auto rotate, set to false if you want to disable outorotation
			
		});
		
	
	

});

/*(function($)
{ 
	$.fn.qs = function(default_options) 
	{
		var defaults = 
		{  
			duration:600, 					// transition duration 
			transition:"easeInOutCubic", 	
			opacity:0.6,
			opacity_level2:0,
			interval: 5000
			
		};  
		
		var def = $.extend(defaults, default_options); 
		
		return this.each(function()
		{	
			
			var $container = $(this), $items = $container.find('.featured_item'), $values = [], $zindex = [], $offset = 0, $animating = false, $clicked=false;
			
			var interval = setInterval(function(){}, 50000);
			
			jQuery(window).load(function(){
				if(def.interval && !$clicked )
					{
					interval = setInterval(function() { rotate(-1); }, def.interval); 
					}
				});
		
			if (def.opacity != 1 && def.opacity_level2 != 1)
			{	$items.not('.featured_item_active').css('opacity',def.opacity_level2);
				$container.find('.featured_item_active').css('opacity', 1);
				$container.find('.featured_item_last, .featured_item_upcoming').css('opacity', def.opacity);
				
			}
			$items.each(function(i)
			{	
				var $item = $(this);
				 
				$values[i]= {
								width: $item.width(),
								top: parseInt($item.css('top')),
								left: parseInt($item.css('left')),
								opacity: $item.css('opacity')
							};
							
				$zindex[i] =	$item.css('zIndex');
							
			}); 
			
			
			$items.click(function(e)
			{	
				if (! $animating)
				{	
					$direction = e.pageX > $(window).width() / 2 ? -1 : 1;
					rotate($direction);
				}
				clearInterval(interval);
				$clicked = true;
			}); 
			
			function rotate($direction)
			{	
				if ($items.length <= 2) return;
				$animating = true;
				
				if($items.length == $offset || $items.length == ($offset*-1))
				{
					$offset = 1 * $direction;
				}
				else
				{
					$offset = $offset + $direction;
				}
								
				
				
				$items.each(function(i)
				{	
					var $item = $(this), $next;
					
					$next = i + $offset;
					
						if($next >= $items.length)
						{
							$next = i - $items.length + $offset;
						}
						else if($next < 0)
						{
							$next = i + $items.length + $offset;
						}
					
									
					$item.animate($values[$next], def.duration, def.transition);
					$item.find("img").animate({width:$values[$next].width-12}, def.duration, def.transition, function()
					{
						$animating = false;
					});
					
					setTimeout(function()
					{
        				$item.css({zIndex: $zindex[$next]});
    				}, def.duration / 2);
    				
				});
			} 
		});	
	};
})(jQuery); 

/*Scroll startstop event jquery*/
/*
(function(){
    
    var special = jQuery.event.special,
        uid1 = 'D' + (+new Date()),
        uid2 = 'D' + (+new Date() + 1);
        
    special.scrollstart = {
        setup: function() {
            
            var timer,
                handler =  function(evt) {
                    
                    var _self = this,
                        _args = arguments;
                    
                    if (timer) {
                        clearTimeout(timer);
                    } else {
                        evt.type = 'scrollstart';
                        jQuery.event.handle.apply(_self, _args);
                    }
                    
                    timer = setTimeout( function(){
                        timer = null;
                    }, special.scrollstop.latency);
                    
                };
            
            jQuery(this).bind('scroll', handler).data(uid1, handler);
            
        },
        teardown: function(){
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid1) );
        }
    };
    
    special.scrollstop = {
        latency: 300,
        setup: function() {
            
            var timer,
                    handler = function(evt) {
                    
                    var _self = this,
                        _args = arguments;
                    
                    if (timer) {
                        clearTimeout(timer);
                    }
                    
                    timer = setTimeout( function(){
                        
                        timer = null;
                        evt.type = 'scrollstop';
                        jQuery.event.handle.apply(_self, _args);
                        
                    }, special.scrollstop.latency);
                    
                };
            
            jQuery(this).bind('scroll', handler).data(uid2, handler);
            
        },
        teardown: function() {
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid2) );
        }
    };
    
})();*/
