// select a model from models category
function showModelFromSearch(id, position, modelname, modelpic, bread, fullname) {
	$('#litebox-cover').remove();
	$('#popupShowLoad').val('0');
	var currentPosition = parseInt( $("#visibleContainer").val() );
	if (currentPosition == 0) { currentPosition = 1; }
	var lang = $("#languageValue").val();
	
	id = parseInt(id);
	position = parseInt(position);
	modelpic = parseInt(modelpic);
	
	
	$("#main-bg").animate({opacity: 0}, 300, function() { $(this).remove(); });
	
	if (currentPosition != 0) {
		$('.popup-loading').delay(0).fadeIn(500);
		
		
		$("#modal-cover").delay(0).fadeOut(600);
		$('#content-container').bind();
		
		
		bread = bread.split(', ');
		breadCategory = bread[0];
		breadModelname = bread[1];
		
		if (lang == '1') {
			if (breadCategory == "Girls") { var showme = "girl"; var showmeNum = "1"; var category = "Lányok"; }
			else if (breadCategory == "Boys") { var showme = "boy"; var showmeNum = "2"; var category = "Fiúk"; }
			else if (breadCategory == "Part Time Models") { var showme = "ptm"; var showmeNum = "3"; var category = "Part Time Models"; }
			else if (breadCategory == "New Faces") { var showme = "newface"; var showmeNum = "4"; var category = "Új Arcok"; }
			var modelTitle = "Modell";
		}
		
		
		else if (lang == '2') {
			if (breadCategory == "Girls") { var showme = "girl"; var showmeNum = "1"; var category = "Girls"; }
			else if (breadCategory == "Boys") { var showme = "boy"; var showmeNum = "2"; var category = "Boys"; }
			else if (breadCategory == "Part Time Models") { var showme = "ptm"; var showmeNum = "3"; var category = "Part Time Models"; }
			else if (breadCategory == "New Faces") { var showme = "newface"; var showmeNum = "4"; var category = "New Faces"; }
			var modelTitle = "Model";
		}
		
		
		var breadcrumbs = '<span><font onclick="modelsShowCategory(\'' + showme + '\', \'' + showmeNum + '\');">' + category + '</font> <span class="bread-divider">&nbsp;</span><span style="margin: 0 7px 0 0;">' + modelTitle + ': </span></span>' + fullname + ' <b>' + breadModelname + '</b>';
		
		
		
		// meglevo fo-divek kifade-elese
		if ( currentPosition < position ) { var moveouttop = "0%"; var moveintop = "100%"; }
		else if ( currentPosition > position ) { var moveouttop = "100%"; var moveintop = "0%"; }
		else if ( currentPosition == position ) { var moveouttop = "0%"; var moveintop = "100%"; }
		
		
		$('#content-container div').animate({opacity: 0}, 400, 'easeInOutCirc', function() {
			$(this).remove();
		});
		
		
		$("#litebox-container").animate({top: "150%"}, 300, "easeInOutCirc");
		$("#litebox-cover").delay(150).fadeOut(300, function() {
			$(".lite-image").animate({left: 0}, 400, "easeInOutCirc");
		});
		$("#menu, #breadcrumbs, #footer").fadeIn(300);
		
		
		$("body").append('<div id="model-container-' + id + '" class="model-container" style="top: ' + moveintop + ';"></div>');
		
		
		
		$.ajax({
			url: 'model-count-images.php?id=' + id, 
			cache: false, 
			success: function(modelCountImages) {
				var modelImages = modelCountImages.split('___');
				var modelDefaults = parseInt(modelImages[0]);
				var modelPolaroids = parseInt(modelImages[1]);
				var modelDir = modelImages[2];
				var modelCurrentImage = 0;
				
				
				loadNextImage(0);
				
				function loadNextImage(modelCurrentImage) {
					setTimeout(function() {
						if (modelCurrentImage <= (modelDefaults + modelPolaroids)) {
							$.ajax({
								url: 'model-load-image.php?id=' + id + '&currentImage=' + modelCurrentImage, 
								cache: false, 
								success: function(modelLoadedImage) {
									if (modelLoadedImage != '') {
										// file extension, middle name, thumb name
										var filename = '', thumbname = '', middlename = '';
										
										var explodedFile = modelLoadedImage.split('.');
										
										var lastPart = explodedFile.length - 1;
										var fileExt = explodedFile[lastPart];
										
										for (i = 0; i <= (lastPart - 1); i++) {
											if (i == (lastPart - 1)) { var filename = explodedFile[i]; }
											else { var filename = explodedFile[i] + '.'; }
										}
										
										var largename = filename + '.' + fileExt;
										var thumbname = filename + '__tn.' + fileExt;
										var middlename = filename + '__mid.' + fileExt;
										
										
										
										$('#gallery-image-' + modelCurrentImage + ' .img-container').html('<img alt="" src="content/models/' + modelDir + '/' + middlename + '" />');
										$('#thumbnails-image-' + modelCurrentImage + ' .tn-container').html('<img alt="" src="content/models/' + modelDir + '/' + thumbname + '" onload="initImage(this);"/>');
										
										$('#gallery-image-' + modelCurrentImage + ' img').delay(1500).fadeIn(800);
										$('#gallery-image-' + modelCurrentImage + ' .preload').delay(1500).animate({"opacity": 0}, 800, function() { $(this).remove(); });
										
										$('#thumbnails-image-' + modelCurrentImage + ' img').delay(1500).fadeIn(800);
										$('#thumbnails-image-' + modelCurrentImage + ' .preload').delay(1500).animate({"opacity": 0}, 800, function() { $(this).remove(); });
									}
								}
							});
							
							loadNextImage((modelCurrentImage+1));
						}
					}, 300);
				} // function: loadNextImage
				
				
				
				
				
				$.ajax({
					url: 'model.php?id=' + id, 
					cache: false, 
					success: function(response) {
						$("#model-container-" + id).html(response);
						
						// a nem meghivott modell eltuntetese
						var modelContainer = $('.model-container');
						for (i = 1; i <= $('.model-container').length; i++) {
							var j = i - 1;
							var thisID = $(modelContainer[j]).attr('id');
							var realID = thisID.split('-');
							realID = realID[2];
							
							if (realID != id) { $('#model-container-' +realID ).animate({opacity: 0}, 0, function() { $(this).remove(); }); }
						}
						
						
						$("#gallery-body").focus();
						keyboardControl();
						
						var firstMarginLeft = (($(window).width() - 950) / 2) + 155;
						$("#gallery-image-1").css("margin-left", firstMarginLeft);
						
						
						// move in new model-container
						$("#model-container-" + id).animate({top: "47%", opacity: 1}, 400, "easeInOutCirc", function() {
							$('.popup').delay(3000).fadeOut(500);
							$('.popup-loading').delay(500).fadeOut(500);
							
							
							// elso kep beigazitasa
							var firstMarginLeft = (($(window).width() - 950) / 2) + 155;
							$("#model-container-" + id + " #gallery-image-1").css("margin-left", firstMarginLeft);
							
							
							$("#visibleContainer").attr("value", position);
							$("#breadcrumbs").animate({opacity: 0}, 400, function() {
								$("#breadcrumbs").html(breadcrumbs).animate({opacity: 1}, 400);
							});
							
							
							// remove class="selected"
					var menuItem = $("#menu li");
					for (i = 0; i <= (menuItem.length - 5); i++) {
						$(menuItem[i]).attr("class", "model-category");
					}
					for (i = 4; i <= (menuItem.length - 1); i++) {
						$(menuItem[i]).attr("class", "");
					}
					
					// add class="selected"
					var divClass = $("#menu-item-" + showme).attr("class");
					var newDivClass = divClass + " selected";
					$("#menu-item-" + showme).attr("class", newDivClass);
							
							
							
							if (!isNaN(modelpic)) {
								if (modelpic <= 0) { modelpic = 1; }
								if (modelpic > 0) { gotoModelPic(modelpic); }
							} // !isNaN(modelpic)
							
							
							var liteboxCoverContent = $('#litebox-cover').html();
							$('#litebox-cover').remove();
							$('#wrap').append('<div id="litebox-cover">' + liteboxCoverContent + '</div><!-- #litebox-cover -->');
							$('#litebox-cover').hide(0).animate({'opacity': '1'}, 0);
							
							
							$(".scroll-pane").jScrollPane();
							$(".jspVerticalBar, .jspHorizontalBar").animate({"opacity": 1}, 500);
							
							
							onResize();
							
							
							$("#visibleContainer").val((parseInt(position) + 1));
						}); // #model-container-id animate-top
					} // success: model.php
				}); // ajax: model.php
			} // success: model-count-images
		}); // ajax: model-count-images
	}
}



// select a model from models category
function showModel(id, position, modelname, modelpic, fullname) {
	$('#litebox-cover').remove();
	$('#popupShowLoad').val('0');
	var currentPosition = $("#visibleContainer").val();
	var lang = $("#languageValue").val();
	
	
	if (currentPosition != position || modelpic) {
		var breadcrumbs = $("#breadcrumbs").html();
		if (lang == 1) {
			if (breadcrumbs == "Lányok") { category = '<font onclick="modelsShowCategory(\'girl\', \'1\'); location.href=\'#!hu/girls\';">' + breadcrumbs + '</font>'; }
			else if (breadcrumbs == "Fiúk") { category = '<font onclick="modelsShowCategory(\'boy\', \'2\'); location.href=\'#!hu/boys\';">' + breadcrumbs + '</font>'; }
			else if (breadcrumbs == "Part Time Models") { category = '<font onclick="modelsShowCategory(\'ptm\', \'3\'); location.href=\'#!hu/part-time-models\';">' + breadcrumbs + '</font>'; }
			else if (breadcrumbs == "Új Arcok") { category = '<font onclick="modelsShowCategory(\'newface\', \'2\'); location.href=\'#!hu/new-faces\';">' + breadcrumbs + '</font>'; }
		}
		
		else if (lang == 2) {
			if (breadcrumbs == "Girls") { category = '<font onclick="modelsShowCategory(\'girl\', \'1\'); location.href=\'#!en/girls\';">' + breadcrumbs + '</font>'; }
			else if (breadcrumbs == "Boys") { category = '<font onclick="modelsShowCategory(\'boy\', \'2\'); location.href=\'#!en/boys\';"">' + breadcrumbs + '</font>'; }
			else if (breadcrumbs == "Part Time Models") { category = '<font onclick="modelsShowCategory(\'ptm\', \'3\'); location.href=\'#!en/part-time-models\';"">' + breadcrumbs + '</font>'; }
			else if (breadcrumbs == "New Faces") { category = '<font onclick="modelsShowCategory(\'newface\', \'2\'); location.href=\'#!en/new-face\';"">' + breadcrumbs + '</font>'; }
		}
		
		
		// move out existing model-container
		if ( currentPosition < position ) { var moveouttop = "0%"; var moveintop = "100%"; }
		else if ( currentPosition > position ) { var moveouttop = "100%"; var moveintop = "0%"; }
		else if ( currentPosition == position ) { var moveouttop = "0%"; var moveintop = "100%"; }
		
		if ($(".pages-container")) { $(".pages-container").animate({top: "100%", opacity: 0}, 600, "easeInOutCirc", function() { $(this).remove(); }); }
		if ($(".models-container")) { $(".models-container").animate({top: moveouttop, opacity: 0}, 600, "easeInOutCirc", function() { $(this).remove(); }); }
		
		
		$("body").append('<div id="model-container-' + id + '" class="model-container" style="top: ' + moveintop + ';"></div>');
		
		
		
		// breadcrumbs
		var searchFor = modelname.search(/"+"/);
		if (searchFor != -1) {
			if (fullname != '') {
				if (lang == 1) { breadcrumbs = '<span>' + category + ' <span class="bread-divider">&nbsp;</span><span style="margin: 0 7px 0 0;">Modell: </span></span>' + fullname + ' <b>' + modelname + '</b>'; }
				else if (lang == 2) { breadcrumbs = '<span>' + category + ' <span class="bread-divider">&nbsp;</span><span style="margin: 0 7px 0 0;">Model: </span></span>' + fullname + ' <b>' + modelname + '</b>'; }
			}
			
			else {
				if (lang == 1) { breadcrumbs = '<span>' + category + ' <span class="bread-divider">&nbsp;</span><span style="margin: 0 7px 0 0;">Modell: </span></span>' + modelname; }
				else if (lang == 2) { breadcrumbs = '<span>' + category + ' <span class="bread-divider">&nbsp;</span><span style="margin: 0 7px 0 0;">Model: </span></span>' + modelname; }
			}
		}
		
		else {
			var newModelname = modelname.replace(/\+/g, " ");
			
			if (fullname != '') {
				if (lang == 1) { breadcrumbs = '<span>' + category + ' <span class="bread-divider">&nbsp;</span><span style="margin: 0 7px 0 0;">Modell: </span></span>' + fullname + ' <b>' + newModelname + '</b>'; }
				else if (lang == 2) { breadcrumbs = '<span>' + category + ' <span class="bread-divider">&nbsp;</span><span style="margin: 0 7px 0 0;">Model: </span></span>' + fullname + ' <b>' + newModelname + '</b>'; }
			}
			
			else {
				if (lang == 1) { breadcrumbs = '<span>' + category + ' <span class="bread-divider">&nbsp;</span><span style="margin: 0 7px 0 0;">Modell: </span></span>' + newModelname; }
				else if (lang == 2) { breadcrumbs = '<span>' + category + ' <span class="bread-divider">&nbsp;</span><span style="margin: 0 7px 0 0;">Model: </span></span>' + newModelname; }
			}
		}
		
		
		$.ajax({
			url: 'model-count-images.php?id=' + id, 
			cache: false, 
			success: function(modelCountImages) {
				var modelImages = modelCountImages.split('___');
				var modelDefaults = parseInt(modelImages[0]);
				var modelPolaroids = parseInt(modelImages[1]);
				var modelDir = modelImages[2];
				var modelCurrentImage = 0;
				
				loadNextImage(0);
				
				function loadNextImage(modelCurrentImage) {
					setTimeout(function() {
						if (modelCurrentImage <= (modelDefaults + modelPolaroids)) {
							$.ajax({
								url: 'model-load-image.php?id=' + id + '&currentImage=' + modelCurrentImage, 
								cache: false, 
								success: function(modelLoadedImage) {
									if (modelLoadedImage != '') {
										// file extension, middle name, thumb name
										var filename = '', thumbname = '', middlename = '';
										
										var explodedFile = modelLoadedImage.split('.');
										
										var lastPart = explodedFile.length - 1;
										var fileExt = explodedFile[lastPart];
										
										for (i = 0; i <= (lastPart - 1); i++) {
											if (i == (lastPart - 1)) { var filename = explodedFile[i]; }
											else { var filename = explodedFile[i] + '.'; }
										}
										
										var largename = filename + '.' + fileExt;
										var thumbname = filename + '__tn.' + fileExt;
										var middlename = filename + '__mid.' + fileExt;
										
										
										
										$('#gallery-image-' + modelCurrentImage + ' .img-container').html('<img alt="" src="content//models/' + modelDir + '/' + middlename + '" />');
										$('#thumbnails-image-' + modelCurrentImage + ' .tn-container').html('<img alt="" src="content//models/' + modelDir + '/' + thumbname + '" onload="initImage(this);"/>');
										
										$('#gallery-image-' + modelCurrentImage + ' img').delay(1500).fadeIn(800);
										$('#gallery-image-' + modelCurrentImage + ' .preload').delay(1500).animate({"opacity": 0}, 800, function() { $(this).remove(); });
										
										$('#thumbnails-image-' + modelCurrentImage + ' img').delay(1500).fadeIn(800);
										$('#thumbnails-image-' + modelCurrentImage + ' .preload').delay(1500).animate({"opacity": 0}, 800, function() { $(this).remove(); });
									}
								}
							});
							
							loadNextImage((modelCurrentImage+1));
						}
					}, 300);
				}
				
				
				
				
				$.ajax({
					url: "model.php?id=" + id, 
					cache: false, 
					success: function(response) {
						$("#model-container-" + id).html(response);
						
						document.getElementById('menu').style.zIndex='100';
						
						keyboardControl();
						
						var popupShow = parseInt( $('#popupShow').val() );
						if (popupShow != 0) { $('.popup').hide(0); }
						
						
						var firstMarginLeft = (($(window).width() - 950) / 2) + 155;
						$("#gallery-image-1").css("margin-left", firstMarginLeft);
						
											
						// move in new model-container
						$("#model-container-" + id).animate({top: "47%", opacity: 1}, 600, "easeInOutCirc", function() {
							if (popupShow == 0) { $('.popup').delay(2000).fadeOut(500, function() { $(this).remove(); }); }
							$('#popupShow').val((popupShow + 1));
							
							
							$("#visibleContainer").attr("value", position);
							$("#breadcrumbs").animate({opacity: 0}, 400, function() {
								$("#breadcrumbs").html(breadcrumbs).animate({opacity: 1}, 400);
							});
							
							
							if (!isNaN(modelpic)) {
								if (modelpic <= 0) { modelpic = 1; }
								
								if (modelpic > 0) {
									gotoModelPic(modelpic);
									
									/*
									var modelItems = $(".gallery-image");
									var tnItems = $(".thumbnails-image");
									for (i = 0; i <= (modelItems.length - 1); i++) {
										var j = parseInt(i) + 1;
										$("#thumbnails-image-" + j + " img").delay(j * 200).fadeIn(800);
										$("#gallery-image-" + j + " img").delay(j * 200).fadeIn(800);
										
										
										$(modelItems[i]).find(".preload").delay(j * 300).animate({"opacity": 0}, 1000, function() { $(this).remove(); });
										$(tnItems[i]).find(".preload").delay(j * 200).animate({"opacity": 0}, 800, function() { $(this).remove(); });
									}*/
								}
							} // !isNaN(modelpic)
							
							
							var liteboxCoverContent = $('#litebox-cover').html();
							$('#litebox-cover').remove();
							$('#wrap').append('<div id="litebox-cover">' + liteboxCoverContent + '</div><!-- #litebox-cover -->');
							$('#litebox-cover').hide(0).animate({'opacity': '1'}, 0);
							
							
							$(".scroll-pane").jScrollPane();
							$(".jspVerticalBar, .jspHorizontalBar").animate({"opacity": 1}, 500);
							
							
							onResize();
						}); // #model-container-id animate-top
					} // success: model.php
				}); // ajax
			} // msuccess: model-count-images.php
		}); // ajax
	}
}



// slideshow thumbnails-click
function gotoModelPic(id) {
	// detecting browser
	var userAgent = navigator.userAgent;
	var browser = '';
	
	var searchForMSIE = userAgent.search('MSIE');
	if (searchForMSIE != -1) { var browser = 'MSIE'; }
	
	
	
	var locationHash = String(location.hash);
	var hash = locationHash.split("/");
	var langHash = hash[0].split("#!");
	langHash = langHash[1];
	
	var categoryHash = hash[1];
	var modelIDHash = hash[2];
	var modelNameHash = hash[3];
	var modelPicHash = hash[4];
	var liteboxHash = hash[5];
	
	
	if (liteboxHash) { var litebox = '/litebox'; }
	else { var litebox = ''; }
	
	
	
	
	var distance = 0;
	var imagesObj = $('.gallery-image');
	var current = parseInt( $("#gotoModelCurrent").val() );
	id = parseInt(id);
	
	
	if (current != id && id <= imagesObj.length && id > 0) {
		location.href='#!' + langHash + '/' + categoryHash + '/' + modelIDHash + '/' + modelNameHash + '/' + id + litebox;
		
		if (id == 1) { distance = 0; } // id = 1
		
		if (id != 1 && id <= $(".gallery-image").length) { // id < current
			for (i = 1; i <= id; i++) {
				distance = distance + ($("#gallery-image-" + i).width() + 10);
			}
			distance = distance - ($("#gallery-image-" + id).width() + 10);
			distance = -1 * distance;
		}
		
		/*if (id > 1 && id > current && id <= $(".gallery-image").length) { // id > current
			for (i = 1; i <= id; i++) {
				distance = distance + ($("#gallery-image-" + i).width() + 10);
			}
			distance = distance - ($("#gallery-image-" + id).width() + 10);
			distance = -1 * distance;
		}*/
		
		
		$(".gallery-image").stop(true, true).animate({left: distance}, 400, "easeInOutCirc");
		
		//$(".gallery-image-active .img-container").stop(true, true).animate({"opacity": .2}, 400, "easeInOutCirc");
		//$(".gallery-image-active").attr("class", "gallery-image").css('z-index', '5');
		//$("#gallery-image-" + id + " .img-container").stop(true, true).animate({"opacity": 1}, 400, "easeInOutCirc");
		//$("#gallery-image-" + id).attr("class", "gallery-image gallery-image-active").css('z-index', '5');
		
		
		// IE
		if (browser == 'MSIE') {
			document.getElementById("menu").zIndex="89";
			
			for (i = 1; i <= (id - 1); i++) {
				if ($('#gallery-image-' + i)) {
					$("#gallery-image-" + i + " .cover-ie").css('display', 'inline');
					
					$("#gallery-image-" + i).mouseover(function() {
						$(this).find('.cover-ie').css('display', 'none');
					}).mouseleave(function() {
						$(this).find('.cover-ie').css('display', 'inline');
					});
				}
			}
			
			for (j = id; j <= imagesObj.length; j++) {
				if ($('#gallery-image-' + j)) {
					$("#gallery-image-" + j + " .cover-ie").css('display', 'none');
					
					$("#gallery-image-" + j).mouseover(function() {
						$(this).find('.cover-ie').css('display', 'none');
					}).mouseleave(function() {
						$(this).find('.cover-ie').css('display', 'none');
					});
				}
			}
		} // IE
		
		
		
		// !IE
		if (browser != 'MSIE') {
			for (i = 1; i <= (id - 1); i++) {
				if ($('#gallery-image-' + i)) {
					$("#gallery-image-" + i + " img").animate({'opacity': .2}, 400);
					
					$("#gallery-image-" + i).mouseover(function() {
						$(this).find('img').stop(false, false).animate({'opacity': 1}, 200);
					});
					$("#gallery-image-" + i).mouseleave(function() {
						$(this).find('img').stop(false, false).animate({'opacity': .2}, 200);
					});
				}
			}
			for (j = id; j <= imagesObj.length; j++) {
				if ($('#gallery-image-' + j)) {
					$("#gallery-image-" + j + " img").animate({'opacity': 1}, 400);
					
					$("#gallery-image-" + j).mouseover(function() {
						$(this).find('img').stop(true, true).animate({'opacity': 1}, 0);
					});
					$("#gallery-image-" + j).mouseleave(function() {
						$(this).find('img').stop(true, true).animate({'opacity': 1}, 0);
					});
				}
			}
		} // !IE
		
		
		$(".thumbnails-image-selected img").stop(true, true).animate({"opacity": .5}, 400, "easeInOutCirc");
		$(".thumbnails-image-selected").attr("class", "thumbnails-image");
		$("#thumbnails-image-" + id + " img").stop(true, true).animate({"opacity": 1}, 400, "easeInOutCirc");
		$("#thumbnails-image-" + id).attr("class", "thumbnails-image thumbnails-image-selected");
		
		
		$("#gotoModelCurrent").val(id);
		$('#popupShowLoad').val(id);
	}
	
	
	
	else {
		$("#gallery-image-" + id + " img").stop(true, true).animate({"opacity": 1}, 400, "easeInOutCirc", function() {
			$("#gallery-image-" + id).attr("class", "gallery-image gallery-image-active");
		});
		
		$("#thumbnails-image-" + id + " img").stop(true, true).animate({"opacity": 1}, 400, "easeInOutCirc", function() {
			$("#thumbnails-image-" + id).attr("class", "thumbnails-image thumbnails-image-selected");
		});
		
		
		/*var popupShow = parseInt( $('#popupShow').val() );
		if (popupShow < 2) { showModelPic(id); }*/
		
		
		
		
		
		var popupShowLoad = parseInt( $('#popupShowLoad').val() );
		if (popupShowLoad != 0) { showModelPic(id); }
	}
}



//keyboard-control
function keyboardControl() {
	$("body").unbind("keyup");
	$("body").keyup(function(e) {
		var current = parseInt( $("#gotoModelCurrent").val() );
		// left arrow 37, right arrow 39
		if (e.keyCode == 37) { gotoModelPic( (current - 1) ); }
		else if (e.keyCode == 39) { gotoModelPic( (current + 1) ); }
	});
}



//keyboard-control
function keyboardControlLitebox(allow) {
	$("body").unbind("keyup");
	if (allow == "1") {
		$("body").keyup(function(e) {
			var images = $(".gallery-image");
			var current = parseInt( $("#gotoModelCurrent").val() );
			
			// left arrow 37, right arrow 39
			if (current > 0) {
				if (e.keyCode == 37) { gotoModelPic( (current - 1) ); modelPicJump( (current - 1) ); }
			}
			if (current < images.length) {
				if (e.keyCode == 39) { gotoModelPic( (current + 1) ); modelPicJump( (current + 1) ); }
			}
		});
	}
	
	else if (allow == "0") {
		keyboardControl();
	}
}




// show litebox
function showModelPic(number) {
	// detecting browser
	var userAgent = navigator.userAgent;
	var browser = '';
	
	var searchForMSIE = userAgent.search('MSIE');
	if (searchForMSIE != -1) { var browser = 'MSIE'; }
	
	
	
	var clickedClass = $("#gallery-image-" + number).attr("class");
	clickedClass = clickedClass.search("gallery-image-active");
	
	if (clickedClass != -1) {
		keyboardControlLitebox("1"); 
		$("#menu, #breadcrumbs, #footer").fadeOut(300);
		number = parseInt(number);
		
		var distance = -((number - 1) * 1000);
		$(".lite-image").animate({left: distance}, 0);
		
		
		if (number == 1) { $(".lite-first").animate({left: 0}, 400, "easeInOutCirc"); }
		else { $(".lite-first").animate({left: -70}, 400, "easeInOutCirc"); }
		
		
		if (number == $(".gallery-image").length) { $(".lite-last").animate({right: 0}, 400, "easeInOutCirc"); }
		else { $(".lite-last").animate({right: -70}, 400, "easeInOutCirc"); }
		
		$(".model-container").fadeOut(300);
		$("#litebox-cover").fadeIn(300, function() {
			if (browser == 'MSIE') { $("#litebox-container").fadeIn(300); }
			else { $("#litebox-container").animate({top: "50%"}, 300, "easeInOutCirc"); }
			
			$('.lite-nav').css('z-index', '199');
			$('.lite-first, .lite-last').css('z-index', '200');
			
			
			$("#litetn-image-" + number).attr("class", "litetn-image litetn-image-selected");
			
			
			$(".jspVerticalBar, .jspHorizontalBar").animate({"opacity": 1}, 500, function() {
				$("#litetn-image-" + number).attr("class", "litetn-image litetn-image-selected");
				$("#litetn-image-" + number + " img").animate({"opacity": 1}, 400, "easeInOutCirc");
			});
		});
		
		
		
		var locationHash = String(location.hash);
		var hash = locationHash.split("/");
		var langHash = hash[0].split("#!");
		langHash = langHash[1];
		
		var categoryHash = hash[1];
		var modelIDHash = hash[2];
		var modelNameHash = hash[3];
		var modelPicHash = hash[4];
		
		location.href='#!' + langHash + '/' + categoryHash + '/' + modelIDHash + '/' + modelNameHash + '/' + number + '/litebox';
		
		
		
		var newPrev = 'modelPicPrev(\'' + (number - 1) + '\');';
		var newNext = 'modelPicNext(\'' + (number + 1) + '\');';
		
		$(".lite-prev").attr("onclick", newPrev);
		$(".lite-next").attr("onclick", newNext);
		
		$("#modelPicCurrent").val(number);
	}
	
	
	
	else if (clickedClass == -1) {
		gotoModelPic(number);
	}
}



// show litebox at crawl
function showModelPicCrawl(number) {
	$("#menu, #breadcrumbs, #footer").fadeOut(300);
	number = parseInt(number);
	
	var distance = -((number - 1) * 1000);
	$(".lite-image").animate({left: distance}, 0);
	
	
	if (number == 1) { $(".lite-first").animate({left: 0}, 400, "easeInOutCirc"); }
	else { $(".lite-first").animate({left: -70}, 400, "easeInOutCirc"); }
	
	
	if (number == $(".gallery-image").length) { $(".lite-last").animate({right: 0}, 400, "easeInOutCirc"); }
	else { $(".lite-last").animate({right: -70}, 400, "easeInOutCirc"); }
	
	
	
	$("#litebox-cover").css("z-index", "9999").fadeIn(300, function() {
		$("#litebox-container").animate({top: "50%"}, 300, "easeInOutCirc");
		
		
		$(".jspVerticalBar, .jspHorizontalBar").animate({"opacity": 1}, 500, function() {
			$("#litetn-image-" + number).attr("class", "litetn-image litetn-image-selected");
			$("#litetn-image-" + number + " img").animate({"opacity": 1}, 400, "easeInOutCirc");
		});
	});
	
	
	
	var locationHash = String(location.hash);
	var hash = locationHash.split("/");
	var langHash = hash[0].split("#!");
	langHash = langHash[1];
	
	var categoryHash = hash[1];
	var modelIDHash = hash[2];
	var modelNameHash = hash[3];
	var modelPicHash = hash[4];
	
	location.href='#!' + langHash + '/' + categoryHash + '/' + modelIDHash + '/' + modelNameHash + '/' + number + '/litebox';
	
	
	
	var newPrev = 'modelPicPrev(\'' + (number - 1) + '\');';
	var newNext = 'modelPicNext(\'' + (number + 1) + '\');';
	
	$(".lite-prev").attr("onclick", newPrev);
	$(".lite-next").attr("onclick", newNext);
	
	$("#modelPicCurrent").val(number);
}



// close litebox
function hideModelPic() {
	// detecting browser
	var userAgent = navigator.userAgent;
	var browser = '';
	
	var searchForMSIE = userAgent.search('MSIE');
	if (searchForMSIE != -1) { var browser = 'MSIE'; }
	
	
	
	keyboardControlLitebox("0"); 
	$("#menu, #breadcrumbs, #footer").fadeIn(300);
	
	$(".model-container").fadeIn(300);
	if (browser == 'MSIE') {
		$("#litebox-container").fadeOut(300);
		$("#litebox-cover").delay(150).fadeOut(300, function() {
			$(".lite-image").animate({left: 0}, 400, "easeInOutCirc");
		});
	}
	else {
		$("#litebox-container").animate({top: "150%"}, 300, "easeInOutCirc");
		$("#litebox-cover").delay(150).fadeOut(300, function() {
			$(".lite-image").animate({left: 0}, 400, "easeInOutCirc");
		});
	}
	
	
	/*$("#litebox-container").animate({top: "150%"}, 300, "easeInOutCirc");
	$("#litebox-cover").delay(150).fadeOut(300, function() {
		$(".lite-image").animate({left: 0}, 400, "easeInOutCirc");
	});*/
	
	
	var locationHash = String(location.hash);
	var hash = locationHash.split("/");
	var langHash = hash[0].split("#!");
	langHash = langHash[1];
	
	var categoryHash = hash[1];
	var modelIDHash = hash[2];
	var modelNameHash = hash[3];
	var modelPicHash = hash[4];
	
	location.href='#!' + langHash + '/' + categoryHash + '/' + modelIDHash + '/' + modelNameHash + '/' + modelPicHash;
}



// litebox prev
function modelPicPrev(id) {
	current = $("#modelPicCurrent").val();
	current = parseInt(current);
	id = parseInt(id);
	
	$(".lite-last").animate({right: -950}, 400, "easeInOutCirc");
	 
	if ((current ) == 2) { $(".lite-first").animate({left: 0}, 400, "easeInOutCirc"); }
	else { $(".lite-first").animate({left: -70}, 400, "easeInOutCirc"); }
	
	
	if (current > 0 && current != id) {
		var distance = -((id - 1) * 1000);
		$(".lite-image").animate({left: distance}, 500, "easeInOutCirc");
		
		
		$(".litetn-image-selected").attr("class", "litetn-image");
		$("#litetn-image-" + id).attr("class", "litetn-image litetn-image-selected");
		
		
		
		var locationHash = String(location.hash);
		var hash = locationHash.split("/");
		var langHash = hash[0].split("#!");
		langHash = langHash[1];
		
		var categoryHash = hash[1];
		var modelIDHash = hash[2];
		var modelNameHash = hash[3];
		var modelPicHash = hash[4];
		
		location.href='#!' + langHash + '/' + categoryHash + '/' + modelIDHash + '/' + modelNameHash + '/' + id + '/litebox';
		
		
		
		gotoModelPic(id);
		
		
		
		var newPrev = 'modelPicPrev(\'' + (id - 1) + '\');';
		var newNext = 'modelPicNext(\'' + (id + 1) + '\');';
		
		$(".lite-prev").attr("onclick", newPrev);
		$(".lite-next").attr("onclick", newNext);
		
		$("#modelPicCurrent").val(id);
	}
}



// litebox next
function modelPicNext(id) {
	current = $("#modelPicCurrent").val();
	current = parseInt(current);
	id = parseInt(id);
	
	$(".lite-first").animate({left: -950}, 400, "easeInOutCirc");
	 
	if ((current + 2) > $(".gallery-image").length) { $(".lite-last").animate({right: 0}, 400, "easeInOutCirc"); }
	else { $(".lite-last").animate({right: -70}, 400, "easeInOutCirc"); }
	
	
	if ((current - 1) <= $(".gallery-image").length) {
		var distance = -(current * 1000);
		$(".lite-image").animate({left: distance}, 500, "easeInOutCirc");
		
		
		$(".litetn-image-selected").attr("class", "litetn-image");
		$("#litetn-image-" + id).attr("class", "litetn-image litetn-image-selected");
		
		
		
		var locationHash = String(location.hash);
		var hash = locationHash.split("/");
		var langHash = hash[0].split("#!");
		langHash = langHash[1];
		
		var categoryHash = hash[1];
		var modelIDHash = hash[2];
		var modelNameHash = hash[3];
		var modelPicHash = hash[4];
		
		location.href='#!' + langHash + '/' + categoryHash + '/' + modelIDHash + '/' + modelNameHash + '/' + id + '/litebox';
		
		
		
		gotoModelPic(id);
		
		
		
		var newPrev = 'modelPicPrev(\'' + (id - 1) + '\');';
		var newNext = 'modelPicNext(\'' + (id + 1) + '\');';
		
		$(".lite-prev").attr("onclick", newPrev);
		$(".lite-next").attr("onclick", newNext);
		
		$("#modelPicCurrent").val(id);
	}
}



// litebox thumbnails-click
function modelPicJump(id) {
	current = $("#modelPicCurrent").val();
	current = parseInt(current);
	id = parseInt(id);
	
	
	if (current != id && id > 0) {
		var distance = -((id - 1) * 1000);
		$(".lite-image").animate({left: distance}, 500, "easeInOutCirc");
		
		
		$(".litetn-image-selected").attr("class", "litetn-image");
		$("#litetn-image-" + id).attr("class", "litetn-image litetn-image-selected");
		
		
		
		var locationHash = String(location.hash);
		var hash = locationHash.split("/");
		var langHash = hash[0].split("#!");
		langHash = langHash[1];
		
		var categoryHash = hash[1];
		var modelIDHash = hash[2];
		var modelNameHash = hash[3];
		var modelPicHash = hash[4];
		
		location.href='#!' + langHash + '/' + categoryHash + '/' + modelIDHash + '/' + modelNameHash + '/' + id + '/litebox';
		
		
		
		gotoModelPic(id);
		
		
		
		var newPrev = 'modelPicPrev(\'' + (id - 1) + '\');';
		var newNext = 'modelPicNext(\'' + (id + 1) + '\');';
		
		$(".lite-prev").attr("onclick", newPrev);
		$(".lite-next").attr("onclick", newNext);
		
		$("#modelPicCurrent").val(id);
	}
	
	
	
	if (id == $(".litetn-image").length) {
		$(".lite-last").animate({right: 0}, 400, "easeInOutCirc");
	}
	
	else if (id < $(".litetn-image").length) {
		$(".lite-last").animate({right: -950}, 400, "easeInOutCirc");
	}
	
	if (id == 1) {
		$(".lite-first").animate({left: 0}, 400, "easeInOutCirc");
	}
	
	else if (id > 1) {
		$(".lite-first").animate({left: -950}, 400, "easeInOutCirc");
	}
}
