function runSlider(){
	if (current_photo < photos_count && current_photo > 1){
		if (slider_direction == 1){
			$('#photos_container_slider').animate({right: 645 * current_photo}, 1000);
			$('#photo_square_'+current_photo).removeClass('photos_square_enabled');
			current_photo++;
			$('#photo_square_'+current_photo).addClass('photos_square_enabled');
		}else{
			$('#photos_container_slider').animate({right: 645 * (current_photo - 2)}, 1000);
			$('#photo_square_'+current_photo).removeClass('photos_square_enabled');
			current_photo--;
			$('#photo_square_'+current_photo).addClass('photos_square_enabled');
		}
	}else if (current_photo == photos_count){
		slider_direction = -1
		$('#photos_container_slider').animate({right: 645 * (current_photo - 2) }, 1000);
		$('#photo_square_'+current_photo).removeClass('photos_square_enabled');
		current_photo--;
		$('#photo_square_'+current_photo).addClass('photos_square_enabled');
	}else if (current_photo = 1){
		slider_direction = 1
		$('#photos_container_slider').animate({right: 645 * current_photo}, 1000);
		$('#photo_square_'+current_photo).removeClass('photos_square_enabled');
		current_photo++;
		$('#photo_square_'+current_photo).addClass('photos_square_enabled');
	}
	
	setTimeout('runSlider();', 5000);
}

function setSquares(){
	var position = $('#photos_slider').position();
	$('#photos_image_square').css('top', position.top + $('#photos_slider').height() - 25);
	$('#photos_image_square').css('left', position.left + $('#photos_slider').width() - $('#photos_image_square').width() - 15);
	$('#photos_image_square').show();
}

function previousProductPhoto(){
	if (current_product_photo > 1){
		current_product_photo--;
		
		$('#gallery_container_slider').animate({right: 305 * (current_product_photo - 1)}, 1000);
		
		var current = current_product_photo;
		$('#photo_description_' + (description_key_to_hide)).fadeOut(500, function(){
			$('#photo_description_' + (current)).fadeIn(500);
		});
		
		if (current_product_photo % product_photos_list_limit == 0){
			previousGalleryList();
		}
		
		if (current_product_photo == 1){
			$('#previous_product_photo').hide();
		}
		
		$('#next_product_photo').show();
		
		description_key_to_hide = current_product_photo;
	}
}

function nextProductPhoto(){
	if (current_product_photo < product_photos_count){
		$('#gallery_container_slider').animate({right: 305 * current_product_photo}, 1000);
		
		var current = current_product_photo;
		$('#photo_description_' + (description_key_to_hide)).fadeOut(500, function(){
			$('#photo_description_' + (current + 1)).fadeIn(500);
		});
		
		if (current_product_photo % product_photos_list_limit == 0){
			nextGalleryList();
		}
		
		current_product_photo++;
		
		if (current_product_photo == product_photos_count){
			$('#next_product_photo').hide();
		}
		
		$('#previous_product_photo').show();
		
		description_key_to_hide = current_product_photo;
	}
}

function getProductPhoto(key){
	if (key != current_product_photo){
		description_key_to_hide - current_product_photo;
		if (key > current_product_photo){
			current_product_photo = key - 1;
			nextProductPhoto();
		}else{
			current_product_photo = key + 1;
			previousProductPhoto();
		}
	}
}

function nextGalleryList(){
	if (product_photos_list_current < product_photos_list_count){
		$('#gallery_list_container_slider').animate({right: 220 * product_photos_list_current}, 1000);
		
		product_photos_list_current++;
		
		if (product_photos_list_current == product_photos_list_count){
			$('#next_gallery_list').hide();
		}
		
		$('#previous_gallery_list').show();
	}
}

function previousGalleryList(){
	if (product_photos_list_current > 1){
		product_photos_list_current--;
		
		$('#gallery_list_container_slider').animate({right: 220 * (product_photos_list_current - 1)}, 1000);
		
		if (product_photos_list_current == 1){
			$('#previous_gallery_list').hide();
		}
		
		$('#next_gallery_list').show();
	}
}

function showArticle(id){
	if ($('#article_' + id).css('display') == 'none'){
		$('#article_' + id).slideDown();
	}else{
		$('#article_' + id).slideUp();
	}
}

function hideSelectedDivs(){
	$('.select').each(function(){
		if (this.tagName == 'DIV'){
			if (this.id != lastShowedDiv){
				$('#' + this.id).slideUp(300);
			}
		}
	});
	
	lastShowedDiv = '';
}

function showSelect(options_div, main_div){
	var options = $('#'+options_div);
	
	if (options.css('display') == 'none'){
		var position = $('#' + main_div).position();
		
		options.css('top', position.top + 21);
		options.css('left', position.left);		
		options.slideDown(300);
		
		lastShowedDiv = options_div;
	}else{
		options.slideDown(300);
	}
}

function select(value, div_input_id, prefix, input_id, select_div_id){
	$('#' + input_id).val(value);
	$('#' + div_input_id).html($('#' + prefix+value).html());
	$('#' + select_div_id).slideUp(300);
}

function getDistributors(){
	var value = $('#DistributorProvinceId').val();
	document.location.href = window.main_page + 'distributors/index/' + value;
}

function loadPhotoSlider(){
	current_loaded_photo++;
	if (current_loaded_photo == photos_count){
		setSquares();
		setTimeout('runSlider();', 5000);
		jQuery('#photo_square_1').addClass('photos_square_enabled');
	}
}
