var leftPx = 0;
var offset = 0;

var leftPx_a = 0;
var offset_a = 0;

var leftPx_b = 0;
var offset_b = 0;

var leftPx_c = 0;
var offset_c = 0;

var leftPx_d = 0;
var offset_d = 0;

var leftPx_e = 0;
var offset_e = 0;

var leftPx_f = 0;
var offset_f = 0;

$(document).ready(function(){
	/* REEL PAGE VARIABLES */
	var reelOffset = $('div#reel_video_container div.thumb_container').size();
	
	/* EL PAIS - LOCACIONES VARIABLES */
	var locPhotoReel_a = $('div#locaciones_photo_container_a div.thumb_container').size();	
	var locPhotoReel_b = $('div#locaciones_photo_container_b div.thumb_container').size();	
	var locPhotoReel_c = $('div#locaciones_photo_container_c div.thumb_container').size();
	var locPhotoReel_d = $('div#locaciones_photo_container_d div.thumb_container').size();
	var locPhotoReel_e = $('div#locaciones_photo_container_e div.thumb_container').size();
	var locPhotoReel_f = $('div#locaciones_photo_container_f div.thumb_container').size();
	
	/* REEL ANIMATIONS */
	$('div.next_button a#reel_next').click(function(){
		reel_next(leftPx, offset, reelOffset, 'div#reel_video_container');
	});
	
	$('div.previous_button a#reel_prev').click(function(){
		reel_prev(leftPx, offset, reelOffset, 'div#reel_video_container');
	});
	
	$('div#reel_video_container div.thumb_container div.thumb_wrapper_ind').hover(
		function(){
			switchBg_video_over(this);
		},
		
		function(){
		
		}
	);
	
	$('div#reel_video_container div.thumb_container div.thumb_wrapper_ind div.hover_reel_div').hover(
		function(){
		
		},
		
		function(){
			switchBg_video_out(this);
		}
	);
	
	/* LOCACIONES ANIMATIONS */
	/* -- MONTEVIDEO REEL -- */
	$('div.next_button a#loc_next_a').click(function(){
		reel_next(leftPx_a, offset_a, locPhotoReel_a, 'div#locaciones_photo_container_a');
	});
	
	$('div.previous_button a#loc_prev_a').click(function(){
		reel_prev(leftPx_a, offset_a, locPhotoReel_a, 'div#locaciones_photo_container_a');
	});
	
	$('div#locaciones_photo_container_a div.thumb_container a').hover(
		function(){
			switchBg_image(this, 0);
		},
		
		function(){
			switchBg_image(this, 1);
		}
	);
	
	/* -- PUNTA DEL ESTE REEL -- */
	$('div.next_button a#loc_next_b').click(function(){
		reel_next(leftPx_b, offset_b, locPhotoReel_b, 'div#locaciones_photo_container_b');
	});
	
	$('div.previous_button a#loc_prev_b').click(function(){
		reel_prev(leftPx_b, offset_b, locPhotoReel_b, 'div#locaciones_photo_container_b');
	});
	
	$('div#locaciones_photo_container_b div.thumb_container a').hover(
		function(){
			switchBg_image(this, 0);
		},
		
		function(){
			switchBg_image(this, 1);
		}
	);
	
	/* -- COLONIA REEL -- */
	$('div.next_button a#loc_next_c').click(function(){
		reel_next(leftPx_c, offset_c, locPhotoReel_c, 'div#locaciones_photo_container_c');
	});
	
	$('div.previous_button a#loc_prev_c').click(function(){
		reel_prev(leftPx_c, offset_c, locPhotoReel_c, 'div#locaciones_photo_container_c');
	});
	
	$('div#locaciones_photo_container_c div.thumb_container a').hover(
		function(){
			switchBg_image(this, 0);
		},
		
		function(){
			switchBg_image(this, 1);
		}
	);
	
	/* -- CAMPO REEL -- */
	$('div.next_button a#loc_next_d').click(function(){
		reel_next(leftPx_d, offset_d, locPhotoReel_d, 'div#locaciones_photo_container_d');
	});
	
	$('div.previous_button a#loc_prev_d').click(function(){
		reel_prev(leftPx_d, offset_d, locPhotoReel_d, 'div#locaciones_photo_container_d');
	});
	
	$('div#locaciones_photo_container_d div.thumb_container a').hover(
		function(){
			switchBg_image(this, 0);
		},
		
		function(){
			switchBg_image(this, 1);
		}
	);
	
	/* -- LOCACIONES PAGE REEL -- */
	$('div.next_button a#loc_next_e').click(function(){
		reel_next(leftPx_e, offset_e, locPhotoReel_e, 'div#locaciones_photo_container_e');
	});
	
	$('div.previous_button a#loc_prev_e').click(function(){
		reel_prev(leftPx_e, offset_e, locPhotoReel_e, 'div#locaciones_photo_container_e');
	});
	
	$('div#locaciones_photo_container_e div.thumb_container a').hover(
		function(){
			switchBg_image(this, 0);
		},
		
		function(){
			switchBg_image(this, 1);
		}
	);
	
	/* -- TALENTOS PAGE REEL -- */
	$('div.next_button a#loc_next_f').click(function(){
		reel_next(leftPx_f, offset_f, locPhotoReel_f, 'div#locaciones_photo_container_f');
	});
	
	$('div.previous_button a#loc_prev_f').click(function(){
		reel_prev(leftPx_f, offset_f, locPhotoReel_f, 'div#locaciones_photo_container_f');
	});
	
	$('div#locaciones_photo_container_f div.thumb_container a').hover(
		function(){
			switchBg_image(this, 0);
		},
		
		function(){
			switchBg_image(this, 1);
		}
	);
});

function reel_next(curLeftPx, curOffset, curReelOffset, curDiv){
	curLeftPx += 460;
	curOffset += 1;
	curDiv = curDiv + ' div.thumb_wrapper';
	
	if(curOffset < curReelOffset){
		$(curDiv).animate({
			'left': '-' + curLeftPx + 'px'
		}, 750);
	} else {
		curOffset = 0;
		curLeftPx = 0;
		
		$(curDiv).animate({
			'left': '0px'
		}, 750);
	}

	updateVariables(curLeftPx, curOffset, curDiv);
}

function reel_prev(curLeftPx, curOffset, curReelOffset, curDiv){
	curDiv = curDiv + ' div.thumb_wrapper';
	
	if(curOffset == 0){
		curLeftPx = (curReelOffset - 1) * 460;
		
		$(curDiv).animate({
			'left': '-' + curLeftPx + 'px'
		}, 750);
		
		curOffset = curReelOffset - 1;
	} else {
		curOffset -= 1;
		curLeftPx -= 460;
		
		$(curDiv).animate({
			'left': '-' + curLeftPx + 'px'
		}, 750);
	}
	
	updateVariables(curLeftPx, curOffset, curDiv);
}

function updateVariables(curLeftPx, curOffset, curDiv){
	switch(curDiv){
		case 'div#reel_video_container div.thumb_wrapper' : {
			leftPx = curLeftPx;
			offset = curOffset;
		}; break;
		
		case 'div#locaciones_photo_container_a div.thumb_wrapper' : {
			leftPx_a = curLeftPx;
			offset_a = curOffset;
		}; break;
		
		case 'div#locaciones_photo_container_b div.thumb_wrapper' : {
			leftPx_b = curLeftPx;
			offset_b = curOffset;
		}; break;
		
		case 'div#locaciones_photo_container_c div.thumb_wrapper' : {
			leftPx_c = curLeftPx;
			offset_c = curOffset;
		}; break;
		
		case 'div#locaciones_photo_container_d div.thumb_wrapper' : {
			leftPx_d = curLeftPx;
			offset_d = curOffset;
		}; break;
		
		case 'div#locaciones_photo_container_e div.thumb_wrapper' : {
			leftPx_e = curLeftPx;
			offset_e = curOffset;
		}; break;
		
		case 'div#locaciones_photo_container_f div.thumb_wrapper' : {
			leftPx_f = curLeftPx;
			offset_f = curOffset;
		}; break;
	}
}

function switchBg_video_over(element){
	$(element).children('div.hover_reel_div').fadeIn('slow');
		
	$(element).css({
		'background-image': 'url(images/video_icon.jpg)',
		'background-repeat': 'no-repeat',
		'background-position': '117px 0px'
	});
}

function switchBg_video_out(element){
	$(element).fadeOut('slow');
		
	$(element).parent('div.thumb_wrapper_ind').css({
		'background': 'none'
	});
}

function switchBg_image(element, type){
	/* MOUSE OVER */
	if(type == 0){
		$(element).css({
			'background-image': 'url(images/photo_icon.jpg)',
			'background-repeat': 'no-repeat',
			'background-position': '117px 5px'
		});
		
		$(element).children('img').css({
			'border': '1px solid',
			'border-color': '#ffdb00',
			'padding': '0px'
		});
	} else {
		/* MOUSE OUT */
		$(element).css({
			'background': 'none'
		});
		
		$(element).children('img').css({
			'border': '0px',
			'padding': '1px'
		});
	}
}