window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){arguments.callee=arguments.callee.caller;var a=[].slice.call(arguments);(typeof console.log==="object"?log.apply.call(console.log,console,a):console.log.apply(console,a))}};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());

/*
 * jQuery The Final Countdown plugin v1.0.0 beta
 * http://github.com/hilios/jquery.countdown
 */

(function($) {
  
  $.fn.countdown = function(toDate, callback) {
    var handlers = ['seconds', 'minutes', 'hours', 'days', 'weeks', 'daysLeft'];
    
    function delegate(scope, method) {
      return function() { return method.call(scope) }
    }
    
    return this.each(function() {
      // Convert
      if(!(toDate instanceof Date)) {
        if(String(toDate).match(/^[0-9]*$/)) {
          toDate = new Date(toDate);
        } else if( toDate.match(/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{2,4})\s([0-9]{1,2})\:([0-9]{2})\:([0-9]{2})/) ||
            toDate.match(/([0-9]{2,4})\/([0-9]{1,2})\/([0-9]{1,2})\s([0-9]{1,2})\:([0-9]{2})\:([0-9]{2})/)
            ) {
          toDate = new Date(toDate);
        } else if(toDate.match(/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{2,4})/) || 
                  toDate.match(/([0-9]{2,4})\/([0-9]{1,2})\/([0-9]{1,2})/)
                  ) {
          toDate = new Date(toDate)
        } else {
          throw new Error("Doesn't seen to be a valid date object or string")
        }
      }
      
      var $this = $(this),
          values = {},
          lasting = {},
          interval = $this.data('countdownInterval'),
          currentDate = new Date(),
          secondsLeft = Math.floor((toDate.valueOf() - currentDate.valueOf()) / 1000);
      
      function triggerEvents() {
        secondsLeft--;
        if(secondsLeft < 0) {
          secondsLeft = 0;
        }
        lasting = {
          seconds : secondsLeft % 60,
          minutes : Math.floor(secondsLeft / 60) % 60,
          hours   : Math.floor(secondsLeft / 60 / 60) % 24,
          days    : Math.floor(secondsLeft / 60 / 60 / 24) % 7,
          weeks   : Math.floor(secondsLeft / 60 / 60 / 24 / 7),
          daysLeft: Math.floor(secondsLeft / 60 / 60 / 24)
        }
        for(var i=0; i<handlers.length; i++) {
          var eventName = handlers[i];
          if(values[eventName] != lasting[eventName]) {
            values[eventName] = lasting[eventName];
            dispatchEvent(eventName);
          }
        }
        if(secondsLeft == 0) { 
          stop();
          dispatchEvent('finished');
        }
      }
      triggerEvents();
      
      function dispatchEvent(eventName) {
        var event = $.Event(eventName);
        event.date  = new Date(new Date().valueOf() + secondsLeft);
        event.value = values[eventName] || "0";
        event.toDate = toDate;
        event.lasting = lasting;
        switch(eventName) {
          case "seconds":
          case "minutes":
          case "hours":
            event.value = event.value < 10 ? '0'+event.value.toString() : event.value.toString();
            break;
          default:
            if(event.value) {
              event.value = event.value.toString();
            }
            break;
        }
        callback.call($this, event);
      }
      
      $this.bind('remove', function() {
        stop(); // If the selector is removed clear the interval for memory sake!
        dispatchEvent('removed');
      });
      
      function stop() {
        clearInterval(interval);
      }

      function start() {
        $this.data('countdownInterval', setInterval(delegate($this, triggerEvents), 1000));
        interval = $this.data('countdownInterval');
      }
      
      if(interval) stop();
      start();
    });
  }
  // Wrap the remove method to trigger an event when called
  var removeEvent = new $.Event('remove'),
      removeFunction = $.fn.remove;
  $.fn.remove = function() {
    $(this).trigger(removeEvent);
    removeFunction.apply(this, arguments);
  }
})(jQuery);


/*
 * jQuery ctRotator Plugin
 * http://thecodecentral.com/2011/08/15/ctnotify-a-flexible-multi-instance-jquery-notification-script
 */
 
 
(function($) {



  var defaultInstanceId = 'default';
  var defaultType = 'message';
  var instData = {};
  var loopPreventer = 0;


  
  $.extend({
    ctNotifyOption:function(options, instId){
      createInstnace(options, instId);
     
    },
    ctNotify:function(html, type, instId){
      var inst = getInstance(instId);
      addItem(html, type, inst.id);

      if(!inst.inTimeout){
	    removeItem(inst.id);
      }
    }
  });

  function getInstanceIdFallback(instId){
    if(instId == null){
      return defaultInstanceId;
    }else{
      return instId;
    }
  }

  function getInstance(instId){
    instId = getInstanceIdFallback(instId);

    var inst;
    if(instData[instId] != null){
      inst = instData[instId];
    }else{
      inst = createInstnace(null, instId);
   
    }
  
 
    return inst;
  }

  function createInstnace(options, instId){
    instId = getInstanceIdFallback(instId);
    var inst = initialize(options, instId);
    return inst;
  }


  function getOptions(instId){
    return getInstance(instId).options;
  }
  

  function initialize(options, instId){
    var inst;

    if(instData[instId] && instData[instId].isInitialized){
      inst = instData[instId];
    }else{
      inst = {
        id: instId,
        con:null,
        parentCon: null,
        inTimeout: false,
        isInitialized: false,
        timerId: null,
        stickyItemCount: 0        
      };
    
    }
    


    var opts = {
      delay: 3000,
      id: 'ctNotify_' + instId,
      className: 'ctNotify',
      animated: true,
      animateSpeed: 500,
      animateType: "slideUp",
      appendTo: null,
      sticky: false,
      autoWidth: 'fitWindow', //fit,fitWindow, disabled
      width: null, //if autoWidth is set to other than disabled, this option is not used
      opacity: .7,
      position: "fixed",
      align: null, //horizontal align based on calculation
      bodyIdSuffix: '_body_', //the element ID which contains the notificationc children
      bodyClassName: 'ctNotify_body',
      anchors: {
        top:0,
        left: 0,
        bottom: null,
        right: null
      }, //top, left, bottom, right
      containerRender: null,
      itemRender: null,
      onHide: $.noop
    };
    
    options = $.extend({}, opts, options);


    options.bodyId = opts.id + opts.bodyIdSuffix;

    
    if(options.appendTo == null){
      options.appendTo = $(document.body);
    }
    
    if(options.autoWidth != 'fit' && options.autoWidth != 'fitWindow'){
      options.autoWidth = 'disabled';
    }
    
    
    if(options.width != null){
      options.autoWidth = 'disabled';
    }
    



    inst.options = options;
    
    
 
    initContainer(inst);
    initItemRender(inst);
 
    inst.con = inst.options.containerRender(inst);
    inst.con.hide();
    inst.body = inst.con.find('#' + inst.options.bodyId);
    inst.parentCon = inst.options.appendTo;


   
    

    inst.con.bind('click', inst, function(e){
      //console.log('click', e.data.id, e.data.timerId, e.data.inTimeout);
     
   
      if(e.data.id == undefined){
        return; 
      }
      
     
      
      if(e.data.inTimeout){
        if(e.data.timerId != null){
        clearTimeout(e.data.timerId);
        }
        e.data.inTimeout = false;
      }

      e.data.body.empty();
      hide(e.data);
      e.data.stickyItemCount = 0;
       
    });


    if(inst.parentCon.size() == 0){
      throw ('Parent container ' + opt.appendTo + ' no found.');
    }

    inst.con.appendTo(inst.parentCon);



    if(inst.options.autoWidth != 'disabled'){
      $(window).resize(function(){
        fixWidth(inst); 
      });
    }

    

    inst.isInitialized = true;
    instData[instId] = inst;

//console.log(inst.id, inst.options.sticky);
 
    return inst;
    
  }
  
  
  function testIfAbNormalPosition(position){
    
    return position == 'absolute' || position == 'fixed' || position == 'relative';
  }
 
  function doAlign(inst){
    
    if(inst.options.align == null || !inst.con.is(":visible")){    
      return;  
    }
    
    if(inst.options.align == 'center'){
      if(testIfAbNormalPosition(inst.options.position)){
        inst.con.css({
          left: '50%',
          marginLeft: '-' + (inst.con.width() / 2) + 'px'
        });
      }else{
        inst.con.css({
          marginLeft: 'auto',
          marginRight: 'auto'
        });
      }
    } else if(inst.options.align == 'left'){
      if(testIfAbNormalPosition(inst.options.position)){
        inst.con.css({
          left: '0',
          right: 'auto'
        });
      }else{
        inst.con.css({
          marginRight: 'auto',
          marginLeft: '0'
        });
      }
    }else if(inst.options.align == 'right'){
      if(testIfAbNormalPosition(inst.options.position)){
        inst.con.css({
          right: '0',
          left: 'auto'
        });
      }else{
        inst.con.css({
          marginLeft: 'auto',
          marginRight: '0'
        });
      }
    }
  }
  
  function initContainer(inst){
    if(inst.options.containerRender != null){
      return;
    }
      
    inst.options.containerRender = function(inst){
      var options = inst.options;
      var conWrapper = $('<div></div>').attr({
        id:  options.id,
        title: 'click to close'
      })
      .css({
        opacity: options.opacity,
        position: options.position,
        top: options.anchors.top,
        bottom: options.anchors.bottom,
        left: options.anchors.left,
        right: options.anchors.right
      })
      .addClass(options.className)
      .hide();


      var con = $('<ul></ul>').attr({
        id: options.id + options.bodyIdSuffix
      })
      .addClass(options.bodyClassName);
      

      

      conWrapper.append(con);

      return conWrapper;
    };
    

  }
  
  
  function hide(inst){
    var con = inst.con;
    con.hide();
    inst.options.onHide(inst);
  }
  
  
  function initItemRender(inst){
    if(inst.options.itemRender != null){
      return;
    }
      
    inst.options.itemRender = function(html, itemOptions, inst){
      var   span = $('<span></span>') ;
      if(itemOptions.isSticky){
        span.addClass('sticky');
      }
      span.html(html);
      return $('<li></li>').append(span);
    };
  }
    
    
  function addItem(html, type, instId){
    var inst = getInstance(instId);
    
    
    
    var options;
    if($.isPlainObject(type)){
      options = type;
    }else{
      options = {};
      options.type = type;
    }
    
    options = $.extend({
      type: defaultType,
      isSticky: inst.options.sticky,
      delay: inst.options.delay
    }, options);
    
   
    inst.con.show();
   
    var item = inst.options.itemRender(html, options, inst);
    item.addClass(options.type);
    inst.body.append(item);

    $(item).data('ct_delay', options.delay);
    
    if(options.isSticky){
      inst.stickyItemCount++;
      $(item).data('ct_isSticky', true);
    }

      
    fixWidth(inst);
    doAlign(inst);  
   
  }

  function fixWidth(inst){
    var con = inst.con;
    
   
    if(inst.options.autoWidth == 'disabled'){
      
      if(inst.options.width != null){
        inst.con.width(inst.options.width);
      }
    }else if(inst.options.autoWidth == 'fit'){
      con.width(inst.options.appendTo.width() - (con.outerWidth() -  con.width()));
      

    }else if(inst.options.autoWidth == 'fitWindow'){
      con.width($(window).width() - (con.outerWidth() - con.width()));
    }
    
  }



  function removeItem(instId){
    if(instId == undefined){
      return;
    }
    var inst = getInstance(instId);
    var con = inst.con;
    var body = inst.body;
    var opt = inst.options;
    
    if(con == null){
      return;
    }

    var size = Math.max(body.children().size() - inst.stickyItemCount, 0);
    //console.log('removedItem: tota=', body.children().size() + ', sticky=' + inst.stickyItemCount + ', inst.id = ' + inst.id);
   
    
    if(size == 0){
      inst.inTimeout = false;
      inst.timerId = null;
      if(body.children().size() == 0){
        hide(inst);
      }else{
          
      }
      
      return;
    }else if(size > 0){
      inst.inTimeout = true;
      getInstance(instId).inTimeout = true;


      var firstRemovable = getRemovableItem(instId);
        
      if(firstRemovable != null){
        inst.timerId = setTimeout(function(){
          var savedInst = inst;
         
		 if(opt.animated){
            firstRemovable[opt.animateType](opt.animateSpeed, function(){
              doRemoveItem( inst.id, firstRemovable);
            });
          }else{
            doRemoveItem( inst.id, firstRemovable);
          }
        

        }, firstRemovable.data('ct_delay'));
      }
    }
  }
  

  function getRemovableItem(instId){
    
    //console.log('getRemovableItem', instId);
    var inst = getInstance(instId);
    var children = inst.body.children();
    
    for(var i=0; i< children.size(); i++){
      if( $(children[i]).data('ct_isSticky') != true){
        return $(children[i]);
      }
    }
    
    return null;
  
  }

  function doRemoveItem(instId, item){
    //console.log('doRemoveId called');
    item.remove();
    removeItem(instId);
  }
 
})(jQuery); 

/*
 * jmNotify
 * http://www.moretech.it/demo/plugins/jmNotify
 */

(function($){

  // declare plugin name
  $.fn.jmNotify = function( options ) {
  
  		// declare default options
        var defaults = {
			
			/** options **/
			'methodIn'  	: 'fadeIn',
			'methodOut' 	: 'fadeOut',
			'speedIn'   	: 'normal',
			'speedOut'  	: 'normal',
			'delay'	    	: 3000,
			'html'      	: '',
			'closeButton'	: 'jm-close',
			'closeText'		: '',
			
			/** methods **/	
			'onStart'    	: '',
			'onComplete' 	: ''
		}
		
		options = $.extend(defaults, options);
		
		var $this;

		 // prevent more clicks when single notify is open
		 preventClicks = function()
		 {
			 $this.is(':visible') ? valid = false : valid = true;
			 return valid;
		 }
		 
		 
		 // close Notify
		 closeNotify = function()
		 {
			 if( $this.find('.'+options.closeButton).length == 0)
			 $this.append('<a href="#" class="'+options.closeButton+'">'+options.closeText+'</a>');
			 
			 
			 $('.'+options.closeButton).bind("click", function(){
				$this.hide();
				return false;
			 });
		 }
		
		 
		 // callback onStart
		 onStart = function()
		 {
			if(options.onStart)
			options.onStart();
		 }
		
		 // callback onComplete			 
		 onComplete = function()
		 {
			if(options.onComplete)
			options.onComplete();
		 }
		
		
		 // set new html
		 setHtml = function()
		 {
			 if(options.html)
			 {
				$this.html(options.html); 
			 }
		 }
		
		 // hide notify			 
		 hideNotify = function()
		 {
			// switch methodOut
			 switch (options.methodOut)
			 {
				case 'fadeOut':
					$this.delay(options.delay).fadeOut(options.speedOut, function(){ onComplete(); });
				break;
		
				case 'slideUp':
					$this.delay(options.delay).slideUp(options.speedOut, function(){ onComplete(); });
				break;

				default:
					$this.delay(options.delay).toggle(1, function(){ onComplete(); });
				break;
				
			 }
		 }
		 
		 // show notify
		 showNotify = function()
		 {
			 // switch methodIn
			 switch (options.methodIn)
			 {
				case 'fadeIn':
					$this.fadeIn( options.speedIn, function(){ hideNotify()} );
				break;

				case 'slideDown':
					$this.slideDown( options.speedIn, function(){ hideNotify()} );
				break;

				default:
					$this.toggle(1, function(){ hideNotify();});
				break;
			 }
		 }
		 
		 // init plugin
		 init = function()
		 {
			 if(preventClicks())
			 {
				 closeNotify();
				 onStart();
				 setHtml();
				 showNotify();
			 }
		 }
		 
	
		
		// cycling all elements
		return this.each(function(){
			 $this = $(this);
			 init();
		});

  };
})(jQuery);

