function hideIntro(flag) {
	if (flag == 1) {
		$('#intro').fadeOut(2000, function(){
			$(this).remove();
		});
		$('#hideIntro').fadeOut(2000);
	}
}

jQuery.easing['Zenonis'] = function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	};

$(function(){
	$('#hideIntro').click(function(){
		hideIntro(1);
	});
	
	$('#navigation a').hover(
		function(){
			curr_nav = $(this);
			nav_flag = 0;
			timer = setTimeout(function(){$(curr_nav).find('span').animate({width:'toggle'}, 700); nav_flag = 1;}, 250); 
		},
		function(){
			clearInterval(timer);
			if(1 == nav_flag){
				$(this).find('span').animate({width:'toggle'}, 700);
				nav_flag = 0;
			}
		}
	);
	
	if (page == 'index') {
		$('#img_block_1 img:first').fadeIn(2000, function(){
			$('#img_block_2 img:first').fadeIn(2000, function(){
				$('#img_block_3 img:first').fadeIn(2000, function(){
					RUN_Slides(); 
				});
			});
		});
		
		var slidesHoldInterval = null;
		
		function RUN_Slides() {
			$('#img_block_1').cycle({
				fx: 		'fade',
				speed:		2000,
				after:		function(){
						clearInterval(slidesHoldInterval);
						$('#img_block_1').cycle('pause');
						$('#img_block_2').cycle('next');
					}
			});
			
			$('#img_block_2').cycle({
				fx: 		'fade',
				speed:		2000,
				after:		function(){
						$('#img_block_2').cycle('pause');
						$('#img_block_3').cycle('next');
					}
			});
			
			$('#img_block_3').cycle({
				fx: 		'fade',
				speed:		2000,
				after:		function(){
						$('#img_block_3').cycle('pause');
						slidesHoldInterval = setTimeout(function(){$('#img_block_1').cycle('next')}, 3000);
					}
			});
		}
	}
	
	if (page == 'products' || page == 'product' || page == 'showroom') {
		function rotator_initCallback(carousel){
			$('#rotator_prev').bind('click', function() {
				carousel.prev();
				return false;
			});

			$('#rotator_next').bind('click', function() {
				carousel.next();
				return false;
			});
			
			$('#fancybox-left').live('click', function(){
				carousel.options.scroll = jQuery.jcarousel.intval(1);
				carousel.prev();
				carousel.options.scroll = jQuery.jcarousel.intval(3);
				return false;
			});
			
			$('#fancybox-right').live('click', function(){
				carousel.options.scroll = jQuery.jcarousel.intval(1);
				carousel.next();
				carousel.options.scroll = jQuery.jcarousel.intval(3);
				return false;
			});
		}
		
		$('#rotator').jcarousel({
    		wrap: 'circular',
			easing: 'Zenonis',
			wrap: 'last',
			animation: 1000,
			initCallback:rotator_initCallback
    	});
		
		$('#sub_navigation a').hover(
			function(){
				curr_sub_nav = $(this);
				sub_nav_flag = 0;
				timer = setTimeout(function(){$(curr_sub_nav).find('span.sub-item-over').animate({width:'toggle'}, 700); sub_nav_flag = 1;}, 250); 
			},
			function(){
				clearInterval(timer);
				if(1 == sub_nav_flag){
					$(this).find('span.sub-item-over').animate({width:'toggle'}, 700);
					sub_nav_flag = 0;
				}
			}
		);
		
		$('.content-text').jScrollPane({showArrows:true});

	}
	
	if (page == 'press') {
		function rotator_initCallback(carousel){
			$('#rotator_prev').bind('click', function() {
				carousel.prev();
				return false;
			});
            
			$('#rotator_next').bind('click', function() {
				carousel.next();
				return false;
			});
			
			$('#fancybox-left').live('click', function(){
				//carousel.options.scroll = jQuery.jcarousel.intval(1);
				//carousel.prev();
				//carousel.options.scroll = jQuery.jcarousel.intval(3);
				return false;
			});
			
			$('#fancybox-right').live('click', function(){
				//carousel.options.scroll = jQuery.jcarousel.intval(1);
				//carousel.next();
				//carousel.options.scroll = jQuery.jcarousel.intval(3);
				return false;
			});
		}
		
		$('#press_rotator').jcarousel({
			visible: 5,
			scroll: 5,
    		wrap: 'last',
			easing: 'Zenonis',
			animation: 1000,
			initCallback:rotator_initCallback
    	});
		
		$('#press_rotator a').fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'overlayShow'	:	true,
			'cyclic'        :   true,
			'titlePosition' :   'over',
			'showNavArrows' :   true
		});
		
		$('#press_rotator a').click(function(){
			gal = $(this).attr('rel');
			
			$.fancybox(pressGalleries[gal],
				{
				'padding'			: 0,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'              : 'image',
				'changeFade'        : 0
			});
		});
	}
	
	if (page == 'product' || page == 'showroom') {
		$('#rotator a').fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'overlayShow'	:	true,
			'cyclic'        :   true,
			'titlePosition' :   'over',
			'showNavArrows' :   true
		});
	}
	
});

