// JavaScript Document
$(document).ready(function() {

	var totalWidth = 0;
	var totalHeight = 0;
	var leftPos = 0;
	var reviewWidth = 0;
	var currentState =0;
						   
	$('.review').each(function(){
		reviewWidth = $(this).width() + parseInt($(this).css('padding-right').replace('px','')) + parseInt($(this).css('margin-right').replace('px',''));
		totalWidth = totalWidth + reviewWidth;
		
		var reviewHeight = $(this).height();
		if(totalHeight<reviewHeight) {
			totalHeight = reviewHeight;
		}
	});
	
	$('#review-slide').width(totalWidth);
	$('#review-container').height(totalHeight);
	
	checkLeftPos();
	
	function checkLeftPos() {
		leftPos = $('#review-slide').css('left').replace('px','');
		if(leftPos==0) {
			$('a.prev').fadeOut();
			$('a.next').fadeIn();
		} else if (leftPos<= -(totalWidth - reviewWidth * 4)) {
			$('a.next').fadeOut();
			$('a.prev').fadeIn();
		} else {
			$('a.prev').fadeIn();
			$('a.next').fadeIn();
		}
	}
	$('a.next').click(function(){
		if($(this).css('opacity')==1) {
			$('#review-slide:not(:animated)').animate({'left':'-='+reviewWidth+'px'},function(){
				checkLeftPos();
			});
		}
		return false;
	});
	
	
	$('a.prev').click(function(){
		if($(this).css('opacity')==1) {
			$('#review-slide:not(:animated)').animate({'left':'+='+reviewWidth+'px'},function(){
				checkLeftPos();
			});
		}
		return false;
	});
	
	
	//LIGHTBOX
	
	$("ul.gallery a, a.zoom").lightBox();	
	
	$("ul.gallery li a").append("<img src='images/magnify.jpg' class='magnify' />");
	$(".magnify").css({"opacity": 0});
	
	$("ul.gallery li a").hover(function(){
		$(this).children(".magnify").stop(true, true).animate({"opacity": 0.77});						
	}, function(){
		$(this).children(".magnify").stop(true, true).animate({"opacity": 0});	
	});

	
	//IMAGE ROTATOR
	
	/* var count=0;
	var countImages = $('.image a img').size();
	
	
	$('.image > a img').each(function(){
		$(this).addClass('fade'+count);							
		if(count>0){
			$(this).hide();
		}
		count++;
	});
	
	count=0;
	
	setInterval(nextImage,4000);
	
	function nextImage() {
		$('.fade'+count).fadeOut(1500);
		if(count<countImages-1){
			count++;
		} else {
			count=0;
		}
		$('.fade'+count).fadeIn(1500);
	} */

});