$(document).ready(function(){
	
	
	
	currentImage = 0;
	
	calculatePortfolio();
	
	
	//alert($totalImages);
	
	
	
	$('#arrowLeft').bind('mouseenter', function(){
		
		$(this).attr('src', '/template-core-2011/images/home/portfolio-leftF2.png');
		$(this).addClass('pointer');
		
	});
	
	$('#arrowLeft').bind('mouseleave', function(){
		
		$(this).attr('src', '/template-core-2011/images/home/portfolio-left.png');
		$(this).removeClass('pointer');
		
	});
	
		$('#arrowRight').bind('mouseenter', function(){
		
		$(this).attr('src', '/template-core-2011/images/home/portfolio-rightF2.png');
		$(this).addClass('pointer');
		
	});
	
	$('#arrowRight').bind('mouseleave', function(){
		
		$(this).attr('src', '/template-core-2011/images/home/portfolio-right.png');
		$(this).removeClass('pointer');
		
	});
	
	
	$('#arrowLeft').bind('click', function(){
			
			prevImage();
	});
	
	$('#arrowRight').bind('click', function(){
			
			nextImage();
	});
	
	
	
	
});

function nextImage(){
	
	if(currentImage < $totalImages -1){
		currentImage++;
		slideImage($slideWidth*-1);
	}
	
}

function prevImage(){
	
	if(currentImage >  0){
		currentImage--;
		slideImage($slideWidth);
	}
}

function slideImage(distance){
	
	$('.portfolioExample').removeClass('portfolioExampleActive');
	$('#browserurl').fadeTo(500,1, function(){
		
		fixTransparency();	
	});
	
	if(updatePortfolioInformation){
		
		showPortfolioInformation();
	}
	
	$('#' + portfolioContainerInner).animate({
		
		 left: '+=' + distance

	}, 500, 'easeOutQuad', function(){
		
		setStartSlideshow();
		$('#browserurl').html($('#portfolioDetailsLink_' + currentImage + ' a').attr('href'));
			$('#browserurl').fadeTo(500, 1, function(){
				
				fixTransparency();
				
			});
		
	});


}

function fixTransparency(){
	
	$('#browserurl').css('filter','');	
	$('#portfolio_' + currentImage).css('filter','');
	
}

function calculatePortfolio(){
	
	$totalImages = $('.initialphoto').length;
	$slideWidth = parseInt($('#' + portfolioContainerItem).css('width'));
	$('#' + portfolioContainerInner).attr('width', ($totalImages * $slideWidth) + 'px');
	$('#' + portfolioContainerInner + '.' + portdolioContainerItemClass).css('float', 'left');
	
	$('#browserurl').fadeTo(500,1, function(){
		
		fixTransparency();		
		
	});
	$('#browserurl').html($('#portfolioDetailsLink_0 a').attr('href'));
}


function constructPortfolio(){
		
		
		
		$('#portfolio_' + currentImage).fadeTo(1000, 1, function(){
		//	alert($('#portfolioDetailsLink_' + currentImage + ' a').attr('href'));
			
			fixTransparency();	
			
			
			//portfolioDetailsLink
			
			
		})
}

function showPortfolioInformation(){
	
	
	$('.portfolioDetails').css('display', 'none');
			constructPortfolio();
		
	
}

function setStartSlideshow(){
	//.addClass('portfolioExampleActive')
	$('.portfolioExample').eq(currentImage).addClass('portfolioExampleActive');
	if($('.portfolioExampleActive').length > 0){
	$('.portfolioExampleActive').cycle({
				fx: 'fade',
				speed: 500
			});
	}
}
