
var mid,
    /*news_EN = "THE 2010 EDITION OF THE CASTELL'ARQUATO-VERNASCA \"SILVER FLAG\" HILLCLIMB WILL HAVE ABARTH AS THE FEATURED MARQUE. DATE: 11-12-13 JUNE.  *  OUR FIRST \"ABARTH TRACK DAY\" ORGANIZED BY BERNI MOTORI AND FRANZONI AUTO WILL BE HELD AT THE FRANCIACORTA CIRCUIT NEAR BRESCIA ON THURSDAY 17TH JUNE 2010.  *  KEEP A CHECK ON \"EVENTS\" TO BE UP-DATED ON THESE MEETINGS.",
    news_IT = "L'EDIZIONE 2010 DELLA CASTELL'ARQUATO \"SILVER FLAG\" AVRA' L'ABARTH COME MARCA IN EVIDENZA. DATA: 11-12-13 GIUGNO.  *  IL 17 DI GIUGNO 2010 VEDRA' LA PRIMA \"ABARTH TRACK DAY\" ORGANIZZATA DALLA BERNI MOTORI E LA FRANZONI AUTO SULLA PISTA DI FRANCIACORTA VICINO A BRESCIA.  *  GUARDATE \"EVENTI\" PER ESSERE AGGIORNATI SU QUESTE MANIFESTAZIONI.",
    news_FR = "L'EDITION 2010 DE LA COURSE DE COTE CASTELL'ARQUATO-VERNASCA \"SILVER FLAG\" METTRA A L'HONNEUR LA MARQUE ABARTH. DATE: 11-12-13 JUIN.  *  LE 17 DE JUIN 2010 A ETE CHOISI POUR LA PREMIERE EDITION \"ABARTH TRACK DAY\" ORGANISEE PAR BERNI MOTORI ET FRANZONI AUTO SU CIRCUIT DE FRANCIACORTA PRES DE BRESCIA.  *  REGARDEZ \"EVENTI\" POUR ETRE ULTERIEUREMENT INFORMES SUR CES EVENEMENTS.",
    news_D = "ZENTRALES THEMA BEIM CASTELL'ARQUATO \"SILVER FLAG\" BERGLAUF 2010 WIRD DIE MARKE ABARTH SEIN.  *  DAI 17 JUNE 2010 WIRD UNSER 1.ABARTH TRACK DAY ORGANISIERT VON BERNI MOTORI UND FRANZONI AUTO, AUF DER RENNSTRECKE FRANCIACORTA IN DER NAEHE VON BRESCIA STATTFINDEN  *  BITTE BEOBACHTEN SIE UNSERE UNTERGRUPPE \"EVENTS\" FUR WEITERE INFORMATIONEN.",*/
    newsIdx = 0,
    newsShow = [];

// Get Url Parameter
// Return the value of the passed in url parameter name. If the parameter doesn't exist then return an empty string
function gup(name) {
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}


var MultipleImgDisp = function() {
  var self = this;
  
  $("#prev").click(function() {self.prev();});
  $("#next").click(function() {self.next();});
};
MultipleImgDisp.prototype = {
  setDetails: function(ele, imgs) {
    var self = this;
    
    this.ele = ele;
    this.imgs = [];
    $.each(imgs,  function(i, v) {
                    var aImg = new Image();
                    aImg.src = this;
                    self.imgs.push(aImg);
                  });
    this.title = ele.attr("title");
    this.curImg = 0;
    this.maxNum = imgs.length;
    
    $("#dwinTitle").html(this.title);
    $("#dwinImg").attr({src: this.imgs[0].src});
    
    if (imgs.length > 1) {
      $("#imgCur").html("1");
      $("#imgMax").html(this.maxNum);
      $("#multipleImgs").show();
    }
    else {
      $("#multipleImgs").hide();
    }
  },
  
  prev: function() {
    this.curImg -= 1;
    if (this.curImg < 0) {
      this.curImg = this.maxNum - 1;
    }
    this.dispImg();
  },
  
  next: function() {
    this.curImg += 1;
    if (this.curImg >= this.maxNum) {
      this.curImg = 0;
    }
    this.dispImg();
  },
  
  dispImg: function() {
    var img = this.imgs[this.curImg].src,
        self = this;
        
    $("#dwinImg").fadeOut(function() {
                            $("#imgCur").html(self.curImg + 1);
                            $(this).attr({src: img});
                            $(this).fadeIn();
                          });
  },
  
  onClose: function() {
    $("#dwinImg").attr({src: ""});
  }
};


// ****************************************************
// NEWS Function START
// ****************************************************
/*function newsReset() {
  $("#newsContent") .html(newsShow[newsIdx])
                    .css({right: -3300});
  newsIdx += 1;
  if (newsIdx >= newsShow.length) {
    newsIdx = 0;
  }
}

function newsAnimate() {
  
  $("#newsContent").animate({right: 1200}, 50000, "linear", function() {newsReset(); newsAnimate();});
}*/
// ****************************************************
// NEWS Function END
// ****************************************************





$(function() {
  
  mid = new MultipleImgDisp();
  
  // Convert thickbox type images into DOMwindow images
  /*$(".thickbox").each(function(i, v) {
                        var href = $(this).attr("href");
                        $(this).attr({img: href,
                                      href: "#dwin"});
                      });*/
                      
  $(".singleimg, .singleimg1000").mousedown(function() {
                                        mid.setDetails($(this), [$(this).attr("img")]);
                                      });
                      
  // Open the template when the user clicks
  $(".singleimg, .multipleimgs").openDOMWindow({ 
    eventType:'click', 
    loader:1, 
    loaderImagePath:'/images/loadingAnimation.gif', 
    loaderHeight:13, 
    loaderWidth:208,
    width:850,
    height:920,
    fixedWindowY: 10
    
    }); 

  // Open the template when the user clicks
  $(".singleimg1000").openDOMWindow({ 
    eventType:'click', 
    loader:1, 
    loaderImagePath:'/images/loadingAnimation.gif', 
    loaderHeight:13, 
    loaderWidth:208,
    width:1050,
    height:920,
    fixedWindowY: 10
    
    }); 
    
  // Attach the close event
  $('.closeDOMWindow').closeDOMWindow({eventType:'click',
                                        functionCallOnClose: mid.onClose,
                                        functionCallAfterClose: mid.onClose
                                      });

  // ================
  // NEWS TICKER TAPE
  // ================
  // Set up news languages order
  /*if (G_LANG === G_LANG_EN) {
    newsShow = [news_EN, news_IT, news_FR, news_D];
  }
  else {
    newsShow = [news_IT, news_EN, news_FR, news_D];
  }
  newsReset();
  newsAnimate();*/

});
