/**
 * params
 *	elemCarousel
 *	perMove
 */
 
var J = jQuery.noConflict();

function wdm_slide( objParams ) {
	objParams = objParams || {};
	var _iterator;
	for (_iterator in objParams) {
		this[_iterator] = objParams[_iterator];
	}
	
	var _countChild = this.elemCarousel.find('> li').length - 1;
    this.elemCarousel.css('width', _countChild * this.perMove * 2);
	this.maxMove = ( _countChild * this.perMove) * -1;
	this.perMove = this.perMove * -1;
	this.currentMove = 0;
	this.timer = null;
	var _self = this;
	
	this.move = function(moveTo) {
			
		if ( moveTo < this.maxMove) {
            moveTo = 0;
		}
        else if ( moveTo >= 0 ) {
            moveTo = this.maxMove;
        }
        /*
        // next btn
        if (moveTo <= this.maxMove)
            _self.nextBtn.hide();
        else
            _self.nextBtn.show();
            
        // prev btn
        if (moveTo >= 0)
            _self.prevBtn.hide();
        else
            _self.prevBtn.show();
            */
        //this.stop();
        this.elemCarousel.animate({
				marginLeft : moveTo
			});
		/*this.elemCarousel.animate({
				marginLeft : moveTo
			}, 'slow', 'linear', function() { if (!_self.timer) _self.start(); }); */
		//this.elemCarousel.css('top', moveTo)
		this.currentMove = moveTo;
	};
	
	this.start = function() {
		_self.timer = setTimeout(function() {
			var _moveTo = _self.currentMove + _self.perMove;
			_self.move(_moveTo);
		}, _self.speed);
	};
	
	
	this.stop = function() {
		clearTimeout(_self.timer);
		_self.timer = null;
	};
	
	//this.start();
	
	this.next = function() {
		var _moveTo = _self.currentMove + _self.perMove;
		_self.move(_moveTo);
		
	}
	
	this.prev = function() {
		var _moveTo = _self.currentMove - _self.perMove;
		_self.move(_moveTo);
	}
    this.nextBtn.click( function () { 
        _self.next();
        return false;
    });
    
    this.prevBtn.click( function () { 
        _self.prev();
        return false;
    });
}

// slide
J( function() {
   var _parent = J('div.carousel').get(0);
   
   if (!_parent) return;
   J('div.car-cont', _parent).css('overflow', 'hidden');
   
   var slide = new wdm_slide( {
       elemCarousel : J('div.car-cont ul', _parent),
       perMove : 194,
       nextBtn : J('a.right-arrow', _parent),
       prevBtn : J('a.left-arrow', _parent)
   });
})

// dropdown
J(function() {
    var _parent = J('#header .country-select').get(0);
    
    if (!_parent) return;
    
    var _ul = J('ul.country-ddown', _parent);
        _ul.hide().find('a')
            .click(function() {
                var _text = $(this).text();
                J('a.country', _parent).text(_text);
                _ul.slideUp();
                return false;
            });
            
    J('a.country', _parent).click(function() {
        _ul.slideDown();
    });
	
	
	var _timerUnHover = null;
	
	J('#header .main-nav > li').each( function() {
		var _me = J(this),
			_timer = null;
		_me.hover(
			function() {
				if ( _timer ) clearTimeout(_timer);
				_me.addClass('active');
			},
			
			function() {
				_timer = setTimeout(function() { _me.removeClass('active'); }, 100);
			}
		);
	});
	
})
