﻿(function(jq) {
    jQuery.fn.scroll = function(settings) {
        settings = jQuery.extend({
            travelocity: 0.1
        }, settings);
        return this.each(function() {
            jQuery('#ticker').removeClass('hide');
            var $strip = jQuery(this);
            $strip.addClass("newsticker")
            var stripWidth = 0;
            var $mask = $strip.wrap("<div class='mask'></div>");
            var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");
            var containerWidth = $strip.parent().parent().innerWidth(); //a.k.a. 'mask' width 
            
            $strip.find("li").each(function(i) {
                stripWidth += jQuery(this, i).innerWidth();
            });
            $strip.width(stripWidth);
            /*
                PB 19/01/09: replaced with the code below inc width of container;
                var defTiming = stripWidth / settings.travelocity;
            */
            var totalTravel = stripWidth + containerWidth;
            var defTiming = Math.floor(totalTravel / settings.travelocity);
            function scrollnews(spazio, tempo) {
                $strip.animate({ left: '-=' + spazio }, tempo, "linear", function() {
                    $strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);
                });
            }
            scrollnews(totalTravel, defTiming);
            $strip.hover(
                function() {
                    jQuery(this).stop();
                },
                function() {
                    var offset = jQuery(this).offset();
                    var residualSpace = offset.left + stripWidth;
                    var residualTime = Math.floor(residualSpace / settings.travelocity);
                    scrollnews(residualSpace, residualTime);
                });
        });
    };
 })(jQuery);

function getVar(name){get_string=document.location.search;return_value='';do{name_index=get_string.indexOf(name+'=');if(name_index!=-1){get_string=get_string.substr(name_index+name.length+1,get_string.length-name_index);end_of_value=get_string.indexOf('&');if(end_of_value!=-1)value=get_string.substr(0,end_of_value);else value=get_string;if(return_value==''||value=='')return_value+=value;else return_value+=', '+value}}while(name_index!=-1)space=return_value.indexOf('+');while(space!=-1){return_value=return_value.substr(0,space)+' '+return_value.substr(space+1,return_value.length);space=return_value.indexOf('+')}return(return_value)}
                        function getNumber(source){switch(source){case"ps":return"1300 675 840";case"oa":return"1300 675 962";case"sta":return"134 STA (782)";default:return"134 STA (782)"}}
                        function getImgPath(source){switch(source){case"ps":return"http://www.statravel.com.au/static/au_division_web_live/assets/AU_division/phoneNoCta-AU-1300675840.png";case"oa":return"http://www.statravel.com.au/static/au_division_web_live/assets/AU_division/phoneNoCta-AU-1300675962.png";case"sta":return"http://www.statravel.com.au/static/au_division_web_live/assets/AU_division/phoneNoCta-AU.png";default:return"http://www.statravel.com.au/static/au_division_web_live/assets/AU_division/phoneNoCta-AU.png"}}
                        function setCookie(cookiename,value,minutes){if(minutes){var date=new Date();date.setTime(date.getTime()+(minutes*60*1000));var expires="; expires="+date.toGMTString()}else var expires="";document.cookie=cookiename+"="+value+expires+"; path=/"}               
                        function getCookie(cookiename){var nameEQ=cookiename+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length)}return null}
                        var cSource;
                        tSource=getVar("tsrc");
                        if(tSource!==''){
                           setCookie('tSrc',tSource,90*24*60);} 
                        cSource=getCookie('tSrc');
                       $(".phoneimg").attr('src',getImgPath(cSource));

                      $(document).ready(function(){
                         $(".phonetext").text(getNumber(cSource));
                      });
