var news_length;
var news_count;

$(document).ready(function(){
  // news scroller
  news_count = $('div.newScroller > a').size();
  news_length = get_newslength();

  $('div.newScroller').css('left', $('div#headline').width()+10+'px');

  headline_rotate();
  headline_inteval = setInterval(headline_rotate,news_count*12000+500); 

  // lightbox
  $(function() {
        $('#picShow a').lightBox({fixedNavigation:true});
    });
  
  // other effects
  $(".tabNav li a").click(change_tab);
  
  $('#picShow li').hover(
    function(){$(this).addClass("on");},
    function(){$(this).removeClass("on");}
    );
    
  $(".newsItem").hover(
    function(){
      $(this).css("border-color", "#054677");},
    function(){
      $(this).css("border-color", "#AEE3FF");});
      
  $(".productItem").hover(
    function(){
      $(this).find(".frame").stop();
      $(this).find(".frame").css("opacity", "1");},
    function(){
      $(this).find(".frame").animate({opacity: 0}, "normal");});
      
  $("#suburb").change(
    function(){
      var path=location.pathname;
      var qs=location.search;
      qs=qs.substr(qs.indexOf("state"));
      qs=qs.substr(qs.indexOf("=")+1);
      var end=qs.indexOf("&");
      var state=qs.substr(0, end==-1?qs.length:end);
      if (this.selectedIndex==0)
        location.href=path+"?state="+state;
      else
        location.href=path+"?state="+state+"&filter="+this.options[this.selectedIndex].value;});

});
  
function get_newslength() {

  var count = $('a.news').size(); 
  var length = 0;
  for(i=0; i<count; i++)
  { length += $('a.news:eq('+i+')').width(); }
  
  return length+30*count;
}

function headline_rotate() {

  $('div.newScroller')
    .animate({left: -news_length-10},news_count*12000, 'linear', function() {
      $(this).css('left', $('div#headline').width()+10+'px');
    });
} 

function change_tab() {
    for(i=0; i<$(".tabNav li").size(); i++)
    {
        if($(".tabNav li:eq("+i+") a").text() == $(this).text())
        {
            $(".tabNav li:eq("+i+")").toggleClass("on");
            $("div#"+$(".tabNav li:eq("+i+") a").text()).show();
        }
        else
        {
            $(".tabNav li:eq("+i+")").toggleClass("on");
            $("div#"+$(".tabNav li:eq("+i+") a").text()).hide();   
        }
    }
    return false;
}