$(document).ready(function() {

	$('.userlogin').click(function() {
		var atextLogin = 'user login';
		var atextClose = 'close'
		if ($('.userlogin span strong').text() == atextLogin)  {
			$('.userlogin span strong').text(atextClose);
		} else {
			$('.userlogin span strong').text(atextLogin);
		}
		$('.login-cont').toggle();
	});
	
	$('.cat-btn').click(function() {
		$('.s-category ul').toggle();
		return false;
	});
	
	$('#uname').click(function() {
		var unametxt = 'Username';
		if ($('#uname').val() == unametxt) {
			$('#uname').val('')
		}
	});	
	
	$('#pword').click(function() {
		var pwordtxt = 'Password'
		
		if ($('#pword').val() == pwordtxt) {
			$('#pword').val('')
		}
	});	
	
});


/**
 * params
 *	elemCarousel
 *	perMove
 */
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.maxMove = ( _countChild * objParams.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;

		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 = setInterval(function() {
			var _moveTo = _self.currentMove + _self.perMove;
			_self.move(_moveTo);
		}, _self.speed);
	};
	
	
	this.stop = function() {
		clearInterval(_self.timer);
		_self.timer = null;
	}; 
	
	this.start(); */
	
	this.next.click( function() {
		var _moveTo = _self.currentMove + _self.perMove;
		_self.move(_moveTo);
		//_self.stop();
		return false;
	});
	
	this.prev.click( function() {
		var _moveTo = _self.currentMove - _self.perMove;
		_self.move(_moveTo);
		//_self.stop();
		return false;
	});
}

$( function() {
	
	var _carousel = $('.rightcolumn div.carousel');
	
	var _slide = new wdm_slide({
		'elemCarousel' : _carousel.find('ul'),
		'prev' : _carousel.parent().find('a.prev'),
		'next' : _carousel.parent().find('a.next'),
		'perMove' :76,
		'speed' : 5000
		});
	
	$('.unitphotos ul.clearfix a').click( function () {
			var _href = $(this).attr('href');
			var _rel = $(this).attr('rel');
			
			
			$('.unitphotos div.main img').fadeOut('slow', function() {
						$(this).attr({
							src : _href
						})
						 .parent('a').attr('href', _rel);
						$(this).fadeIn('slow') 
					});
			
			return false;
	});
	
	$('.unitphotos div.main > a').lightBox();
});
