﻿jQ(function(){
    if(jQ('#home-slider').length>0 && jQ('#home-slider-nav').length>0)
	{
		jQ('#home-slider').cycle({
			fx: 'fade', //scrollHorz
			speed: 500,
			timeout: 6000,			
			pager: '#home-slider-nav', 
            pagerEvent: 'mouseover',
            pagerAnchorBuilder: function(idx, slide) {	
                return '#home-slider-nav dl:eq(' + idx + ')';
			}
		});
                
        var totalW = parseInt(jQ(window).width());
		//jQ(".slider-item").css("max-width",totalW+"px");
		jQ("#home-slider").css("width",totalW+"px");
		
        jQ('.slider-item img').each(function(){
            var imgObj = jQ(this);
            var parentBox = jQ('.slider-item');
            var objImagePreloader = new Image();            
            objImagePreloader.onload = function() {
                width =jQ(".slider-item img").width();  
				//alert(width+"--"+totalW);
                var leftpos = (totalW-parseInt(width))/2;
                leftpos = leftpos.toFixed(0);
                parentBox.css({
                    'margin-left' : leftpos+'px'
                    
                });
            };
            objImagePreloader.src = jQ(this).attr('src');
        });
	};
	
	
	 function isScrolledIntoView(elem) {
        var docViewTop = jQ(window).scrollTop();
        var docViewBottom = docViewTop + jQ(window).height();
        var elemTop = jQ(elem).offset().top;
        if (elemTop + 50 < docViewBottom) {
            return true
        } else {
            return false
        }
    }
    function animateShow(item, time,callback) {
        if (jQ(item).attr('init') == 'false'&& isScrolledIntoView(jQ(item).parent()) ){
            jQ(item).attr('init', 'true');
            setTimeout(function(){
                jQ(item).fadeIn(800);
				
            },time)
        }
        }
		function animateFade(item, time,callback) {
        if (jQ(item).attr('init') == 'false'&& isScrolledIntoView(jQ(item).parent()) ){
            jQ(item).attr('init', 'true');
            setTimeout(function(){
                jQ(item).animate({opacity:1.0},500);
				
            },time)
        }
        }
		
    jQ(window).scroll(function () {
		animateFade('.cases_dl',300);
		animateShow('.partners_table',300);
       
    });
    
})

function banner_hover(i)
{
	jQ("#home-slider-nav>dl").each(function(index){
			if(i==index){
			   jQ(this).addClass("sel");
			}
			else
			{
				 jQ(this).removeClass("sel");
			}
										   }
    )
}
function banner_out()
{
	jQ("#home-slider-nav>dl").each(function()
										   {
								  jQ(this).removeClass("sel");
										   }
    )
}