var $j = jQuery.noConflict();


//==================================================
//BANNER

var BANNER_SLIDER = {};
    BANNER_SLIDER.slider = (function () {
	    var imageWidth = $j("#slideHeaderDiv").width();
	    var imageSum = $j("#bannerPosition-1 img").length;
	    var imageReelWidth = imageWidth * imageSum;
	    var $active,play;

	    function init() {
		    $j(".paging").show();
		    $j(".paging a:first").addClass("active");
		    $j("#bannerPosition-1").css({'width' : imageReelWidth});
			setInterval (function (){
				function onBlur() {
				    clearInterval(play); //Stop the rotation
				};
				function onFocus(){
				};
				if (/*@cc_on!@*/false) { // check for Internet Explorer
				    document.onfocusin = onFocus;
				    document.onfocusout = onBlur;
				} else {
				    window.onfocus = onFocus;
				    window.onblur = onBlur;
				}
			}, 500 );
		    rotateSwitch();    
		    $j("#slideHeaderDiv").hover(function() {
		        clearInterval(play);
		    }, function() {
		        rotateSwitch();
		    });    
		    $j(".paging a").click(function(e) {    
		        e.preventDefault();
		        $active = $j(this);
		        clearInterval(play);
		        rotate();
		        rotateSwitch();
		    });
	    }
	    	    
	    rotate = function(){    
	        var triggerID = $active.attr("rel") - 1;
	        var image_reelPosition = triggerID * imageWidth;
	        $j(".paging a").removeClass('active');
	        $active.addClass('active');
	        $j("#bannerPosition-1").stop().animate({
	            left: -image_reelPosition
	        }, 500 );
	    };
	    rotateSwitch = function(){        
	        play = setInterval(function(){
		        $active = $j('.paging a.active').next();
		        if ( $active.length === 0) {
		            $active = $j('.paging a:first');
		        }
		        rotate();
	        }, 7000);
	    };
  return {
    init: init
  };
})();    
//end


//DOC READY
$j(document).ready(function(){
//==================================================
//BANNER
		if($j('#bannerPosition-1 img').length > 1){
			BANNER_SLIDER.slider.init();
		}
});//End Doc Ready


