jQuery(document).ready(function() {
	var oLooks = new Looks();
	// jQuery(window).resize(function() {
	// 	oLooks.init();
	// });
	oLooks.init();
	oLooks.setVisibility();
});
function Looks(){
}

Looks.prototype = {
	init:function() {
		this.itemWidth = 756 + 60;
	    this.itemNum = jQuery('.looks ul li').length;
	    this.looksWidth = this.itemNum * this.itemWidth;
		jQuery('.looks ul').css({width:this.looksWidth});
	    this.bFlag = true;
	    this.attachEvents();
	},
	setVisibility:function() {
		var _my = this;
		if (n = eval(jQuery('#zoom').attr('class')) ){}else {
			var n = Math.round(this.itemNum*Math.random());
		}
		if (n>0 && n<this.itemNum) {
			$('.looks ul').css({left:-this.itemWidth*n});
			_my.addPairHrefToZoom(n)
		} else {
			$('.arrow-left').css({opacity:0, visibility:'hidden'});
			if (this.looksWidth<=this.itemWidth) {
				$('.arrow-right').css({opacity:0, visibility:'hidden'});    
			} else {
				_my.addPairHrefToZoom(0)
			}
		}
		if (n == this.itemNum - 1) {
			$('.arrow-right').css({opacity:0, visibility:'hidden'});      
		}
	},
	attachEvents:function() {
    	var _my = this;
		jQuery('.navigation.arrow-left').click(function() {
	      _my.moveLeft();
	    });
		jQuery('.navigation.arrow-right').click(function() {
	      _my.moveRight();
	    });
		jQuery('.winners .place').hover(function(){
			jQuery('.red', this).css('display','none');
		},function(){
			jQuery('.red', this).css('display','block');
		});
	},
	moveRight:function() {
    var _my = this;
    if (this.bFlag == true && this.looksWidth-Math.abs(jQuery('.looks ul').offset().left)>this.itemWidth) {
      if (jQuery('.arrow-left').css('visibility') == 'hidden') {
        jQuery('.arrow-left').css({visibility:'visible'});
        jQuery('.arrow-left').animate({opacity:1}, 600);
      }
      if (this.looksWidth-Math.abs(jQuery('.looks ul').offset().left) == 2*this.itemWidth) {
        jQuery('.arrow-right').animate({opacity:0}, 600, function(){
          jQuery('.arrow-right').css({visibility:'hidden'});
        })
      }
      this.bFlag = false;
      jQuery('.looks ul').animate({left:jQuery('.looks ul').offset().left-this.itemWidth}, 600, 'easeout', function() {
        _my.bFlag = true;
      });
		
		_my.addPairHrefToZoom(eval(jQuery('#zoom').attr('class')) + 1 )
    }
  },
	moveLeft:function() {
		var _my = this;
		if (this.bFlag == true && Math.abs(jQuery('.looks ul').offset().left)>0) {
		if (jQuery('.arrow-right').css('visibility') == 'hidden') {
			jQuery('.arrow-right').css({visibility:'visible'});
			jQuery('.arrow-right').animate({opacity:1}, 600);
		}
		if (Math.abs(jQuery('.looks ul').offset().left) == this.itemWidth) {
			jQuery('.arrow-left').animate({opacity:0}, 600, function(){
				jQuery('.arrow-left').css({visibility:'hidden'});
			})
		}
		this.bFlag = false;
		jQuery('.looks ul').animate({left:jQuery('.looks ul').offset().left+this.itemWidth}, 600, 'easeout', function() {
			_my.bFlag = true;
		});
			_my.addPairHrefToZoom(jQuery('#zoom').attr('class') - 1 )
		}
	},
	addPairHrefToZoom:function(n){
	 	var _my = this;
		sZoom = jQuery( '.battle-user a',jQuery('.looks ul li').eq(n)).eq(4).attr('href')
		
		jQuery('#zoom').attr('href', sZoom );
		jQuery('#zoom').attr('class', n);
	}
}