/*	=======================	*/
/*	Module:	stye creator	*/
/*	By:		Robin 't Hoen	*/
/*	Date: 21 jan 2010		*/
/*	=======================	*/

$(document).ready(function(){

	var types = ["jacket", "shirt", "pants"];

	$.each(types, function(){
		$.post("/_php/_requests/stylecreator.php",
			{action: "startup", type: this},
			function(data){
				var type = data.type;
				//	clear attributes

				$("#"+type+"_name").text("");

				$("#"+type+"_price").text("");
				//	set new values to attributes
				$("#"+type+"_id").val(data.id);
				$("#"+type+"_name").text(data.productnaam);
				$("#"+type+"_img").attr("src", data.imgsrc);
				$("#"+type+"_price").text(data.price);
						
			},"json"
		);
	});
	
	//	click action for right arrow for jackets
	$("#jacket_rgt").click(function(){
		var img_id = $("#jacket_id").val();
		$.post("/_php/_requests/stylecreator.php",
			{action: "change_item" , type: 'jacket', last: img_id, order: 1 },
			function(data){			
				var type = data.type;
				//	clear attributes

				$("#"+type+"_name").text("");

				$("#"+type+"_price").text("");
				//	set new values to attributes
				$("#"+type+"_id").val(data.id);
				$("#"+type+"_name").text(data.productnaam);
				$("#"+type+"_img").attr("src", data.imgsrc);
				$("#"+type+"_price").text(data.price);
			},"json"
		);
	});

	//	click action for left arrow for jackets
	$("#jacket_lft").click(function(){
		var img_id = $("#jacket_id").val();
		$.post("/_php/_requests/stylecreator.php",
			{action: "change_item" , type: 'jacket', last: img_id, order: 0 },
			function(data){
				var type = data.type;
				//	clear attributes

				$("#"+type+"_name").text("");

				$("#"+type+"_price").text("");
				//	set new values to attributes
				$("#"+type+"_id").val(data.id);
				$("#"+type+"_name").text(data.productnaam);
				$("#"+type+"_img").attr("src", data.imgsrc);
				$("#"+type+"_price").text(data.price);			
			},"json"
		);
	});

	//	click action for right arrow for shirts
	$("#shirt_rgt").click(function(){
		var img_id = $("#shirt_id").val();
		$.post("/_php/_requests/stylecreator.php",
			{action: "change_item" , type: 'shirt', last: img_id, order: 1 },
			function(data){
				var type = data.type;
				//	clear attributes

				$("#"+type+"_name").text("");
				$("#"+type+"_price").text("");
				//	set new values to attributes
				$("#"+type+"_id").val(data.id);
				$("#"+type+"_name").text(data.productnaam);
				$("#"+type+"_img").attr("src", data.imgsrc);
				$("#"+type+"_price").text(data.price);			
			},"json"
		);
	});

	//	click action for left arrow for shirts
	$("#shirt_lft").click(function(){
		var img_id = $("#shirt_id").val();
		$.post("/_php/_requests/stylecreator.php",
			{action: "change_item" , type: 'shirt', last: img_id, order: 0 },
			function(data){
				var type = data.type;
				//	clear attributes

				$("#"+type+"_name").text("");

				$("#"+type+"_price").text("");
				//	set new values to attributes
				$("#"+type+"_id").val(data.id);
				$("#"+type+"_name").text(data.productnaam);
				$("#"+type+"_img").attr("src", data.imgsrc);
				$("#"+type+"_price").text(data.price);			
			},"json"
		);
	});

	//	click action for right arrow for pants
	$("#pants_rgt").click(function(){
		var img_id = $("#pants_id").val();
		$.post("/_php/_requests/stylecreator.php",
			{action: "change_item" , type: 'pants', last: img_id, order: 1 },
			function(data){
				var type = data.type;
				//	clear attributes

				$("#"+type+"_name").text("");

				$("#"+type+"_price").text("");
				//	set new values to attributes
				$("#"+type+"_id").val(data.id);
				$("#"+type+"_name").text(data.productnaam);
				$("#"+type+"_img").attr("src", data.imgsrc);
				$("#"+type+"_price").text(data.price);			
			},"json"
		);
	});

	//	click action for left arrow for pants
	$("#pants_lft").click(function(){
		var img_id = $("#pants_id").val();
		$.post("/_php/_requests/stylecreator.php",
			{action: "change_item" , type: 'pants', last: img_id, order: 0 },
			function(data){
				var type = data.type;
				//	clear attributes

				$("#"+type+"_name").text("");

				$("#"+type+"_price").text("");
				//	set new values to attributes
				$("#"+type+"_id").val(data.id);
				$("#"+type+"_name").text(data.productnaam);
				$("#"+type+"_img").attr("src", data.imgsrc);
				$("#"+type+"_price").text(data.price);			
			},"json"
		);
	});	
});


function submitSet(){
	//	get selected id's
	var jacket_id = $("#jacket_id").val();
	var shirt_id = $("#shirt_id").val();
	var pants_id = $("#pants_id").val();

	$.post("/_php/_requests/stylecreator.php",
		{action: "make_set", jacket: jacket_id, shirt: shirt_id, pants: pants_id},
		function(data){
			self.location.href="/set/"+data.id+"/";
		},"json"
	);
}