function cl(obj) {
   console.log(obj);
}


jQuery(document).ready(function() {
   
var slickSelect = Klass.extend({
   init: function(options) {
      this.options = options;
      this.externalEvents = false;
      this.is_down = this.is_down || false;
   },
   
   activate: function() {
      if(this.externalEvents == true) this.do_additional_events();
      this.verify_triggers(this.options.triggers);
   },
   
   verify_triggers: function(triggers) {
      var totalTriggers = triggers.length;
      var _self = this;
      
      for (var i=0; i < totalTriggers; i++) {
         $(triggers[i]).click(function(evt) {
            evt.stopPropagation();
            _self.handle_dropdown();
         })
      }
   },
   
   handle_dropdown: function() {
      var _self = this;
      
      // IE6 workaround
      var menuParent = this.options.dropDown[0].parentNode;
      
      if (this.is_down == true) {
         this.options.dropDown.css({
            'display': 'none'
         });
         $(menuParent).css({
            'position': 'static'// IE6 workaround
         });
         this.is_down = false;
      } else {
         this.options.dropDown.css({
            'display': 'block'
         });
         $(menuParent).css({
            'position': 'relative'// IE6 workaround
         });
         this.is_down = true;
      }
      
      $(this.options.innerAnchors).click(function(evt) {
         evt.preventDefault();
         
         _self.options.dropDown.css({
            'display': 'none'
         });
         $(menuParent).css({
            'position': 'static',// IE6 workaround
            'z-index:': '9999'
         });
         _self.is_down = false;
         
         $(_self.options.inputLabel).html($(this).html());
         
         
         /*$('#country_sel_f').attr('value', 'as');*/
         //$('#cctype_sel_f').attr('value', $(this).attr('id'));
         //$('#exp_month').attr('value', $(this).attr('id'));
         //$('#exp_year').attr('value', $(this).attr('id'));
      });
   },
   
   do_additional_events: function() {
      var _self = this;
       var menuParent = $(this.options.dropDown[0]).parent();
      
      // for ie6
      $(document).click(function() {
         if (_self.is_down == true) {
            _self.options.dropDown.css({
               'display': 'none'
            });
            $(menuParent).css({
               'position': 'static',// IE6 workaround
               'z-index:': '9999'
            });
         }
         _self.is_down = false;
      });
   }
})




//var slickSelect = function(options) {
//   this.options = options;
//   this.externalEvents = false;
//   this.is_down = this.is_down || false;
//}
//
//slickSelect.prototype = {
//   activate: function() {
//      if(this.externalEvents == true) this.do_additional_events();
//      this.verify_triggers(this.options.triggers);
//   },
//   
//   verify_triggers: function(triggers) {
//      var totalTriggers = triggers.length;
//      var _self = this;
//      
//      for (var i=0; i < totalTriggers; i++) {
//         $(triggers[i]).click(function(evt) {
//            evt.stopPropagation();
//            _self.handle_dropdown();
//         })
//      }
//   },
//   
//   handle_dropdown: function() {
//      var _self = this;
//      
//      // IE6 workaround
//      var menuParent = this.options.dropDown[0].parentNode;
//      
//      if (this.is_down == true) {
//         this.options.dropDown.css({
//            'display': 'none'
//         });
//         $(menuParent).css({
//            'position': 'static'// IE6 workaround
//         });
//         this.is_down = false;
//      } else {
//         this.options.dropDown.css({
//            'display': 'block'
//         });
//         $(menuParent).css({
//            'position': 'relative'// IE6 workaround
//         });
//         this.is_down = true;
//      }
//      
//      $(this.options.innerAnchors).click(function(evt) {
//         evt.preventDefault();
//         
//         _self.options.dropDown.css({
//            'display': 'none'
//         });
//         $(menuParent).css({
//            'position': 'static'// IE6 workaround
//         });
//         _self.is_down = false;
//         
//         $(_self.options.inputLabel).html($(this).html());
//      });
//   },
//   
//   do_additional_events: function() {
//      var _self = this;
//       var menuParent = this.options.dropDown[0].parentNode;
//      
//      // for ie6
//      $(document).click(function() {
//         if (_self.is_down == true) {
//            _self.options.dropDown.css({
//               'display': 'none'
//            });
//            $(menuParent).css({
//               'position': 'static'// IE6 workaround
//            });
//         }
//         _self.is_down = false;
//      });
//   }
//}






var creditcardSelect = new slickSelect({
   dropDown: $('#creditcard_select'),
   triggers: $('.s_creditcard'),
   innerAnchors: $('#creditcard_select ul li a'),
   inputLabel: $('label.s_creditcard')
})
creditcardSelect.externalEvents = true;
creditcardSelect.activate();


var monthSelect = new slickSelect({
   dropDown: $('#month_select'),
   triggers: $('.s_month'),
   innerAnchors: $('#month_select ul li a'),
   inputLabel: $('label.s_month')
})
monthSelect.externalEvents = true;
monthSelect.activate();
   

var yearSelect = new slickSelect({
   dropDown: $('#year_select'),
   triggers: $('.s_year'),
   innerAnchors: $('#year_select ul li a'),
   inputLabel: $('label.s_year')
})
yearSelect.externalEvents = true;
yearSelect.activate();


var countrySelect = new slickSelect({
   dropDown: $('#country_select'),
   triggers: $('.s_country'),
   innerAnchors: $('#country_select ul li a'),
   inputLabel: $('label.s_country')
})
countrySelect.externalEvents = true;
countrySelect.activate();
   
   
});

