﻿jQuery(document).ready(function()
{
	$(".imageHolder").mousemove(function(e)
	{
		var position = $(this).offset();
		var x = e.pageX - position.left;
		var y = e.pageY - position.top;
		var side = "";
		
		var caption = $(this).find("#caption");
		
		if(x > $(this).width() * .5)
		{
			side = "right";
			
			$(this).find("#caption").removeClass("left")
			$(this).find("#caption").addClass("right")
				
		} else 
		{
			side = "left";
			$(this).find("#caption").removeClass("right")
			$(this).find("#caption").addClass("left")
		}
		
		// $('#alerts').html( side + " : " + x +', '+ y);
	}); 
	
	// Remove the hover
	$(".imageHolder").mouseleave(function(e)
	{
		// var caption = 
		$(this).find("#caption").remove(); // .find('.caption');
	
		$(this).find("#caption").removeClass("left")
		$(this).find("#caption").removeClass("right")
		
		
	})
	
	$(".imageHolder").mouseenter( function(e)
	{
		$(this).prepend("<div id='caption'><div class='bar'></div></div>")
		
		$(this).find("#caption").click( function() 
		{
			if( $(this).hasClass("right") )
			{
				side = "right";
				showNextImage( $(this).parent() ) 
				
				// alert("Show next image")
					
			} else 
			{
				side = "left";
				showNextImage( $(this).parent() ) 
				
				// alert("Show prev image")
				
			}
			
		})
		
	})
	
})







///////////////////////////////// 
$(document).ready( function() 
{
	// $(".section").each("img").each( function(i) file:///G:/amaclean/deploy/img/portfolio_bdse_01.jpg
	$(".section").each( function( i ) 
	{
		// alert("kjhkl")
		$(this).append("<br class='clearBoth' />")
		$(this).find(".imageHolder").wrap("<div class='imageHolderWrapper' />")
		
		// Add a line break to clear the floats
		// $(this).append("<br class='clearBoth' />");
		
		$(this).find("img").each( function( n )
		{
			// Hide the first image
			if(n > 0) $(this).hide()
			
			$(this).addClass("onOut")
			
			$(this).mouseover( function() 
			{
				$(this).addClass("onOver")
				$(this).removeClass("onOut")
				
			}).mouseout( function() 
			{
				$(this).addClass("onOut")
				$(this).removeClass("onOver")
			})
			
		})
		
	})
	
})

function showNextImage( item )
{
	var current = $(item).find("img.active");
	
	var next = current.next().length ? current.next() : current.parent().find("img:first");				
		next.show();
		next.addClass("active");
		
	current.hide();
	current.removeClass("active")
	
}

function prevNextImage( item )
{
	var current = $(item).find("img.active");
	
	var next = current.prev().length ? current.prev() : current.parent().find("img:last");				
		next.show();
		next.addClass("active");
		
	current.hide();
	current.removeClass("active")
}

$(document).ready( function() 
{
	// $(".section").each("img").each( function(i) file:///G:/amaclean/deploy/img/portfolio_bdse_01.jpg
	$(".section").each( function( i ) 
	{
		// Add a line break to clear the floats
		// $(this).append("<br class='clearBoth' />");
		
		$(this).find("img").each( function( n )
		{
			// Hide the first image
			
			if(n == 0) $(this).addClass("active");
			
			if(n > 0) $(this).hide()
			
			$(this).addClass("onOut")
			
			$(this).mouseover( function() 
			{
				$(this).addClass("onOver")
				$(this).removeClass("onOut")
				
			}).mouseout( function() 
			{
				$(this).addClass("onOut")
				$(this).removeClass("onOver")
			})
			
		})
		
		
	})
	
})
