// execute your scripts when the DOM is ready. this is a good habit 	
$(function() { 
	// initialize scrollable 
	$('#videoProfiles .panelContent .buttons a').live('click', function() {
		if (!$(this).is(".play")) {
			//$('.play').hide();
			var container = $('#videoProfiles .panelContent .images .theslider').not(':animated');
			if (!container.length) {
				return false;
			}
			var images = '#videoProfiles .panelContent .images .slider_image img';
			var possibleMoves = $(images).length;
			var firstElement = $(images+':first');
			var lastElement = $(images+':last');
			var currentElement = $('#videoProfiles .panelContent .images .big img');
			var nextElement = "";
			
			if ($(this).hasClass('next')) {
				nextElement = currentElement.parent().next().find("img");
				if (nextElement.length == 0) {
					nextElement = firstElement;
					delta = 102;
				}
				else {
					delta = 162;
				}
			}
			else if ($(this).hasClass('prev')) {
				nextElement = currentElement.parent().prev().find("img");
				if (nextElement.length == 0) {
					nextElement = lastElement;
					delta = 162;
				}
				else {
					delta = 102;
				}
			}
			
			container.animate({
				'left': (-1 * $(nextElement).position().left + delta) + 'px'
			});
			
			currentElement.parent().animate({
				'width': '100px',
				'height': '85px',
				'marginTop': '22px'
			});
			currentElement.animate({
				'width': '100px',
				'height': '85px'
			});
			currentElement.next().animate({
				'width': '100px'
			});
			nextElement.parent().animate({
				'width': '160px',
				'height': '130px',
				'marginTop': '0'
			});
			//set this to a full sized item
			nextElement.animate({
				'width': '160px',
				'height': '130px',
				'marginTop': '0'
			});
			nextElement.next().animate({
				'width': '160px'
			}, "normal", "linear", function() {
				$('.play').attr("rel", nextElement.siblings('a').attr('rel'));
				$('.play').show();
			});
			
			currentElement.parent().removeClass('big').addClass('thumb');
			nextElement.parent().removeClass('thumb').addClass('big');
			return false;
		}
	});
}); 