function init() {}
var Body = null;
var IsTouch = isTouch();
var FirstLoad = true;


//  Setup

var WinW = null;
var WinH = null;
var ImgW = 1160;
var ImgH = 768;
//
var StaH = 700;
var PadTop = 120;
var MinW = 800;
var MinH=600;

var Setup = {
  init: function() {
    var cc = this;

    Content.init();

    cc.render();
    if(!IsTouch) {
      $(window).resize(function(){
        cc.render();
      });
    }
  },
  render: function() {
    var cc = this;

    if($(window).width()!=WinW||$(window).height()!=WinH) {

      //WinW = $('#Container').width();
      //WinH = $('#Container').height();
      WinW = document.documentElement.clientWidth;
      WinH = document.documentElement.clientHeight;
      Content.render();
    }
  }
};

var Content = {
  Container: null,
  Wpr: null,
  ULH:null,
  init: function() {
    var cc = this;
    cc.Container = $('#example');
    cc.Wpr = cc.Container.find('.wpr');

    cc.ULH = cc.Container.find('.pageBg img');
    cc.ODIV = cc.Container.find('.pageBg .overflowDiv');
    cc.SDIV = cc.Container.find('.showContent');
  },
  render: function() {
    var cc = this;
    //min width and height
    if(WinH < MinH) WinH = MinH;
    if(WinW < MinW) WinW = MinW;
    //
    if(cc.ODIV.height() > WinH)
    {
      WinH = WinH + 20;
    }
    if(WinW > ImgW || WinH > ImgH)
    {
      if ((WinW / WinH) > (ImgW / ImgH)) {
        var newHeight = Math.round((WinW / ImgW) * ImgH);
        var newWidth = WinW;
      } else {
        var newHeight = WinH;
        var newWidth = (WinH / ImgH) * ImgW;
      }
    }
    else
    {
      var newWidth = 1160;
      var newHeight = 768;
    }
    
    newTop = 0 - Math.round((newHeight - WinH) / 2);
    newLeft =  0 - Math.round((newWidth - WinW) / 2);
    if(( WinH / StaH ) < 1)
    {
      var newPadTop = Math.round(PadTop * (WinH / StaH));
    }
    else
    {
      var newPadTop = PadTop
    }
    
    var _currentSlide = _slider.getCurrentSlide();
    _slider.children().width(WinW);  
    var _totalW = 0;
    $.each(_slider.children(),function(index){
      if(index<_currentSlide &&$.trim($(this).html()).length != 0)
      _totalW+=$(this).width();
    });
    if(Sys.ie == '7.0'){
      _totalW = _currentSlide * WinW;
    }
    //in people page
    if(cc.Container.find('.peopleIntro').length > 0)
    {
       if(Sys.ie == '7.0')  WinH = WinH  - 1;
      cc.Container.find('.peopleIntro').css({height: WinH});
      
      if(_slider.children().eq(_currentSlide).find(".showContent").length > 0)
      {
        cc.SDIV.css({height: WinH});
        cc.SDIV.parent('div').css({height: WinH * 2});
        _slider.css({left:0 -  _totalW,height: WinH * 2});
      }
      else
      {
        var tempH = _slider.height();
       
        cc.Container.find('.peopleIntro').parent('div').css({height: WinH});
        _slider.css({left:0 -  _totalW,height: WinH});
        
         if(tempH  > WinH)
          WinW = document.documentElement.clientWidth;
      }
      
      cc.Container.find('.pager').css({width: WinW});
      cc.Container.css({width: WinW});
      cc.Container.parent().css({width: WinW});
      
      return;
    }  
    
    var _imgCount = cc.Container.find('#slider1>li').eq(_currentSlide).find('.pageBg img').length;
    if(_imgCount == 0) 
    {
       _slider.css({left:0 -  _totalW});
       _slider.parent().width(WinW);
       _slider.parent().parent().width(WinW);
      return;
    }
    var wprHeight = WinH * _imgCount;
    var contentHeight = WinH - newPadTop;
      
    //cc.Container.css({height: WinH, width: WinW});
    cc.Wpr.css({width: newWidth, height: wprHeight});
    cc.ULH.css({width: newWidth, height: newHeight, top: newTop, left: newLeft});
    
      cc.ODIV.css({height: WinH, width: WinW,overflow:"hidden"});
    if(Sys.ie && Sys.ie != '8.0' && Sys.ie != '9.0'){
       cc.ULH .css({height:newHeight ,width: newWidth,top: newTop});
       $.each($(".pageBg"),function(){
         $(this).find('.overflowDiv').eq(0).css({height: WinH - newTop , width: WinW,overflow:"hidden",top: newTop});  
       });
      //_totalW = _currentSlide * WinW;
    }
    cc.SDIV.css({ height: contentHeight, "padding-top": newPadTop});
    $("#example").css({width: WinW});
    cc.SDIV.children(".middleContent").each(function(){
        marginLeft = $(this).width();
        $(this).css({"margin-left": - marginLeft / 2});  
    });
    cc.SDIV.parent('div').css({height: wprHeight});
   
    _slider.css({height: wprHeight,left:0 -  _totalW});
    var _lft = (_slider.css("left"));

     _slider.parent().width(WinW);
     _slider.parent().parent().width(WinW);
  }
};

function isTouch() {
   var el = document.createElement('div');
   el.setAttribute('ongesturestart', 'return;');
   if(typeof el.ongesturestart == "function"){
      return true;
   }else {
      return false
   }
};
function cOnAfterSlide(_currSlide, _length,_chl){
  if(Body ==null)
    Body = $(document.body);
  if(_slider!=null ){
    Setup.init(); 
    Content.render();}
}

