loadSystems =
	function(){
		wsContent.getSystems(currLang, loadSystems_complete, loadSystems_error, "null")
	};

loadSystems_complete =
	function(result){
		$("#mainCol").find("#systemListing").remove();
		if(result.rows){
			$("#mainCol").append("<div id='systemListing' style='display:none;'></div>");
			$.each(result.rows, function(i){
				$("#mainCol").find("#newsListing").append("<div onClick='loadSystem(" + result.rows[i]["ID"] + ")'>" + result.rows[i]["Name"] + "</div>");
			})
			$("#mainCol").find("#newsListing").fadeIn("fast");
		}
	};

loadSystems_error =
	function(result){
		alert(result.get_message())
	};
	
// - - - - - - - - -
	
		
loadSystem =
	function(systemId){
		
		$("#leftCol").fadeOut("fast", function(){
			$("#leftCol").empty();
		})
		
		$("#rightCol").fadeOut("fast", function(){
			$("#rightCol").empty();
		})
		
		$(".systemList").fadeOut("fast", function(){
			$(".systemList").remove();
		});
		$("#mainCol").fadeOut("fast", function(){

			$("#mainCol").empty();
			wsContent.getSystem(systemId, loadSystem_complete, loadSystem_error, "null")
			wsContent.getPanelByPage(systemId, 0, 0, 0, currLang, loadLeftAndRightCol_complete, loadLeftAndRightCol_error, "null");
		
		})
	};


loadSystem_complete =
	function(result){
		$("body").append("<div class='systemList' style='display: none;'></div>")
		$("#mainCol").append("<div id='bgIllustration'><div id='systemMediaPanelWrapper'><div class='systemMediaPanel' id='systemMediaPanel'><div id='illustration'><img src='../img/blank.gif' width='526' height='338' alt='' /></div></div><div class='systemMediaPanelMenu'><div id='mediaPanelHoleSizes' style='float: right;'></div></div><div class='head' style='font-size: 18px !important; margin-top: 15px;'>" + result.rows[0]["Header"] + " <span id='holeSizeHead'></span>");
		if(result.rows[0]["PDF"]){
			$("#mainCol").append("<a href='http://www.wassara.com/images/PDF/" + result.rows[0]["PDF"] + "' target='_blank'><img src='../img/systems/pdfIcon.gif' width='41' height='40' border='0' style='position: absolute; top: 375px; right: 0px;' alt='Click to download PDF over this system'></a>");
		}
		$("#mainCol").append("</div></div>");
		
		var holeSubHead = result.rows[0]["SelectText"];
		
		$(".systemMediaPanelMenu").append("<div class='subHeadW' style='float: left; margin-top: 6px; margin-left: 45px;'>" + holeSubHead + "</div>");

		$("#mainCol").fadeIn("fast");
		
		var bgImage = "url('http://www.wassara.com/images/system/" + result.rows[0]["MainImage"] + "')";
		$("#bgIllustration").css({"background-image":bgImage});
		
		loadSystemHoleSizes(result.rows[0]["ID"]);
	};
	
loadSystem_error =
	function(result){
		alert(result.get_message())
	};
	

// - - - - - - - - -
	
	
loadSystemHoleSizes =
	function(systemId){
		wsContent.getProducts(systemId, loadSystemHoleSizes_complete, loadSystemHoleSizes_error, "null")
	};

loadSystemHoleSizes_complete =
	function(result){
		if(result.rows){
			$.each(result.rows, function(i){
				var holeZ = ("" + result.rows[i]["HoleSize1"] + "");

				$("#mediaPanelHoleSizes").append("<div id='" + result.rows[i]["ID"] + "' onClick='loadSystemPartsByHoleSize(" + result.rows[i]["ID"] + ", \"" + holeZ + "\")' class='holeZ'>" + holeZ + "</div>");
			})
			$("#mediaPanelHoleSizes").find(".holeZ:first").click();
		}
	};
	
loadSystemHoleSizes_error =
	function(result){
		alert(result.get_message())
	};
	
	
// - - - - - - - - -
	
	
loadSystemPartsByHoleSize =
	function(holeSize, holeSizeHead){
		$("#holeSizeHead").empty();
		$("#holeSizeHead").append("&nbsp; &Oslash; " + holeSizeHead + " mm");
		$("#mediaPanelHoleSizes").find(".holeZ_Active").removeClass("holeZ_Active");
		$("#mediaPanelHoleSizes").find("#"+holeSize).addClass("holeZ_Active");
		
		wsContent.getParts(holeSize, loadSystemPartsByHoleSize_complete, loadSystemPartsByHoleSize_error, "null")
	};

var currSystemBgImage = "";

loadSystemPartsByHoleSize_complete =
	function(result){
		$(".systemList").fadeOut("fast", function(){
			$(".systemList").empty();
			if(result.rows){
				$.each(result.rows, function(i){
					
					var pdfLink = "";
					
					if(result.rows[i]["PDF"]){
						pdfLink = "<a href='http://www.wassara.com/images/PDF/" + result.rows[i]["PDF"] + "' target='_blank'><img src='../img/systems/pdfIconPart.gif' width='123' height='29' border='0' alt='Click to download PDF on this part.'></a>";
					};
					
					$(".systemList").append("<div class='systemListItem' id='listItem" + result.rows[i]["ID"] + "'><div id='image1' class='hidden'>" + result.rows[i]["Image"] + "</div><div id='image2' class='hidden'>" + result.rows[i]["AltImage"] + "</div><div class='systemListItemLeftText'>" + result.rows[i]["Header"] + "</div><div class='systemListItemRightText'>" + result.rows[i]["Description"] + pdfLink + "<div class='systemListItemSubContent'>" + result.rows[i]["ExtendedDescription"] + "</div></div></div>");
				})
			}
			
			$(".systemListItem").click(function(){
				var sctollToDiv = $("#" + this.id);
				$(".systemListItemSubContent").hide();
				$(this).find(".systemListItemSubContent").slideDown("slow", function(){
					$('.systemList').scrollTo(sctollToDiv, 500);
				});		
			});
			
			setSystemHeight();
			
			$(".systemListItem").hoverIntent({
				sensitivity: 5, 
				interval: 200, 
				over: function(){
				
					var bgImageName = $("#" + this.id).find("#image1").html();
					var coverImageName = $("#" + this.id).find("#image2").html();
					var bgImage = "url('http://www.wassara.com/images/parts/" + bgImageName + "')";
					
					$("#systemMediaPanel").css({"background-image":bgImage});
					setTimeout(function(){
						$("#illustration").fadeOut("fast", function(){
							$("#illustration").empty().append("<img src='http://www.wassara.com/images/parts/" + coverImageName + "' width='526' height='338'>").fadeIn("slow");
						});
					}, 200);
					
				}, 
				timeout: 200, 
				out: function(){
						//$("#illustration").fadeOut("slow");
					}
			});
			
			$(".systemList").bind("mouseleave", function(){
				$("#illustration").fadeOut("slow");
				$("#systemMediaPanel").css({"background-image":""});
			});
			
			$(".systemList").bind("mouseenter", function(){
				$("#illustration").fadeIn("fast");
			});
			
			$(".systemList").fadeIn("fast");
			
			if($("#rightCol").find("#pnlRightColHeader").html() == null) {
				
				if(currLang == 1)
					$("#rightCol").prepend("<div id='pnlRightColHeader'>Referensprojekt</div>");
				else
					$("#rightCol").prepend("<div id='pnlRightColHeader'>Reference cases</div>");
			}
		});		
	};
	
	
loadSystemPartsByHoleSize_error =
	function(result){
		alert(result.get_message())
	};