$(document).ready(function() {


	/* Ink Finder */
	$('#next').attr('disabled', false);
	$('#prev').attr('disabled', false);
	
	//var widthLi = parseInt($('ul#brand li').css('width'))+26;
	//var numLi = Math.round(($('ul#brand').children().length)/2);/* FINISH HERE SOON */
	
	// Brand slider
	$('#next').click(function(){
		var pos = parseInt($('ul#brand, ul#model').css('left'));
		$(this).attr('disabled', true);
		$('ul#brand, ul#model').animate({ left: pos-590 + "px" }, 500 );
		setTimeout(reEnable,500);
		function reEnable()
		{
			$('#next').attr('disabled', false);
		}
	});
	
	$('#prev').click(function(){
		var pos = parseInt($('ul#brand, ul#model').css('left'));
		$(this).attr('disabled', true); 
		$('ul#brand, ul#model').animate({ left: parseInt(pos+590) + "px" }, 500 );
		setTimeout(reEnable2,500);
		function reEnable2()
		{
			$('#prev').attr('disabled', false);
		}
	});
		
	var i = 1;
	
	
	$("#inkFinder ul li a").live('click', 
	function(e)
	{
		e.preventDefault();
		
		$('ul#brand, ul#model').css('left','0px');
		$(".bubb"+i).css('display','none');
		$(".bubb"+(i+1)).css('display','block');		
	
		var text = $(this).html();
		var area = parseInt($(this).parent().parent().attr("class"));
		$("#inkfinderSelected").find("."+area).css('background','url(images/selected.gif) no-repeat 50% 50% #fefefe');		
		$("#inkfinderSelected").find("."+i).find(".selection").html(text);		
		
		url = $(this).attr("href");	
		
		if ( i < 3 )
		{
			$.getJSON(url, function(data) {
				var text = "";
				var img = "";
				
			    for (var j=0; j < data.length; j++)
			    {   		    	
			    	if ( data[j].image )
			    	{
			    		img = '<img src="/images/printers/' + data[j].image + '" />';
			    	}		    		
			    	text += '<li><a href="' + data[j].url + '">' + data[j].name + img + '</a></li>';
			    }
			    
			    $("#inkFinder").find("."+(i)).html(text);
			}); 
		}
		else 
		{
			text = '<a href="' + url + '"><img src="/images/viewProductButton.gif" /></a>';
			$("#inkfinderSelected").find("."+(i+1)).find(".selection").html(text);	
		}
		
		$("#inkFinder").find("."+i).css('display','none');		
		$("#inkFinder").find("."+(i+1)).css('display','block'); 		

		
		if(i < 4)
		{
			$("#inkfinderArrow").animate({ left: (parseInt(i*160) + 40) + "px" }, 1000 );
		}
		else
		{
			$("#inkfinderArrow").css('display','none');
		}
		
		i++;
		if(i == 2)
		{
			$("#next").stop().animate({ opacity: 0.2 }, 200); 
			$("#prev").stop().animate({ opacity: 0.2 }, 200);
		}
		else
		{
			$("#next").stop().animate({ opacity: 1 }, 200);
			$("#prev").stop().animate({ opacity: 1 }, 200);
		}
		if(i == 4)
		{
			$("#next").css('display','none'); 
			$("#prev").css('display','none');
			$("#inkFinder").css('display','none');
			$("#inkfinderArrow").css('display','none');
			
		}
		else
		{
			$("#next").css('display','inline'); 
			$("#prev").css('display','inline');
			$("#inkFinder").css('display','block');
			$("#inkfinderArrow").css('display','inline');
		}
		
		if(i == 3)
		{
			$("#next").attr('disabled', true);
			$("#prev").attr('disabled', true);
			$("#next").stop().animate({ opacity: 0.2 }, 200); 
			$("#prev").stop().animate({ opacity: 0.2 }, 200);
		}
		else
		{
			$("#next").attr('disabled', false);
			$("#prev").attr('disabled', false);

		}

	});
	
	

	
	
	
	
	
	$("#backButton").click(function(e)
	{
		e.preventDefault();

		if (i>1)
		{
			$("#inkfinderArrow").animate({ left: (parseInt((i-2)*160) + 40) + "px" }, 1000 );
			$(".bubb"+i).css('display','none');
			$(".bubb"+(i-1)).css('display','block');
			
			$("#inkfinderSelected").find("."+(i-1)).css('background','url(/images/notSelected.gif) no-repeat 50% 50% #f6fbff');
			
			$("#inkfinderSelected").find("."+(i-1)).find(".selection").html("");
			$("#inkFinder").find("."+i).css('display','none');
			$("#inkFinder").find("."+(i-1)).css('display','block');
			i--;
		}
		
		if(i == 2)
		{
			$("#next").stop().animate({ opacity: 0.2 }, 200); 
			$("#prev").stop().animate({ opacity: 0.2 }, 200);
		}
		else
		{
			$("#next").stop().animate({ opacity: 1 }, 200);
			$("#prev").stop().animate({ opacity: 1 }, 200);
		}
		
		if(i < 4)
		{
			$("#next").css('display','inline'); 
			$("#prev").css('display','inline');
			$("#inkFinder").css('display','block');
			$("#inkfinderArrow").css('display','inline');
			$(".selection").css('display','hidden');
		}
		
		if(i == 3)
		{
			$("#next").attr('disabled', true);
			$("#prev").attr('disabled', true);
			$("#next").stop().animate({ opacity: 0.2 }, 200); 
			$("#prev").stop().animate({ opacity: 0.2 }, 200);
		}
		else
		{
			$("#next").attr('disabled', false);
			$("#prev").attr('disabled', false);

		}
	});
	
	

	
	
	
	
	
	
	
	
	
	
	/* END Ink Finder */
	













































/*

function man() {
	
	jQuery("#modx").hide();
	jQuery("#mod").hide();
	
	jQuery("#itex").hide();
	jQuery("#ite").hide();
	jQuery("#ited").hide();
	
	ps = "Manufacturer=" + jQuery("#manuf").val();	
	url = "/consumables/filter/";
	
	jQuery.getJSON ( url, ps, gettypes )
	
}

function gettypes(data) 
{	
	var options = '';
	jQuery("#modelty").children().remove();
	
    options += '<option value="0">select...</option>'; 
    
    jQuery.each(data.ajaxresponse, function(i,item)
    {	
    	modeltype = item.MachineType;	
		options += '<option value="' + modeltype + '">' + modeltype + '</option>';	
	})	
    	
	jQuery("#modelty").append(options);
	jQuery("#modx").show();
	jQuery("#mod").show();		
	
}


function tpy() {
	
	if ( jQuery("#modelty").val() != 0 )
	{
		ps = "Manufacturer=" + jQuery("#manuf").val();
		ps = ps + "&ModelType=" + jQuery("#modelty").val();
		
		url = "/consumables/filter/";
		
		jQuery.getJSON ( url, ps, getmodels )
	} else {
		jQuery("#itex").hide();
		jQuery("#ite").hide();		
		jQuery("#ited").hide();
	}
		

}

function getmodels(data) {
	
	var options = '';
	jQuery("#modelnum").children().remove();
	
    options += '<option value="0">select...</option>'; 
    
    jQuery.each(data.ajaxresponse, function(i,item)
    {	
    	modelnumbers = item.MachineName;	
    	modelcode = item.PKU;	
		options += '<option value="' + modelcode + '">' + modelnumbers + '</option>';	
	})	
    	
	jQuery("#modelnum").append(options);
	jQuery("#itex").show();
	jQuery("#ite").show();	

}

function showButton() {
	if ( jQuery("#modelnum").val() != 0 ) 
	{
		jQuery("#ited").show();	
	} else {
		jQuery("#ited").hide();
	}

}*/

});
