(function($){
	var popAction = function(_obj){
		var pop_bg = $('#pop_bg'),
			pop_block = $('#pop_block'),
			pop_inner = $('#pop_inner');
		var popClear = function(item){
			pop_inner.html('')
			pop_block.hide();
			pop_bg.hide();
		}
		if(_obj.item){
			$(pop_inner).html($(_obj.item).html());
		}
		if(_obj.node){
			$(pop_block).find(_obj.node).hide();
			$(pop_block).find(_obj.node).eq(_obj.nodeindex).show();
			$(pop_block).find(_obj.node).each(function(ind,node){
				$(node).find('.next').click(function(){
					$(node).hide();
					$(node).next(_obj.node).show();
					if(ind>=$(pop_block).find(_obj.node).length-1){
						$(pop_block).find(_obj.node).eq(0).show();
					}
				})
			})
		}
		$(pop_block).show();
		var pop_width = $(_obj.item).outerWidth();
		var pop_height = $(_obj.item).outerHeight();
		if(_obj && _obj.height){
			var pop_height = _obj.height;
		}
		var body_width = $('body').width();
		var body_height = $('body').height();
		var window_width =  $(window).width();
		var window_height =  $(window).height();
		var top_scroll = $(window).scrollTop();
		var pop_top = top_scroll + (window_height - pop_height)/2;
		if(pop_top<top_scroll){
			pop_top = top_scroll;
		}
		if(window_height>body_height){
			body_height = window_height;
		}
		var pop_bg_height = body_height;
		if( pop_top +pop_height > pop_bg_height){
			pop_bg_height = pop_top +pop_height;
		}
		$(pop_block).css({top:pop_top,width:pop_width,height:pop_height,left:(body_width - pop_width)/2});
		$(pop_bg).css({width:body_width,height:pop_bg_height}).show();
		
		$(pop_block).find('#pop_close_btn').click(function(){
			popClear()
		})
		$(pop_bg).click(function(){
			popClear()
		})
	}

	  $(document).ready(function() {

    var url = 'http://el-lady.com.cn/nj/message/status?jsoncallback=?&messageType=visitsite';
    visitMessageCount(1);

    $('a.c-msg-l').click(function() {
      sp = $(this).attr('name');
      visitMessageCount(sp);
      return false;
    });

    function visitMessageCount(sp) {
      var step = 0;
      _url = url + '&step=' + sp;
      $.getJSON(_url, function(data) {
        var obj = $.parseJSON(data);//console.log(obj.status);
        sp = parseInt(sp);
        if (obj.status == 'closed') {
          return false;
        }
        _sp = parseInt(obj.status);
        if (_sp >= sp) {
          step = _sp;
        }
        else {
          step = sp;
        }
        showVisitMessage(step);
      });
    }

    function showVisitMessage(step) {
      if (step == 0) {
        popAction({'item':'#flv'});
      }else {
        $('div.c-msg').css('display', 'none');
        $('#c-msg-' + (step + 1)).css('display', 'block');
      }
      //add ga code
      if (step == 1) {
        _gaq.push(['_trackEvent', 'newVersion', 'Yes']);
      }
      else if (step == 2) {
        _gaq.push(['_trackEvent', 'newVersion', 'Know-weibo']);
      }
      else if (step == 3) {
        _gaq.push(['_trackEvent', 'newVersion', 'Know-yafenreyi']);
      }
      else if (step == 4) {
        _gaq.push(['_trackEvent', 'newVersion', 'Know-chaoliuqianxian']);
      }
      else if (step == 5) {
        _gaq.push(['_trackEvent', 'newVersion', 'Know-darenxinde']);
      }
      else if (step == 6) {
        _gaq.push(['_trackEvent', 'newVersion', 'Know-shiyongzhongxin']);
      }
      else if (step == 100) {
        _gaq.push(['_trackEvent', 'newVersion', 'No']);
      }
    }
  });

})(jQuery)

