ua = navigator.userAgent;
clickevent = (ua.match(/iPhone/i) || ua.match(/iPad/i)) ? "touchstart" : "click";	
var Banner = {};

Banner = function() {  
  // init 
}

Banner.prototype = {
  
  
  
  //
  //  these are default settings, allows banner to work on hotel pages automatically
  //
  width:600, // default width
  height:179, // default height
  animType:'fade', // type of animation: crossfade, cover, uncover,scroll
  circular:true, // looping mechanism type, leave to true
  elemName:'headerBanner', // create an element container using this id
  pauseDuration:4000, // amount of time before cycling
  animDuration:500,
  customSettings:null,
  //
  // end of defaults
  //
  
  _arrBannersHTML:new Array(), // private, do not modify
  // this should be called first, sets up the above options.  Useful on homepage
  setup:function(elemName, width, height, animType, pauseDuration, animDuration ) {
     this.width = width;
     this.height = height;
     this.animType = animType;
     this.elemName = elemName;
     this.pauseDuration = pauseDuration;
     this.animDuration = animDuration;
  },
  
  
  // if you want to set your own settings you can do it here
  // like this:
  // objBanner.setCustomSettings({
  //   effect:'random',
  //   slices:8,
  //   boxRows:4,
  //   pauseOnHover:true
  // etc
  // });
  setCustomSettings:function(elemName, width, height, myOwnSettings) {
    this.elemName = elemName;
    this.width = width;
    this.height = height;
    this.customSettings = myOwnSettings; 
  },
  
  // add images to the queue, takes in image path, and URL to click to.  If URL is empty then doesn't wrap with link tag
  addImage:function(img, url) {
    var timg = new Image(this.width, this.height);
    timg.src = img;
    
    if(url == '') {
     this._arrBannersHTML.push('<img src="' + img + '" width="' + this.width + '" height="' + this.height + '"/>');
    } else {
     this._arrBannersHTML.push('<a href="' + url + '"><img  border="0" src="' + img + '" width="' + this.width + '" height="' + this.height + '"/></a>');
    }
  },
  
  // regular linear display, called last
  display:function() {
    var str = '';
    var self = this;
    
    this._arrBannersHTML.each(function(item) {
       str +=  item;
    });    
    
    document.write('<div class="nivoSlider" id="' + this.elemName + '">' + str + '</div>');
        
    $j(window).load(function() {
        self.start();     
    });   
  },
  
  // random display, use instead of display().
  // basically how this works is takes the images you give it and randomizes the set.
  displayRandom:function() {
    // randomize array
    var self = this;
    var str = '';
        
    this._arrBannersHTML.sort(function() {return 0.5 - Math.random()});
    
    this._arrBannersHTML.each(function(item) {
       str +=  item;
    });    
    
    document.write('<div class="nivoSlider" id="' + this.elemName + '">' + str + '</div>');
    
    $j(window).load(function() {
        self.start();     
    });
    
  },
  
  
  
  
  
  // private, do not touch
  start:function() {
    var self = this;
    var carousel = $j('#' + self.elemName);
    
    
    var minSettings = {
      effect: self.animType,
      directionNav:true,
      controlNav:false,
      pauseTime:5000,
      prevText:'',
      nextText:'',
      slices: 15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed: 500 // Slide transition speed
    };
    
    
    
    if(this.customSettings != null) {
      carousel.nivoSlider(self.customSettings); 
    } else {
      carousel.nivoSlider(minSettings);    
    }
    
    
    carousel.touchwipe({
        wipeLeft: function() {
          //carousel.trigger("next");
          $j(".nivo-directionNav .nivo-nextNav").click()
         //alert('hellooooo????');

        },
        wipeRight: function() {
          //carousel.trigger("prev");
          $j(".nivo-directionNav .nivo-prevNav").click()
          //alert('hellooooo????');
        }
    });
    
   
    
  }
  

  
};

