﻿/*  THIS TICKER SCRIPT REQUIRES THE JQUERY LIBRARY TO RUN  */

//  ---------------------------------------------------------------------------
//	variables
//  ---------------------------------------------------------------------------

    //	ticker animation speed
    var iTickerSpeed = 30;
    
    //	ticker animation paused flag
    var isPaused = false;



//  ---------------------------------------------------------------------------
//	homepage ticker animator
//  ---------------------------------------------------------------------------

    $(document).ready(function() {
        if (!document.getElementById("HomepageTicker")) {
             $("#HomepagePromoBanner").css("margin-top", "0");
             return;
        }
    
	    $("#HomepageTicker .Content").each(function() {
	        //	store start and finish positions and move ticker content to start position
		    //  firefox: set position to absolute to return the correct width as the width is capped by the main content container
		    if ($.browser.mozilla) {
		        this.style.position = "absolute";
		    }
		    
		    this.start = $("#HomepageTicker").width();
		    this.finish = 0 - $(this).width();
    		
		    if ($.browser.mozilla) {
		        this.style.position = "relative";
		    }
    		
		    this.style.left = this.start + "px";
    		
    	    //	attach events to ticker to pause/resume ticker scrolling
		    $("#HomepageTicker").bind("mouseover", function() {
			    $(this).find(".Content").each(function() {
				    this.isPaused = true;
			    });
		    }).bind("mouseout", function() {
			    $(this).find(".Content").each(function() {
				    this.isPaused = false;
			    });
		    }).css("visibility", "visible");
    		
		    //	start animation
		    animateTicker(this);
	    });
    });
  
    function animateTicker(obj) {
        if (!obj.animate) {
	        obj.animate = setInterval(function() {
		        //	if the ticker is not paused then continue
		        if (obj.isPaused != true) {
			        var x = parseInt(obj.style.left);
			        obj.style.left = (x > obj.finish) ? (x - 1) + "px" : obj.start + "px";
		        }
	        }, iTickerSpeed);
	    }
    }