gPosition = 'center';

(function($) {
  $.fn.ContentSlider = function(options)
  {
    var defaults = {
      leftBtn : 'images/cs_leftImg.jpg',
      rightBtn : 'images/cs_rightImg.jpg',
      width : '900px',
      height : '400px',
      speed : 400,
      easing : 'easeOutQuad',
      textResize : false,
      IE_h2 : '26px',
      IE_p : '11px'
    }
    var defaultWidth = defaults.width;
    var o = $.extend(defaults, options);
    var w = parseInt(o.width);
    var n = this.children('.cs_wrapper').children('.cs_slider').children('.cs_article').length;
    var x = -1*w*n+w; // Minimum left value
    var p = parseInt(o.width)/parseInt(defaultWidth);
    var thisInstance = this.attr('id');
    var inuse = false; // Prevents colliding animations

    function moveSlider(d, b, m)
    {
      //var l = parseInt(b.siblings('.cs_wrapper').children('.cs_slider').css('left'));
      var l = parseInt($('#container').css('margin-left'));

      if(isNaN(l)) {
        var l = 0;
      }
      //var m = (d=='left') ? l-w : 0;

      //if(m<=0&&m>=x) {
      if(true) {
        $('#container')
              .animate({ 'left' : (m+'px') }, o.speed, o.easing, function() {
                inuse=false;
              });

        /*if(b.attr('class')=='cs_leftBtn') {
          var thisBtn = $('.cs_leftBtn');
          var otherBtn = $('.cs_rightBtn');
        } else {
          var thisBtn = $('.cs_rightBtn');
          var otherBtn = $('.cs_leftBtn');
        }
        if(m==0||m==x) {
          thisBtn.animate({ 'opacity':'0' }, o.speed, o.easing, function() { thisBtn.hide(); });
        }
        if(otherBtn.css('opacity')=='0') {
          otherBtn.show().animate({ 'opacity':'1' }, { duration:o.speed, easing:o.easing });
        }*/
      }
    }

    function vCenterBtns(b)
    {
      // Safari and IE don't seem to like the CSS used to vertically center
      // the buttons, so we'll force it with this function
      //var mid = parseInt(o.height)/2;
      /*b
        .find('.cs_leftBtn img').css({ 'top':mid+'px', 'padding':0 }).end()
        .find('.cs_rightBtn img').css({ 'top':mid+'px', 'padding':0 });*/
    }

    return this.each(function() {
      /*$(this)
        // Set the width and height of the div to the defined size
        .css({
          width:o.width,
          height:o.height
        })*/
        // Add the buttons to move left and right
        //.prepend('<a href="#" class="cs_leftBtn"><img src="'+o.leftBtn+'" /></a>')
        //.append('<a href="#" class="cs_rightBtn"><img src="'+o.rightBtn+'" /></a>')
        // Dig down to the article div elements
        //.find('.cs_article')
          // Set the width and height of the div to the defined size
          /*.css({
            width:o.width,
            height:o.height
          })*/
          //.end()
        // Animate the entrance of the buttons
        /*.find('.cs_leftBtn')
          .css('opacity','0')
          .hide()
          .end()
        .find('.cs_rightBtn')
          .hide()
          .animate({ 'width':'show' })*/

      // Resize the font to match the bounding box
      /*if(o.textResize===true) {
        var h2FontSize = $(this).find('h2').css('font-size');
        var pFontSize = $(this).find('p').css('font-size');
        $.each(jQuery.browser, function(i) {
          if($.browser.msie) {
             h2FontSize = o.IE_h2;
             pFontSize = o.IE_p;
          }
        });
        $(this).find('h2').css({ 'font-size' : parseFloat(h2FontSize)*p+'px', 'margin-left' : '66%' });
        $(this).find('p').css({ 'font-size' : parseFloat(pFontSize)*p+'px', 'margin-left' : '66%' });
        $(this).find('.readmore').css({ 'font-size' : parseFloat(pFontSize)*p+'px', 'margin-left' : '66%' });
      }*/

      // Store a copy of the button in a variable to pass to moveSlider()
      var leftBtn = $('.cs_leftBtn');
      leftBtn.bind('click', function() {
        if(inuse===false) {
          inuse = true;

          $('.titlemnu').css('margin-top', '0px');
          $('.flash').remove();
          $('.info').removeClass('titlenfo');
          $('#rightMenu ul').removeClass('titlemnu');
          $('#leftMenu ul').removeClass('titlemnu');

          $('#rightMenu').addClass('active');
		  $('#leftMenu').addClass('active');
          $('#leftContent').show('slow');

          $('#logo').addClass('small m');

          $('#popup').hide();
          $('#center').addClass('active');

          $('#rightMenu .info').addClass('info22');

          gPosition = 'left';

          moveSlider('right', leftBtn, 0);

          $('#rightContent').hide('slow');
          $('#menu').addClass('tmenu');

          if(gSelectFirst) {
			  $('#leftMenu li').removeClass('act');
			  $('#leftMenu li ul').hide();
			  $('#leftMenu .first-level:first').addClass('act');
			  $('#leftMenu .frst').addClass('act').parent().show();

			  showContent('left', gLang + '-catalog-view_cat.html?cid=2&ajax=true');
          }

		  $('.menuCategory').hide();
		  $('#oldlogo').hide();
		  //$('#leftMenu .frst a').click();
        }
        return false; // Keep the link from firing
      });

      // Store a copy of the button in a variable to pass to moveSlider()
      var rightBtn = $('.cs_rightBtn');
      rightBtn.bind('click', function() {
        if(inuse===false) {
          inuse=true;

          $('.titlemnu').css('margin-top', '0px');
          $('.info').removeClass('titlenfo');
          $('#leftMenu ul').removeClass('titlemnu');
          $('#rightMenu ul').removeClass('titlemnu');
          $('.flash').remove();

          $('#leftMenu').addClass('active');
          $('#rightMenu').addClass('active');
          $('#rightContent').show();

          $('#logo').removeClass('m').addClass('small v');

          $('#popup').hide();
          $('#center').addClass('active');

          $('#rightMenu .info').addClass('info22');

          gPosition = 'right';

          moveSlider('left', rightBtn, -300);

          $('#leftContent').hide('slow');
          $('#menu').addClass('tmenu');

          if(gSelectFirst) {
			  $('#rightMenu li').removeClass('act');
			  $('#rightMenu li ul').hide();
			  $('#rightMenu .first-level:first').addClass('act');
			  $('#rightMenu .frst').addClass('act').parent().show();

			  showContent('right', gLang + '-catalog-view_cat.html?cid=1&ajax=true');
          }

		  $('.menuCategory').show();
		  $('#oldlogo').hide();
		  //$('#rightMenu .frst a').click();
        }
        return false; // Keep the link from firing
      });

      //vCenterBtns($(this)); // This is a CSS fix function.
    });
  }
})(jQuery)