$(function () {


var scrollerSrc = new Array(
	'/assets_2010/images/homepage/slider_image_1.png',
	'/assets_2010/images/homepage/slider_image_2.jpg',
	'/assets_2010/images/homepage/slider_image_3.png',
	'/assets_2010/images/homepage/slider_image_4.png');

	$('#scroller a.loading').each(function (i) {

			var img = new Image();
			var target = this;
			$(img).load(function () {

					$(this).hide();
					$(target).removeClass('loading').append(this);
					$(this).show()
			}
).error(function () {
}
);
			$(img).attr('src', scrollerSrc[i]);
			$(img).attr('width', 960);
			$(img).attr('height', 299);
	}
);

    window.api = $("#scroller").scrollable({

        vertical: true,
        clickable: false,
        speed: 1200,
        size: 1
    }
).circular().autoscroll({

        interval: 6000,
				autoplay: true,
				api: true
    }
);
		
		api.onStart(function() {
			
			$('.scroller_thumb').removeClass('active_thumb');			
			var thumbIndex = api.getIndex();
			if(thumbIndex == 5){

				thumbIndex = 0;
			}

			$('#st_'+thumbIndex).addClass('active_thumb');
		}
);
		
		$('.demoLink').click(function() {

			api.stop();
		}
);
		
		$('.scroller_thumb').click(function() {

			api.stop();
		}
);		
		
		$('.video_play').click(function() {

			api.stop();
		}
);
		
		$('#scroller').hover(
			function () {

				api.pause();
			}
,
			function () {

				api.pause();
			}

		);
		var activeBox;
		$('.block_fourth').hover(
			function () {

				
				activeBox = true;
				api.pause();
				$('.block_fourth').css('z-index','10');
				$('.bf_content_l').css('opacity', 0);
				$('.bf_content_l').css('display', 'none');
				$('.bf_bg2').css('display', 'none');

				$('#row_2_mask').css('display', 'block')
				
				$('#row_2_mask').animate({
 
					opacity: .6
				}
, {
queue:false, duration:100}
);
				
				var thisID = '#'+$(this).attr('id');
				$(thisID).css('z-index','100');
				$(thisID+' .bf_bg1').css('z-index','100');
				$(thisID+' .bf_content_l').css('display', 'block');				
				$(thisID+' .bf_content_s').css('display', 'none');
				
				$(thisID+' .bf_content_l')
				.animate({

					opacity: 1
				}
, {
queue:false, duration:400}
);
				
				$(thisID+' .bf_bg1').animate({

					width: 473,
					height: 299,
					top: 36
				}
, {
queue:false, duration:400}
);
				
				$('#row_2_mask').animate({

					width: 960
				}
, 400,
					function(){

						if (activeBox == true && $(thisID+' .bf_content_l').css('display') == 'block'){

							$(thisID+' .bf_bg2').css('display', 'block');
						}

				}
);
				var largeBox=$(thisID+' .bf_content_l');
				var shadow=$(thisID+' .bf_bg2');
				var smallBox=$(thisID+' .bf_content_s');
				startShowShadow( largeBox, smallBox, shadow)

			}
,
			function () {

				activeBox = false;
				api.pause();
				var thisID = '#'+$(this).attr('id');
				$(thisID+' .bf_bg2').css('display', 'none');
				$(thisID+' .bf_bg1').css('z-index','5');			
				$(thisID+' .bf_content_l').animate({
 
					opacity: 0
				}
, {
queue:false, duration:400}
);

				$(thisID+' .bf_bg1').animate({

					width: 230,
					height: 152,
					top: -1
				}
, 400,
					function(){

						if (activeBox == false){

							$('#row_2_mask').css('display', 'none');
							$('#row_2_mask').css('opacity', '0');
						}

				}
);
				var largeBox=$(thisID+' .bf_content_l');
				var shadow=$(thisID+' .bf_bg2');
				var smallBox=$(thisID+' .bf_content_s');
				startSBShow( largeBox, smallBox, shadow )

			}
);
		


  function startSBShow( largeBox, smallBox, shadow ) {


		var SBInterval;
		SBInterval = setInterval( function() {
 SBShow( SBInterval, largeBox, smallBox, shadow ); }
, 100);
  }
;

  function SBShow( SBInterval, largeBox, smallBox, shadow ) {

	
		var browserVersion = navigator.appName;		
    if (largeBox.css('opacity') <= .2 && browserVersion != 'Microsoft Internet Explorer'){

			shadow.css('display', 'none');	
			smallBox.css('display', 'block');
			smallBox.css('opacity', .3);
			smallBox.animate({
 
				opacity: 1
			}
, {
queue:false, duration:300}
);			
			clearInterval( SBInterval );
		}

    else if (largeBox.css('opacity') <= .2 && browserVersion == 'Microsoft Internet Explorer'){

			smallBox.css('display', 'block');		
			clearInterval( SBInterval );
		}
;
  }
;

  function startShowShadow( largeBox, smallBox, shadow ) {

		var showShadowInterval;
		showShadowInterval = setInterval( function() {
 showShadow( showShadowInterval, largeBox, smallBox, shadow ); }
, 100);
  }
;

  function showShadow( showShadowInterval, largeBox, smallBox, shadow ) {

    if (largeBox.css('opacity') == 1){

			smallBox.css('display', 'none');	
			shadow.css('display', 'block');	
			clearInterval( showShadowInterval );
		}
 else if (largeBox.css('opacity') == 0){

			clearInterval( showShadowInterval );
		}
;
  }
;

		
		
		$('.close').click(function() {

			api.play();
		}
);
		
			var root = $("div.scrollable").scrollable({
size: 1, speed: 600}
).navigator().mousewheel();
			window.api2 = root.data("scrollable");
		
			api2.onBeforeSeek(function() {

				$('.slider_arrow_hp').css('display','none');
			}
);
		
			api2.onSeek(function() {

				$('.slider_arrow_hp').css('display','block');
			}
);
			
			$('.navi a').attr('onclick','page_tracker_event("Testimonials Section","Arrows and Boxes","Testimonials Section");');
	
}
);
